@scm-manager/scm-code-editor-plugin 4.0.0-20260230-160625 → 4.0.0-20260928-154606
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.
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scm-manager/scm-code-editor-plugin",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "4.0.0-
|
|
4
|
+
"version": "4.0.0-20260928-154606",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"main": "./src/main/js/index.tsx",
|
|
7
7
|
"scripts": {
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
"deploy": "plugin-scripts publish"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@scm-manager/ui-api": "4.0.0-
|
|
16
|
-
"@scm-manager/ui-components": "4.0.0-
|
|
17
|
-
"@scm-manager/ui-core": "4.0.0-
|
|
18
|
-
"@scm-manager/ui-extensions": "4.0.0-
|
|
19
|
-
"@scm-manager/ui-plugins": "4.0.0-
|
|
15
|
+
"@scm-manager/ui-api": "4.0.0-20260928-094717",
|
|
16
|
+
"@scm-manager/ui-components": "4.0.0-20260928-094717",
|
|
17
|
+
"@scm-manager/ui-core": "4.0.0-20260928-094717",
|
|
18
|
+
"@scm-manager/ui-extensions": "4.0.0-20260928-094717",
|
|
19
|
+
"@scm-manager/ui-plugins": "4.0.0-20260928-094717",
|
|
20
20
|
"@tanstack/react-query": "^5.90.6",
|
|
21
21
|
"ace-builds": "^1.43.6",
|
|
22
22
|
"classnames": "^2.3.4",
|
|
@@ -46,13 +46,15 @@
|
|
|
46
46
|
"@scm-manager/eslint-config": "^2.18.2",
|
|
47
47
|
"@scm-manager/plugin-scripts": "^1.6.1",
|
|
48
48
|
"@scm-manager/prettier-config": "^2.12.0",
|
|
49
|
-
"@scm-manager/tsconfig": "^
|
|
50
|
-
"@scm-manager/ui-types": "4.0.0-
|
|
49
|
+
"@scm-manager/tsconfig": "^3.0.0-alpha1",
|
|
50
|
+
"@scm-manager/ui-types": "4.0.0-20260928-094717",
|
|
51
51
|
"@types/classnames": "^2.3.4",
|
|
52
52
|
"@types/i18next": "^13.0.0",
|
|
53
53
|
"@types/query-string": "6",
|
|
54
54
|
"@types/react": "^19.1.1",
|
|
55
55
|
"@vitest/coverage-v8": "^4.0.18",
|
|
56
|
+
"@vitest/web-worker": "^4.0.18",
|
|
57
|
+
"jsdom": "^29.1.1",
|
|
56
58
|
"vitest": "^4.0.18"
|
|
57
59
|
},
|
|
58
60
|
"publishConfig": {
|
|
@@ -14,17 +14,18 @@
|
|
|
14
14
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import React, {
|
|
18
|
-
import {
|
|
19
|
-
import { WithTranslation, withTranslation } from "react-i18next";
|
|
17
|
+
import React, { FC, useState, useEffect, useCallback } from "react";
|
|
18
|
+
import { useTranslation } from "react-i18next";
|
|
20
19
|
|
|
21
20
|
import AceEditor from "react-ace";
|
|
22
21
|
import "./EditorTheme.js";
|
|
23
22
|
import findLanguage from "./findLanguage";
|
|
24
23
|
import styled from "styled-components";
|
|
25
|
-
import {registerTheme} from "./EditorTheme";
|
|
24
|
+
import { registerTheme } from "./EditorTheme";
|
|
26
25
|
import * as ace from "ace-builds";
|
|
27
|
-
import {Ace} from "ace-builds";
|
|
26
|
+
import { Ace } from "ace-builds";
|
|
27
|
+
import { useCodeSettingValue } from "./useProfile";
|
|
28
|
+
import { ErrorNotification, Loading } from "@scm-manager/ui-core";
|
|
28
29
|
|
|
29
30
|
const defaultLanguage = "text";
|
|
30
31
|
|
|
@@ -33,7 +34,7 @@ type OnBlurCallbacks = {
|
|
|
33
34
|
strgEnter: () => void;
|
|
34
35
|
};
|
|
35
36
|
|
|
36
|
-
type Props =
|
|
37
|
+
type Props = {
|
|
37
38
|
content?: string;
|
|
38
39
|
language: string;
|
|
39
40
|
disabled?: boolean;
|
|
@@ -43,122 +44,111 @@ type Props = WithTranslation & {
|
|
|
43
44
|
onBlur?: OnBlurCallbacks;
|
|
44
45
|
};
|
|
45
46
|
|
|
46
|
-
type State = {
|
|
47
|
-
loading?: boolean;
|
|
48
|
-
error?: Error;
|
|
49
|
-
language?: string;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
47
|
const StyledAceEditor = styled(AceEditor)`
|
|
53
48
|
resize: vertical;
|
|
54
49
|
min-height: 500px;
|
|
55
50
|
`;
|
|
56
51
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
componentDidUpdate(prevProps: Readonly<Props>) {
|
|
77
|
-
if (prevProps.language !== this.props.language) {
|
|
78
|
-
this.loadLanguage();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
52
|
+
const CodeEditor: FC<Props> = ({
|
|
53
|
+
content,
|
|
54
|
+
language: languageProp,
|
|
55
|
+
disabled,
|
|
56
|
+
className,
|
|
57
|
+
initialFocus = false,
|
|
58
|
+
onChange,
|
|
59
|
+
onBlur
|
|
60
|
+
}) => {
|
|
61
|
+
const { t } = useTranslation("plugins");
|
|
62
|
+
const { value: codeSetting } = useCodeSettingValue();
|
|
63
|
+
|
|
64
|
+
const [loading, setLoading] = useState(true);
|
|
65
|
+
const [error, setError] = useState<Error | undefined>(undefined);
|
|
66
|
+
const [currentLanguage, setCurrentLanguage] = useState(defaultLanguage);
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
const language = findLanguage(languageProp);
|
|
70
|
+
setLoading(true);
|
|
81
71
|
|
|
82
|
-
loadLanguage = () => {
|
|
83
|
-
const language = this.getLanguage();
|
|
84
|
-
this.setState({
|
|
85
|
-
loading: true,
|
|
86
|
-
error: undefined
|
|
87
|
-
});
|
|
88
72
|
import(`ace-builds/src-noconflict/mode-${language}`)
|
|
89
73
|
.then(() => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
language
|
|
94
|
-
});
|
|
74
|
+
setCurrentLanguage(language);
|
|
75
|
+
setError(undefined);
|
|
76
|
+
setLoading(false);
|
|
95
77
|
})
|
|
96
|
-
.catch(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
language: defaultLanguage
|
|
101
|
-
});
|
|
78
|
+
.catch((err) => {
|
|
79
|
+
setCurrentLanguage(defaultLanguage);
|
|
80
|
+
setError(err);
|
|
81
|
+
setLoading(false);
|
|
102
82
|
});
|
|
103
|
-
};
|
|
83
|
+
}, [languageProp]);
|
|
84
|
+
|
|
85
|
+
const reloadEditor = useCallback((editor: Ace.Editor) => {
|
|
86
|
+
const session = editor.getSession();
|
|
87
|
+
session.setOptions({
|
|
88
|
+
mode: "ace/mode/javascript",
|
|
89
|
+
tabSize: codeSetting.tabSize,
|
|
90
|
+
useSoftTabs: false
|
|
91
|
+
});
|
|
104
92
|
|
|
105
|
-
|
|
93
|
+
document.documentElement.style.setProperty(
|
|
94
|
+
"--user-tab-size",
|
|
95
|
+
String(codeSetting.tabSize)
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
editor.renderer.updateCharacterSize();
|
|
106
99
|
editor.resize(true);
|
|
107
100
|
editor.renderer.updateFull(true);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (loading) {
|
|
115
|
-
return <Loading />;
|
|
116
|
-
} else if (error) {
|
|
117
|
-
return <ErrorNotification error={error} />;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
<StyledAceEditor
|
|
122
|
-
className={`is-family-monospace ${className}`}
|
|
123
|
-
mode={language}
|
|
124
|
-
onLoad={(editor) => {
|
|
125
|
-
registerTheme(ace);
|
|
126
|
-
editor.setTheme("ace/theme/scm-manager");
|
|
127
|
-
}}
|
|
128
|
-
theme="scm-manager"
|
|
129
|
-
onChange={onChange}
|
|
130
|
-
name="UNIQUE_ID_OF_DIV"
|
|
131
|
-
value={content}
|
|
132
|
-
readOnly={disabled}
|
|
133
|
-
width="100%"
|
|
134
|
-
fontSize="14px"
|
|
135
|
-
onFocus={(event, editor: Ace.Editor) => this.reloadEditor(editor)}
|
|
136
|
-
onScroll={(editor: Ace.Editor) => this.reloadEditor(editor)}
|
|
137
|
-
setOptions={{ useWorker: false, cursorStyle: "smooth", autoScrollEditorIntoView: true }}
|
|
138
|
-
placeholder={t("scm-editor-plugin.edit.placeholder")}
|
|
139
|
-
focus={initialFocus}
|
|
140
|
-
navigateToFileEnd={false}
|
|
141
|
-
commands={[
|
|
142
|
-
{
|
|
143
|
-
name: "ToCommitMessage",
|
|
144
|
-
bindKey: { mac: "Command-Enter", win: "Ctrl-Enter" },
|
|
145
|
-
exec: editor => {
|
|
146
|
-
editor.blur();
|
|
147
|
-
this.props.onBlur?.strgEnter();
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
name: "ToCancelButton",
|
|
152
|
-
bindKey: { mac: "Esc", win: "Esc" },
|
|
153
|
-
exec: editor => {
|
|
154
|
-
editor.blur();
|
|
155
|
-
this.props.onBlur?.esc();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
]}
|
|
159
|
-
/>
|
|
160
|
-
);
|
|
101
|
+
}, [codeSetting.tabSize, content]);
|
|
102
|
+
|
|
103
|
+
if (loading) {
|
|
104
|
+
return <Loading />;
|
|
105
|
+
} else if (error) {
|
|
106
|
+
return <ErrorNotification error={error} />;
|
|
161
107
|
}
|
|
162
|
-
}
|
|
163
108
|
|
|
164
|
-
|
|
109
|
+
return (
|
|
110
|
+
<StyledAceEditor
|
|
111
|
+
className={`is-family-monospace ${className}`}
|
|
112
|
+
mode={currentLanguage}
|
|
113
|
+
onLoad={(editor) => {
|
|
114
|
+
registerTheme(ace);
|
|
115
|
+
editor.setTheme("ace/theme/scm-manager");
|
|
116
|
+
reloadEditor(editor);
|
|
117
|
+
}}
|
|
118
|
+
theme="scm-manager"
|
|
119
|
+
onChange={onChange}
|
|
120
|
+
name="UNIQUE_ID_OF_DIV"
|
|
121
|
+
value={content}
|
|
122
|
+
readOnly={disabled}
|
|
123
|
+
width="100%"
|
|
124
|
+
fontSize="14px"
|
|
125
|
+
onFocus={(event, editor) => {
|
|
126
|
+
reloadEditor(editor as any);
|
|
127
|
+
}}
|
|
128
|
+
setOptions={{ useWorker: false, cursorStyle: "smooth", autoScrollEditorIntoView: true }}
|
|
129
|
+
placeholder={t("scm-editor-plugin.edit.placeholder")}
|
|
130
|
+
focus={initialFocus}
|
|
131
|
+
navigateToFileEnd={false}
|
|
132
|
+
commands={[
|
|
133
|
+
{
|
|
134
|
+
name: "ToCommitMessage",
|
|
135
|
+
bindKey: { mac: "Command-Enter", win: "Ctrl-Enter" },
|
|
136
|
+
exec: (editor) => {
|
|
137
|
+
editor.blur();
|
|
138
|
+
onBlur?.strgEnter();
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "ToCancelButton",
|
|
143
|
+
bindKey: { mac: "Esc", win: "Esc" },
|
|
144
|
+
exec: (editor) => {
|
|
145
|
+
editor.blur();
|
|
146
|
+
onBlur?.esc();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
]}
|
|
150
|
+
/>
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export default CodeEditor;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020 - present Cloudogu GmbH
|
|
3
|
+
*
|
|
4
|
+
* This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
* the terms of the GNU Affero General Public License as published by the Free
|
|
6
|
+
* Software Foundation, version 3.
|
|
7
|
+
*
|
|
8
|
+
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
9
|
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
10
|
+
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
11
|
+
* details.
|
|
12
|
+
*
|
|
13
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
14
|
+
* along with this program. If not, see https://www.gnu.org/licenses/.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { useLocalStorage } from "@scm-manager/ui-api";
|
|
18
|
+
|
|
19
|
+
const LOCAL_STORAGE_KEY = "scm.profile.code.setting";
|
|
20
|
+
|
|
21
|
+
export type CodeSettingConfig = {
|
|
22
|
+
tabSize: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const useCodeSettingValue = () => {
|
|
26
|
+
const [value] = useLocalStorage<CodeSettingConfig>(LOCAL_STORAGE_KEY, { tabSize: 4 });
|
|
27
|
+
|
|
28
|
+
return { value, isLoading: false } as const;
|
|
29
|
+
};
|