@nethru/ui 2.1.14 → 2.1.15
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/base/Slider.js +0 -1
- package/base/editor/Editor.js +29 -1
- package/package.json +6 -1
package/base/Slider.js
CHANGED
package/base/editor/Editor.js
CHANGED
|
@@ -11,6 +11,8 @@ import borderRadius from "../styles/borderRadius";
|
|
|
11
11
|
import { blue, grey, red, yellow } from "../colors";
|
|
12
12
|
import typography from "../styles/typography";
|
|
13
13
|
import shadow from "../styles/shadow";
|
|
14
|
+
import { linter } from "@codemirror/lint";
|
|
15
|
+
import { Linter } from "eslint-linter-browserify";
|
|
14
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
17
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
18
|
export default function Editor({
|
|
@@ -20,6 +22,7 @@ export default function Editor({
|
|
|
20
22
|
helperText,
|
|
21
23
|
basicSetup,
|
|
22
24
|
keymap = [],
|
|
25
|
+
eslintRules,
|
|
23
26
|
extensions = [],
|
|
24
27
|
format = 'javascript',
|
|
25
28
|
keyword,
|
|
@@ -30,6 +33,7 @@ export default function Editor({
|
|
|
30
33
|
onScroll,
|
|
31
34
|
onFocus,
|
|
32
35
|
onBlur,
|
|
36
|
+
onEslintUpdate,
|
|
33
37
|
style,
|
|
34
38
|
...props
|
|
35
39
|
}) {
|
|
@@ -140,12 +144,36 @@ export default function Editor({
|
|
|
140
144
|
});
|
|
141
145
|
}
|
|
142
146
|
}, [format]);
|
|
147
|
+
const eslintLinter = useMemo(() => {
|
|
148
|
+
return format === 'javascript' ? linter(view => {
|
|
149
|
+
const text = view.state.doc.toString();
|
|
150
|
+
const linter = new Linter();
|
|
151
|
+
const config = {
|
|
152
|
+
rules: {
|
|
153
|
+
"func-names": "off",
|
|
154
|
+
"no-unused-expressions": "off",
|
|
155
|
+
...eslintRules
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const hints = linter.verify(text, config).map(hint => ({
|
|
159
|
+
line: hint.line,
|
|
160
|
+
column: hint.column,
|
|
161
|
+
from: view.state.doc.line(hint.line).from + hint.column - 1,
|
|
162
|
+
to: view.state.doc.line(hint.line).from + hint.column - 1 + (linter.getSourceCode()?.length || 0),
|
|
163
|
+
severity: hint.severity === 2 ? "error" : "warning",
|
|
164
|
+
message: hint.message
|
|
165
|
+
}));
|
|
166
|
+
if (onEslintUpdate) onEslintUpdate(hints);
|
|
167
|
+
return hints;
|
|
168
|
+
}) : undefined;
|
|
169
|
+
}, [format, eslintRules, onEslintUpdate]);
|
|
143
170
|
const keymapExtension = useMemo(() => {
|
|
144
171
|
return [keyMapper.of(keymap), keyMapper.of(defaultKeymap)];
|
|
145
172
|
}, [keymap]);
|
|
146
173
|
const extensionList = useMemo(() => {
|
|
147
174
|
const result = [EditorView.lineWrapping, highlight.extension, ...keymapExtension];
|
|
148
175
|
if (languageExtension) result.push(languageExtension);
|
|
176
|
+
if (eslintLinter) result.push(eslintLinter);
|
|
149
177
|
if (onScroll) {
|
|
150
178
|
result.push(EditorView.domEventHandlers({
|
|
151
179
|
scroll(event, view) {
|
|
@@ -156,7 +184,7 @@ export default function Editor({
|
|
|
156
184
|
}
|
|
157
185
|
result.push(...extensions);
|
|
158
186
|
return result;
|
|
159
|
-
}, [languageExtension, highlight.extension, keymapExtension, extensions, onScroll]);
|
|
187
|
+
}, [languageExtension, eslintLinter, highlight.extension, keymapExtension, extensions, onScroll]);
|
|
160
188
|
const handleUpdate = viewUpdate => {
|
|
161
189
|
setFocused(viewUpdate.view.hasFocus);
|
|
162
190
|
if (onUpdate) onUpdate(viewUpdate);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nethru/ui",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.15",
|
|
4
4
|
"main": "base/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"/base"
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@codemirror/lang-javascript": "^6.2.1",
|
|
10
10
|
"@codemirror/lang-json": "^6.0.1",
|
|
11
|
+
"@codemirror/lint": "^6.8.4",
|
|
11
12
|
"@emotion/react": "^11.13.3",
|
|
12
13
|
"@emotion/styled": "^11.13.0",
|
|
13
14
|
"@fontsource/roboto": "^5.0.8",
|
|
@@ -24,6 +25,10 @@
|
|
|
24
25
|
"@uiw/react-codemirror": "^4.21.21",
|
|
25
26
|
"dayjs": "^1.11.13",
|
|
26
27
|
"days": "^1.1.1",
|
|
28
|
+
"eslint-browser": "^3.8.1",
|
|
29
|
+
"eslint-linter-browserify": "^9.17.0",
|
|
30
|
+
"eslint-utils": "^3.0.0",
|
|
31
|
+
"eslint4b": "^7.32.0",
|
|
27
32
|
"immer": "^10.0.3",
|
|
28
33
|
"react": "^18.2.0",
|
|
29
34
|
"react-dom": "^18.2.0",
|