@olenbetong/synergi-react 5.0.0 → 5.2.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/dist/styles/styles.css +1 -1
- package/dist/styles/styles.css.map +1 -1
- package/es/components/Checkbox/index.css +1 -1
- package/es/components/Checkbox/index.js +1 -9
- package/es/components/CodeEditor/CodeEditor.css +6 -6
- package/es/components/ColorCard/index.css +17 -28
- package/es/components/DateNavigator/index.css +5 -7
- package/es/components/FilePond.js +3 -12
- package/es/components/ImageEditor/ImageEditor.css +10 -10
- package/es/components/ImageEditor/ImageEditor.js +4 -4
- package/es/components/ImageEditor/ResponsiveButton.js +2 -2
- package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +1 -1
- package/es/components/ImageEditor/plugins/redactPlugin/RedactToolbar.js +1 -1
- package/es/components/ImageEditor/plugins/redactPlugin/useRedactTool.js +18 -14
- package/es/components/ImageEditor/useImageHistory.js +13 -1
- package/es/components/MergeProgressDialog/MergeProgressDialogDs.js +3 -3
- package/es/components/MergeProgressDialog/useMergeJob.js +5 -4
- package/es/components/PageBanner/index.css +1 -1
- package/es/components/PdfViewer/PdfViewer.js +1 -1
- package/es/components/Portal/index.js +20 -20
- package/es/components/Spinner/index.css +1 -1
- package/es/components/SplitContainer/index.css +1 -1
- 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/components/ValueToggleGroup/index.css +2 -2
- package/es/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +7 -7
- 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/index.css +1 -1
- package/es/useTranslation/index.js +5 -3
- package/package.json +16 -4
- 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.scss +2 -2
- 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/ColorCard/index.css +17 -28
- package/src/components/DateNavigator/DateNavigator.test.tsx +175 -0
- package/src/components/DateNavigator/index.css +5 -7
- 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.css +10 -10
- package/src/components/ImageEditor/ImageEditor.test.tsx +299 -0
- package/src/components/ImageEditor/ImageEditor.tsx +348 -348
- package/src/components/ImageEditor/ResponsiveButton.tsx +2 -2
- 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 +42 -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 +4 -3
- package/src/components/MergeProgressDialog/useMergeJob.test.ts +326 -0
- package/src/components/MergeProgressDialog/useMergeJob.ts +4 -3
- package/src/components/PageBanner/index.scss +10 -10
- 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/Spinner/index.css +1 -1
- package/src/components/SplitContainer/SplitContainer.browser.test.tsx +304 -0
- package/src/components/SplitContainer/index.scss +5 -1
- 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/components/ValueToggleGroup/index.css +2 -2
- 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/BarcodeScanner.css +7 -7
- 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 +194 -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
|
+
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
.ObColorCard-root {
|
|
2
2
|
--bg-color-border: black;
|
|
3
3
|
--bg-color-main: white;
|
|
4
|
-
--bg-size: 0.75rem;
|
|
4
|
+
--bg-size: var(--ds-size-3, 0.75rem);
|
|
5
5
|
--card-color: rgb(0, 0, 0);
|
|
6
6
|
|
|
7
7
|
display: flex;
|
|
8
8
|
align-items: stretch;
|
|
9
|
-
min-height:
|
|
9
|
+
min-height: calc(var(--ds-size-10, 2.5rem) * 4);
|
|
10
10
|
overflow: hidden;
|
|
11
11
|
border-radius: 0.25rem;
|
|
12
12
|
box-shadow:
|
|
@@ -21,20 +21,9 @@
|
|
|
21
21
|
var(--bg-color-main)
|
|
22
22
|
);
|
|
23
23
|
font-family:
|
|
24
|
-
"Variable Bahnschrift",
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
-apple-system,
|
|
28
|
-
BlinkMacSystemFont,
|
|
29
|
-
"Segoe UI",
|
|
30
|
-
Roboto,
|
|
31
|
-
"Helvetica Neue",
|
|
32
|
-
Arial,
|
|
33
|
-
sans-serif,
|
|
34
|
-
"Apple Color Emoji",
|
|
35
|
-
"Segoe UI Emoji",
|
|
36
|
-
"Segoe UI Symbol";
|
|
37
|
-
font-size: 1rem;
|
|
24
|
+
"Variable Bahnschrift", "Bahnschrift", "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
|
25
|
+
"Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
|
26
|
+
font-size: var(--ds-font-size-3, 1rem);
|
|
38
27
|
transition: all ease-in-out 300ms;
|
|
39
28
|
cursor: pointer;
|
|
40
29
|
|
|
@@ -64,7 +53,7 @@
|
|
|
64
53
|
}
|
|
65
54
|
|
|
66
55
|
@media screen and (min-width: 48rem) {
|
|
67
|
-
font-size: 1.2rem;
|
|
56
|
+
font-size: var(--ds-font-size-4, 1.2rem);
|
|
68
57
|
}
|
|
69
58
|
}
|
|
70
59
|
|
|
@@ -73,8 +62,8 @@
|
|
|
73
62
|
flex: 1 1 100%;
|
|
74
63
|
flex-direction: column;
|
|
75
64
|
justify-content: space-between;
|
|
76
|
-
margin: 1rem 0;
|
|
77
|
-
padding: 0.5rem 1.5rem 0.5rem 1rem;
|
|
65
|
+
margin: var(--ds-size-4, 1rem) 0;
|
|
66
|
+
padding: var(--ds-size-2, 0.5rem) var(--ds-size-6, 1.5rem) var(--ds-size-2, 0.5rem) var(--ds-size-4, 1rem);
|
|
78
67
|
overflow: hidden;
|
|
79
68
|
text-overflow: ellipsis;
|
|
80
69
|
|
|
@@ -83,12 +72,12 @@
|
|
|
83
72
|
}
|
|
84
73
|
|
|
85
74
|
&.ObColorCard-minor {
|
|
86
|
-
flex: 0 0
|
|
75
|
+
flex: 0 0 calc(var(--ds-size-8, 2rem) * 2);
|
|
87
76
|
border-right: 1px solid #e3e3e3;
|
|
88
77
|
transition: margin ease-in-out 300ms;
|
|
89
78
|
|
|
90
79
|
@media screen and (min-width: 48rem) {
|
|
91
|
-
flex: 0 0
|
|
80
|
+
flex: 0 0 calc(var(--ds-size-8, 2rem) * 4);
|
|
92
81
|
}
|
|
93
82
|
}
|
|
94
83
|
}
|
|
@@ -99,18 +88,18 @@
|
|
|
99
88
|
|
|
100
89
|
.ObColorCard-detailLabel {
|
|
101
90
|
color: #696969;
|
|
102
|
-
font-size: 0.8rem;
|
|
91
|
+
font-size: var(--ds-font-size-1, 0.8rem);
|
|
103
92
|
text-transform: uppercase;
|
|
104
93
|
}
|
|
105
94
|
|
|
106
95
|
.ObColorCard-detail {
|
|
107
96
|
&:not(:last-child) {
|
|
108
|
-
margin-right: 1.5rem;
|
|
97
|
+
margin-right: var(--ds-size-6, 1.5rem);
|
|
109
98
|
}
|
|
110
99
|
|
|
111
100
|
&.ObColorCard-primary,
|
|
112
101
|
&.ObColorCard-primary .ObColorCard-detailValue {
|
|
113
|
-
font-size: 1.25rem;
|
|
102
|
+
font-size: var(--ds-font-size-5, 1.25rem);
|
|
114
103
|
font-weight: 300;
|
|
115
104
|
}
|
|
116
105
|
|
|
@@ -119,14 +108,14 @@
|
|
|
119
108
|
}
|
|
120
109
|
|
|
121
110
|
@media screen and (min-width: 48rem) {
|
|
122
|
-
font-size: 1rem;
|
|
111
|
+
font-size: var(--ds-font-size-3, 1rem);
|
|
123
112
|
}
|
|
124
113
|
}
|
|
125
114
|
|
|
126
115
|
.ObColorCard-stepList {
|
|
127
116
|
display: flex;
|
|
128
117
|
flex-direction: column;
|
|
129
|
-
gap: 1rem;
|
|
118
|
+
gap: var(--ds-size-4, 1rem);
|
|
130
119
|
}
|
|
131
120
|
|
|
132
121
|
.ObColorCard-step {
|
|
@@ -135,7 +124,7 @@
|
|
|
135
124
|
|
|
136
125
|
display: flex;
|
|
137
126
|
align-items: flex-start;
|
|
138
|
-
gap: 0.5rem;
|
|
127
|
+
gap: var(--ds-size-2, 0.5rem);
|
|
139
128
|
}
|
|
140
129
|
|
|
141
130
|
.ObColorCard-step::before {
|
|
@@ -159,7 +148,7 @@
|
|
|
159
148
|
position: absolute;
|
|
160
149
|
top: calc(0.25em + 0.6em + 0.15em); /* dot top + dot height + 0.15em spacing */
|
|
161
150
|
left: calc(0.3em - 1px); /* half of the circle width minus half the border width */
|
|
162
|
-
height: calc(100% - 0.95em + 1rem + 0.0625em); /* height of container - top + gap */
|
|
151
|
+
height: calc(100% - 0.95em + var(--ds-size-4, 1rem) + 0.0625em); /* height of container - top + gap */
|
|
163
152
|
border-left: 2px dotted #999;
|
|
164
153
|
z-index: 0;
|
|
165
154
|
}
|