Skip to content

Commit

Permalink
feat: support upload and display jsonl file (#21)
Browse files Browse the repository at this point in the history
* feat: support jsonl file

* chore: update pnpm-lock

* chore: format files

* chore: add pyproject rules
  • Loading branch information
myzxlin authored Feb 1, 2024
1 parent 573a197 commit 2cf9892
Show file tree
Hide file tree
Showing 10 changed files with 2,327 additions and 3,080 deletions.
2 changes: 2 additions & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"fdspawn",
"getipython",
"grpcio",
"highlightjs",
"hljs",
"ifaddresses",
"iloc",
"INET",
Expand Down
4 changes: 2 additions & 2 deletions packages/secretnote-ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "build"
"outDir": "build",
},
"include": ["./src/**/*", "./src/.openapi-stubs/**/*"],
"references": [{ "path": "./tsconfig.node.json" }]
"references": [{ "path": "./tsconfig.node.json" }],
}
1 change: 1 addition & 0 deletions packages/secretnote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"classnames": "^2.3.2",
"d3-dsv": "^3.0.1",
"endent": "^2.1.0",
"highlight.js": "^11.9.0",
"lodash-es": "^4.17.21",
"lucide-react": "^0.284.0",
"monaco-editor": "^0.45.0",
Expand Down
46 changes: 46 additions & 0 deletions packages/secretnote/src/modules/file/jsonl-preview-contrib.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { singleton } from '@difizen/mana-app';
import hljs from 'highlight.js';
import { useEffect } from 'react';

import { FilePreviewContribution } from './protocol';
import 'highlight.js/styles/xcode.css'; // 选择主题 https://highlightjs.org/demo

const JsonlView = (props: { data: string }) => {
useEffect(() => {
hljs.highlightAll();
}, []);

// 创建行号
const lineNumber = props.data
.trim()
.split('\n')
.map((_, index) => `${index + 1}\n`)
.join('');

return (
<pre style={{ width: '100%', height: '100%', overflow: 'scroll', margin: 0 }}>
<span
style={{
float: 'left',
textAlign: 'right',
marginRight: 12,
color: '#bfbfbf',
userSelect: 'none',
}}
>
{lineNumber}
</span>
<code className="language-json" style={{ padding: '0 1em' }}>
{props.data}
</code>
</pre>
);
};

@singleton({ contrib: [FilePreviewContribution] })
export class JsonlPreview implements FilePreviewContribution {
type = 'jsonl';
render = (data: string) => {
return <JsonlView data={data} />;
};
}
2 changes: 2 additions & 0 deletions packages/secretnote/src/modules/file/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SecretNoteServerModule } from '@/modules/server';

import { CsvPreview } from './csv-preview-contrib';
import { ExtraView } from './extra-view';
import { JsonlPreview } from './jsonl-preview-contrib';
import { LogPreview } from './log-preview-contrib';
import { FilePreviewView } from './preview-view';
import { FilePreviewContribution } from './protocol';
Expand Down Expand Up @@ -35,6 +36,7 @@ export const FilePreviewModule = ManaModule.create()
FilePreviewView,
CsvPreview,
LogPreview,
JsonlPreview,
createViewPreference({
slot: PreviewLayoutArea.main,
view: FilePreviewView,
Expand Down
2 changes: 1 addition & 1 deletion packages/secretnote/src/modules/file/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { downloadFileByUrl as download } from '@/utils';
import { SecretNoteServerManager } from '../server';

export const BASE_PATH = '/';
export const FILE_EXTS = ['.csv', '.log', '.txt'];
export const FILE_EXTS = ['.csv', '.log', '.txt', '.jsonl'];
@singleton()
export class FileService {
protected readonly contentsManager: ContentsManager;
Expand Down
4 changes: 2 additions & 2 deletions packages/secretnote/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"importHelpers": false
}
"importHelpers": false,
},
}
Loading

0 comments on commit 2cf9892

Please sign in to comment.