Skip to content

Commit 64e411e

Browse files
committed
rough card panel satic design added
1 parent 60897bf commit 64e411e

File tree

7 files changed

+146
-18
lines changed

7 files changed

+146
-18
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ yarn-error.log*
3737
next-env.d.ts
3838

3939
.env
40-
.env.test
40+
.env.test
41+
42+
temp/

package-lock.json

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"dependencies": {
1111
"@codemirror/lang-javascript": "^6.2.2",
12+
"@codemirror/legacy-modes": "^6.4.2",
1213
"@codemirror/state": "^6.4.1",
1314
"@codemirror/theme-one-dark": "^6.1.2",
1415
"@codemirror/view": "^6.32.0",
@@ -31,4 +32,4 @@
3132
"eslint-config-next": "^14.2.5",
3233
"typescript": "^5"
3334
}
34-
}
35+
}
+16-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
.code-mirror-container {
2-
width: 100%;
3-
max-width: 100%;
4-
overflow: auto;
5-
height: 200px;
6-
box-sizing: border-box;
7-
}
1+
.comp-code-mirror {
2+
flex-grow: 1;
3+
display: flex;
4+
overflow: auto;
5+
box-sizing: border-box;
6+
height: 100px;
7+
8+
.cm-editor {
9+
flex-grow: 1;
10+
background-color: #111111;
11+
}
12+
13+
.cm-gutters {
14+
background-color: #202020;
15+
}
16+
}

src/app/components/CodeMirrorEditor/index.tsx

+27-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
import React, { useRef, useEffect, useImperativeHandle } from 'react';
1+
import React, { useRef, useEffect, useImperativeHandle, useState } from 'react';
22
import { EditorView, basicSetup } from 'codemirror';
33
import { EditorState } from '@codemirror/state';
44
import { javascript } from '@codemirror/lang-javascript';
5+
import { StreamLanguage } from '@codemirror/language';
6+
import { shell as shellMode } from '@codemirror/legacy-modes/mode/shell';
7+
58
import { oneDark } from '@codemirror/theme-one-dark';
69

710
import './index.css';
811

12+
import { redisSupport } from './redis-support';
13+
914
interface CodeMirrorEditorProps {
1015
initialValue?: string;
1116
className?: string;
1217
tabIndex?: number;
1318
onBlur?: (code: string) => void;
1419
disabled?: boolean;
20+
mode?: 'javascript' | 'shell' | 'redis';
1521
}
1622

23+
1724
const CodeMirrorEditor = React.forwardRef<EditorView | null, CodeMirrorEditorProps>(
1825
({
1926
initialValue = '',
2027
className = '',
2128
tabIndex = 99,
2229
onBlur,
23-
disabled = false
30+
disabled = false,
31+
mode = 'javascript'
2432
}, ref) => {
2533
const editorContainerRef = useRef<HTMLDivElement>(null);
2634
const editorViewRef = useRef<EditorView | null>(null);
@@ -42,12 +50,19 @@ const CodeMirrorEditor = React.forwardRef<EditorView | null, CodeMirrorEditorPro
4250
return;
4351
}
4452

53+
let modeElm: any = javascript();
54+
if (mode === 'shell') {
55+
modeElm = StreamLanguage.define(shellMode);
56+
} else if (mode === 'redis') {
57+
modeElm = redisSupport;
58+
}
59+
4560
// Create a new editor state with initial value and extensions
4661
const state = EditorState.create({
4762
doc: initialValue,
4863
extensions: [
4964
basicSetup,
50-
javascript(),
65+
modeElm,
5166
oneDark,
5267
EditorView.editable.of(!disabled), // editor read-only if disabled
5368
],
@@ -71,11 +86,15 @@ const CodeMirrorEditor = React.forwardRef<EditorView | null, CodeMirrorEditorPro
7186
// eslint-disable-next-line react-hooks/exhaustive-deps
7287
}, [ref, disabled]);
7388

74-
return <div ref={editorContainerRef}
75-
className={`code-mirror-container ${className}`}
76-
tabIndex={tabIndex}
77-
onBlur={onEditorBlur}
78-
/>;
89+
90+
return (
91+
<div ref={editorContainerRef}
92+
className={`comp-code-mirror ${className}`}
93+
tabIndex={tabIndex}
94+
onBlur={onEditorBlur}
95+
/>
96+
)
97+
7998
}
8099
);
81100

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import {
2+
LRLanguage,
3+
LanguageSupport,
4+
defineLanguageFacet,
5+
} from "@codemirror/language";
6+
import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
7+
import { tags } from "@lezer/highlight";
8+
import { StreamLanguage } from "@codemirror/language";
9+
10+
// Define Redis language with explicit tag mapping
11+
const redisLanguage = StreamLanguage.define({
12+
name: "redis",
13+
14+
token(stream, state) {
15+
if (stream.eatSpace()) return null;
16+
17+
// Commands
18+
if (stream.match(/^(GET|HGET|PING|KEYS|LRANGE)\b/i)) {
19+
return "keyword";
20+
}
21+
22+
// Extended Commands
23+
if (stream.match(/^(FT\.CREATE|FT\.SEARCH)\b/i)) {
24+
return "keyword";
25+
}
26+
27+
// Numbers
28+
if (stream.match(/^\d+/)) {
29+
return "number";
30+
}
31+
32+
// JSON paths and other identifiers
33+
if (stream.match(/^\$\.?\w*/)) {
34+
return "property";
35+
}
36+
37+
// Tags and other variables
38+
if (stream.match(/^\w+/)) {
39+
return "variable";
40+
}
41+
42+
// Strings (e.g., '{dbIndexName}', '{keyPrefix}')
43+
if (stream.match(/^'.*?'|".*?"/)) {
44+
return "string";
45+
}
46+
47+
// Brackets and delimiters
48+
if (stream.match(/^[\[\](),;]/)) {
49+
return "bracket";
50+
}
51+
52+
stream.next();
53+
return null;
54+
},
55+
});
56+
57+
// Define highlighting style
58+
const redisHighlightStyle = HighlightStyle.define([
59+
// Commands (FT.CREATE, GET, SET, etc.)
60+
{
61+
tag: tags.keyword,
62+
color: "#c8b6f3", //#111111
63+
//fontWeight: "bold",
64+
},
65+
66+
// Variables and identifiers
67+
{ tag: tags.variableName, color: "#c98e75" },
68+
69+
// Numbers
70+
{ tag: tags.number, color: "#98c379" },
71+
72+
// JSON paths ($.productId)
73+
{ tag: tags.propertyName, color: "#e5c07b" },
74+
75+
// Strings (quoted values)
76+
{ tag: tags.string, color: "#e06c75" },
77+
78+
// Brackets and delimiters
79+
{ tag: tags.bracket, color: "#56b6c2" },
80+
]);
81+
82+
// Create language support with highlighting
83+
export const redisSupport = new LanguageSupport(redisLanguage, [
84+
syntaxHighlighting(redisHighlightStyle),
85+
]);

src/app/globals.css

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ body {
5050
}
5151

5252
body {
53-
color: rgb(var(--foreground-rgb));
53+
/* color: rgb(var(--foreground-rgb)); */
54+
background-color: #111111;
55+
color: #eaeaeb;
5456
}
5557

5658
a {

0 commit comments

Comments
 (0)