Skip to content

Commit 2cf9892

Browse files
authored
feat: support upload and display jsonl file (#21)
* feat: support jsonl file * chore: update pnpm-lock * chore: format files * chore: add pyproject rules
1 parent 573a197 commit 2cf9892

File tree

10 files changed

+2327
-3080
lines changed

10 files changed

+2327
-3080
lines changed

.vscode/cspell.json

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"fdspawn",
3030
"getipython",
3131
"grpcio",
32+
"highlightjs",
33+
"hljs",
3234
"ifaddresses",
3335
"iloc",
3436
"INET",

packages/secretnote-ui/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
4-
"outDir": "build"
4+
"outDir": "build",
55
},
66
"include": ["./src/**/*", "./src/.openapi-stubs/**/*"],
7-
"references": [{ "path": "./tsconfig.node.json" }]
7+
"references": [{ "path": "./tsconfig.node.json" }],
88
}

packages/secretnote/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"classnames": "^2.3.2",
6262
"d3-dsv": "^3.0.1",
6363
"endent": "^2.1.0",
64+
"highlight.js": "^11.9.0",
6465
"lodash-es": "^4.17.21",
6566
"lucide-react": "^0.284.0",
6667
"monaco-editor": "^0.45.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { singleton } from '@difizen/mana-app';
2+
import hljs from 'highlight.js';
3+
import { useEffect } from 'react';
4+
5+
import { FilePreviewContribution } from './protocol';
6+
import 'highlight.js/styles/xcode.css'; // 选择主题 https://highlightjs.org/demo
7+
8+
const JsonlView = (props: { data: string }) => {
9+
useEffect(() => {
10+
hljs.highlightAll();
11+
}, []);
12+
13+
// 创建行号
14+
const lineNumber = props.data
15+
.trim()
16+
.split('\n')
17+
.map((_, index) => `${index + 1}\n`)
18+
.join('');
19+
20+
return (
21+
<pre style={{ width: '100%', height: '100%', overflow: 'scroll', margin: 0 }}>
22+
<span
23+
style={{
24+
float: 'left',
25+
textAlign: 'right',
26+
marginRight: 12,
27+
color: '#bfbfbf',
28+
userSelect: 'none',
29+
}}
30+
>
31+
{lineNumber}
32+
</span>
33+
<code className="language-json" style={{ padding: '0 1em' }}>
34+
{props.data}
35+
</code>
36+
</pre>
37+
);
38+
};
39+
40+
@singleton({ contrib: [FilePreviewContribution] })
41+
export class JsonlPreview implements FilePreviewContribution {
42+
type = 'jsonl';
43+
render = (data: string) => {
44+
return <JsonlView data={data} />;
45+
};
46+
}

packages/secretnote/src/modules/file/module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { SecretNoteServerModule } from '@/modules/server';
66

77
import { CsvPreview } from './csv-preview-contrib';
88
import { ExtraView } from './extra-view';
9+
import { JsonlPreview } from './jsonl-preview-contrib';
910
import { LogPreview } from './log-preview-contrib';
1011
import { FilePreviewView } from './preview-view';
1112
import { FilePreviewContribution } from './protocol';
@@ -35,6 +36,7 @@ export const FilePreviewModule = ManaModule.create()
3536
FilePreviewView,
3637
CsvPreview,
3738
LogPreview,
39+
JsonlPreview,
3840
createViewPreference({
3941
slot: PreviewLayoutArea.main,
4042
view: FilePreviewView,

packages/secretnote/src/modules/file/service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { downloadFileByUrl as download } from '@/utils';
88
import { SecretNoteServerManager } from '../server';
99

1010
export const BASE_PATH = '/';
11-
export const FILE_EXTS = ['.csv', '.log', '.txt'];
11+
export const FILE_EXTS = ['.csv', '.log', '.txt', '.jsonl'];
1212
@singleton()
1313
export class FileService {
1414
protected readonly contentsManager: ContentsManager;

packages/secretnote/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"compilerOptions": {
44
"experimentalDecorators": true,
55
"emitDecoratorMetadata": true,
6-
"importHelpers": false
7-
}
6+
"importHelpers": false,
7+
},
88
}

0 commit comments

Comments
 (0)