@nethru/ui 2.1.14 → 2.1.16
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 +50 -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,8 @@ export default function Editor({
|
|
|
20
22
|
helperText,
|
|
21
23
|
basicSetup,
|
|
22
24
|
keymap = [],
|
|
25
|
+
eslintRules,
|
|
26
|
+
customVariables = [],
|
|
23
27
|
extensions = [],
|
|
24
28
|
format = 'javascript',
|
|
25
29
|
keyword,
|
|
@@ -30,6 +34,7 @@ export default function Editor({
|
|
|
30
34
|
onScroll,
|
|
31
35
|
onFocus,
|
|
32
36
|
onBlur,
|
|
37
|
+
onEslintUpdate,
|
|
33
38
|
style,
|
|
34
39
|
...props
|
|
35
40
|
}) {
|
|
@@ -140,12 +145,56 @@ export default function Editor({
|
|
|
140
145
|
});
|
|
141
146
|
}
|
|
142
147
|
}, [format]);
|
|
148
|
+
const eslintLinter = useMemo(() => {
|
|
149
|
+
const regex = /\{\{(\S+)\}\}/g;
|
|
150
|
+
return format === 'javascript' ? linter(view => {
|
|
151
|
+
const text = view.state.doc.toString();
|
|
152
|
+
const linter = new Linter();
|
|
153
|
+
let replaced = text;
|
|
154
|
+
let hints = [];
|
|
155
|
+
const config = {
|
|
156
|
+
rules: {
|
|
157
|
+
"func-names": "off",
|
|
158
|
+
"no-unused-expressions": "off",
|
|
159
|
+
...eslintRules
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
if (customVariables.length > 0) {
|
|
163
|
+
let match;
|
|
164
|
+
while ((match = regex.exec(text)) !== null) {
|
|
165
|
+
if (!customVariables.includes(match[1])) {
|
|
166
|
+
hints.push({
|
|
167
|
+
from: match.index + 2,
|
|
168
|
+
to: match.index + 2,
|
|
169
|
+
severity: 'error',
|
|
170
|
+
message: `${match[1]}는 정의된 변수가 아닙니다.`
|
|
171
|
+
});
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
replaced = text.replace(regex, () => `''`);
|
|
176
|
+
}
|
|
177
|
+
if (hints.length === 0) {
|
|
178
|
+
hints = linter.verify(replaced, config).map(hint => ({
|
|
179
|
+
line: hint.line,
|
|
180
|
+
column: hint.column,
|
|
181
|
+
from: view.state.doc.line(hint.line).from + hint.column - 1,
|
|
182
|
+
to: view.state.doc.line(hint.line).from + hint.column - 1 + (linter.getSourceCode()?.length || 0),
|
|
183
|
+
severity: hint.severity === 2 ? "error" : "warning",
|
|
184
|
+
message: hint.message
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
if (onEslintUpdate) onEslintUpdate(hints);
|
|
188
|
+
return hints;
|
|
189
|
+
}) : undefined;
|
|
190
|
+
}, [format, eslintRules, onEslintUpdate, customVariables]);
|
|
143
191
|
const keymapExtension = useMemo(() => {
|
|
144
192
|
return [keyMapper.of(keymap), keyMapper.of(defaultKeymap)];
|
|
145
193
|
}, [keymap]);
|
|
146
194
|
const extensionList = useMemo(() => {
|
|
147
195
|
const result = [EditorView.lineWrapping, highlight.extension, ...keymapExtension];
|
|
148
196
|
if (languageExtension) result.push(languageExtension);
|
|
197
|
+
if (eslintLinter) result.push(eslintLinter);
|
|
149
198
|
if (onScroll) {
|
|
150
199
|
result.push(EditorView.domEventHandlers({
|
|
151
200
|
scroll(event, view) {
|
|
@@ -156,7 +205,7 @@ export default function Editor({
|
|
|
156
205
|
}
|
|
157
206
|
result.push(...extensions);
|
|
158
207
|
return result;
|
|
159
|
-
}, [languageExtension, highlight.extension, keymapExtension, extensions, onScroll]);
|
|
208
|
+
}, [languageExtension, eslintLinter, highlight.extension, keymapExtension, extensions, onScroll]);
|
|
160
209
|
const handleUpdate = viewUpdate => {
|
|
161
210
|
setFocused(viewUpdate.view.hasFocus);
|
|
162
211
|
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.16",
|
|
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": "^8.20.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",
|