import * as React from 'react'; import { ReactWidget } from '@jupyterlab/apputils'; import { ServerConnection } from '@jupyterlab/services'; import { getSnapshotContent } from '../api'; import { INotebook } from '../diff'; import { SnapshotModel } from '../model'; import { CommandIDs } from '../commands'; import { JupyterFrontEnd } from '@jupyterlab/application'; import { INotebookTracker } from '@jupyterlab/notebook'; function formatTimestamp(ts: number): string { // timestamp is microseconds (see backend store.py) const ms = ts / 1000; return new Date(ms).toLocaleString(); } function formatSize(bytes: number): string { if (bytes < 1024) { return `${bytes} B`; } if (bytes < 1024 * 1024) { return `${(bytes / 1024).toFixed(1)} KB`; } return `${(bytes / (1024 * 1024)).toFixed(2)} MB`; } interface PanelProps { model: SnapshotModel; app: JupyterFrontEnd; tracker: INotebookTracker; serverSettings: ServerConnection.ISettings; onOpenDiff: (newNb: INotebook, oldNb: INotebook, name: string) => void; } const Panel: React.FC = ({ model, app, tracker, serverSettings, onOpenDiff }) => { const [, force] = React.useReducer(x => x + 1, 0); React.useEffect(() => { const onChange = () => force(); model.versionsChanged.connect(onChange); return () => { model.versionsChanged.disconnect(onChange); }; }, [model]); if (!model.path) { return
未选中 notebook
; } if (model.loading && model.versions.length === 0) { return
加载中…
; } if (model.versions.length === 0) { return (
暂无快照
点击工具栏「保存快照」按钮创建
); } return ( ); }; export class SnapshotPanel extends ReactWidget { constructor( private readonly _props: PanelProps ) { super(); this.addClass('jp-snapshot-panel'); } render(): React.ReactElement { return ; } }