From 5272598a07f76b59eeecfd4ce10802a090ef3dd9 Mon Sep 17 00:00:00 2001 From: sunshinesmilelk <1176136681@qq.com> Date: Wed, 6 Dec 2023 21:05:52 +0800 Subject: [PATCH] fix: improve details --- .../libro-jupyter/src/file/file-command.tsx | 6 +- .../src/file/file-create-modal.tsx | 3 +- .../src/file/file-createdir-modal.tsx | 12 ++- packages/libro-jupyter/src/file/index.ts | 2 + packages/libro-lab/src/common/icon.tsx | 63 +-------------- packages/libro-lab/src/index.less | 9 +++ .../libro-lab/src/layout/layout-service.ts | 3 +- packages/libro-lab/src/layout/module.ts | 2 +- ...tor-tab-view.tsx => saveable-tab-view.tsx} | 2 +- packages/libro-lab/src/module.tsx | 2 +- .../src/toc/libro-toc-panel-view.tsx | 3 +- .../src/welcome/entry-point-view.tsx | 80 +++++++++++++++---- packages/libro-lab/src/welcome/index.tsx | 10 ++- 13 files changed, 97 insertions(+), 100 deletions(-) rename packages/libro-lab/src/layout/{editor-tab-view.tsx => saveable-tab-view.tsx} (97%) diff --git a/packages/libro-jupyter/src/file/file-command.tsx b/packages/libro-jupyter/src/file/file-command.tsx index 1065d0d3..a7dba605 100644 --- a/packages/libro-jupyter/src/file/file-command.tsx +++ b/packages/libro-jupyter/src/file/file-command.tsx @@ -257,7 +257,7 @@ export class FileCommandContribution }); command.registerCommand(FileCommands.CREATE_FILE, { execute: async (data) => { - let path = '/'; + let path = this.fileView.model.location?.path.toString() || '/'; if (FileStatNode.is(data)) { path = data.fileStat.isDirectory ? data.uri.path.toString() @@ -270,7 +270,7 @@ export class FileCommandContribution }); command.registerCommand(FileCommands.CREATE_DIR, { execute: async (data) => { - let path = '/'; + let path = this.fileView.model.location?.path.toString() || '/'; if (FileStatNode.is(data)) { path = data.fileStat.isDirectory ? data.uri.path.toString() @@ -284,7 +284,7 @@ export class FileCommandContribution command.registerCommand(FileCommands.COPY_PATH, { execute: async (data) => { - let path = '/'; + let path = this.fileView.model.location?.path.toString() || '/'; if (FileStatNode.is(data)) { path = data.uri.path.toString(); } diff --git a/packages/libro-jupyter/src/file/file-create-modal.tsx b/packages/libro-jupyter/src/file/file-create-modal.tsx index 87294644..b098f3eb 100644 --- a/packages/libro-jupyter/src/file/file-create-modal.tsx +++ b/packages/libro-jupyter/src/file/file-create-modal.tsx @@ -16,6 +16,7 @@ import { export interface ModalItemType { path: string; + fileType?: FileType; } type FileType = '.ipynb' | '.py' | '.json' | '.sql' | undefined; @@ -27,7 +28,7 @@ export const FileCreateModalComponent: React.FC> = }: ModalItemProps) => { const fileService = useInject(JupyterFileService); const viewManager = useInject(ViewManager); - const [fileType, setFileType] = useState(undefined); + const [fileType, setFileType] = useState(data.fileType); const [fileView, setFileView] = useState(); const inputRef = useRef(null); const [form] = Form.useForm(); diff --git a/packages/libro-jupyter/src/file/file-createdir-modal.tsx b/packages/libro-jupyter/src/file/file-createdir-modal.tsx index 655f0e24..5c8aec83 100644 --- a/packages/libro-jupyter/src/file/file-createdir-modal.tsx +++ b/packages/libro-jupyter/src/file/file-createdir-modal.tsx @@ -10,15 +10,13 @@ import { JupyterFileService } from './file-service.js'; import { FileView } from './file-view/index.js'; import './index.less'; -export interface ModalItemType { +export interface FileDirCreateModalItemType { path: string; } -export const FileCreateDirModalComponent: React.FC> = ({ - visible, - close, - data, -}: ModalItemProps) => { +export const FileCreateDirModalComponent: React.FC< + ModalItemProps +> = ({ visible, close, data }: ModalItemProps) => { const fileService = useInject(JupyterFileService); const viewManager = useInject(ViewManager); const inputRef = useRef(null); @@ -104,7 +102,7 @@ export const FileCreateDirModalComponent: React.FC ); }; -export const FileDirCreateModal: ModalItem = { +export const FileDirCreateModal: ModalItem = { id: 'file.createdir.modal', component: FileCreateDirModalComponent, }; diff --git a/packages/libro-jupyter/src/file/index.ts b/packages/libro-jupyter/src/file/index.ts index 9f418d47..09571d9e 100644 --- a/packages/libro-jupyter/src/file/index.ts +++ b/packages/libro-jupyter/src/file/index.ts @@ -5,3 +5,5 @@ export * from './open-handler-contribution.js'; export * from './file-service.js'; export * from './file-protocol.js'; export * from './file-icon.js'; +export * from './file-create-modal.js'; +export * from './file-createdir-modal.js'; diff --git a/packages/libro-lab/src/common/icon.tsx b/packages/libro-lab/src/common/icon.tsx index 02234894..d55e4f9a 100644 --- a/packages/libro-lab/src/common/icon.tsx +++ b/packages/libro-lab/src/common/icon.tsx @@ -1,4 +1,5 @@ import './index.less'; + export interface IProps { className?: string; width?: string; @@ -70,68 +71,6 @@ export function TocIcon(props: IProps) { ); } -export function WelcomeIcon(props: IProps) { - return ( - - - - - - - - - - - - - - - - - - ); -} - export function Loadding(props: IProps) { return ( handler()); + return slotView.onActiveChange(handler); } } return undefined; diff --git a/packages/libro-lab/src/layout/module.ts b/packages/libro-lab/src/layout/module.ts index c55caae8..7d48f8a4 100644 --- a/packages/libro-lab/src/layout/module.ts +++ b/packages/libro-lab/src/layout/module.ts @@ -8,7 +8,6 @@ import { import { BrandView } from './brand/index.js'; import { LibroLabLayoutContainerView } from './container.js'; -import { SaveableTabView } from './editor-tab-view.js'; import { LibroLabCurrentFileFooterView } from './footer/current-file-footer-view.js'; import { FooterArea, LibroLabLayoutFooterView } from './footer/footer-view.js'; import { LibroLabStatusFooterView } from './footer/status-footer-view.js'; @@ -16,6 +15,7 @@ import { LayoutService } from './layout-service.js'; import { LibroLabLayoutView } from './layout.js'; import { LibroLabLayoutMainView } from './main.js'; import { LibroLabLayoutSlots } from './protocol.js'; +import { SaveableTabView } from './saveable-tab-view.js'; export const LibroLabLayoutModule = ManaModule.create('LibroLabLayoutModule').register( LibroLabLayoutView, diff --git a/packages/libro-lab/src/layout/editor-tab-view.tsx b/packages/libro-lab/src/layout/saveable-tab-view.tsx similarity index 97% rename from packages/libro-lab/src/layout/editor-tab-view.tsx rename to packages/libro-lab/src/layout/saveable-tab-view.tsx index d3a8e5ea..0373fa51 100644 --- a/packages/libro-lab/src/layout/editor-tab-view.tsx +++ b/packages/libro-lab/src/layout/saveable-tab-view.tsx @@ -1,12 +1,12 @@ import { CloseOutlined } from '@ant-design/icons'; import type { View } from '@difizen/mana-app'; -import { Saveable } from '@difizen/mana-app'; import { CardTabView, MenuRender, transient, view, ViewContext, + Saveable, } from '@difizen/mana-app'; import { Dropdown } from '@difizen/mana-react'; import { Badge } from 'antd'; diff --git a/packages/libro-lab/src/module.tsx b/packages/libro-lab/src/module.tsx index b07cb9e7..2bc6d653 100644 --- a/packages/libro-lab/src/module.tsx +++ b/packages/libro-lab/src/module.tsx @@ -11,12 +11,12 @@ import { import { GithubLinkView } from './github-link/index.js'; import { KernelManagerView } from './kernel-manager/index.js'; import { LibroLabApp } from './lab-app.js'; -import { SaveableTabView } from './layout/editor-tab-view.js'; import { LibroLabLayoutModule, LibroLabLayoutSlots, LibroLabLayoutView, } from './layout/index.js'; +import { SaveableTabView } from './layout/saveable-tab-view.js'; import './index.less'; import { LibroLabHeaderMenuModule } from './menu/module.js'; import { LibroLabTocModule } from './toc/module.js'; diff --git a/packages/libro-lab/src/toc/libro-toc-panel-view.tsx b/packages/libro-lab/src/toc/libro-toc-panel-view.tsx index b2af4774..d580f02a 100644 --- a/packages/libro-lab/src/toc/libro-toc-panel-view.tsx +++ b/packages/libro-lab/src/toc/libro-toc-panel-view.tsx @@ -12,8 +12,8 @@ import { ViewRender, } from '@difizen/mana-app'; import { Empty } from 'antd'; -import { TocIcon } from '../common/index.js'; +import { TocIcon } from '../common/index.js'; import { LayoutService } from '../layout/layout-service.js'; import { LibroLabLayoutSlots } from '../layout/protocol.js'; @@ -69,6 +69,7 @@ export class TocPanelView extends BaseView { handleEditTabChange = () => { if (!this.libroNavigatableView) { + this.libroTocView = undefined; return; } this.viewManager diff --git a/packages/libro-lab/src/welcome/entry-point-view.tsx b/packages/libro-lab/src/welcome/entry-point-view.tsx index 6e0766ca..e21e6531 100644 --- a/packages/libro-lab/src/welcome/entry-point-view.tsx +++ b/packages/libro-lab/src/welcome/entry-point-view.tsx @@ -1,19 +1,43 @@ -import { singleton, view } from '@difizen/mana-app'; -import { BaseView } from '@difizen/mana-app'; import { NotebookIcon, PythonIcon, JSONIcon, - SQLIcon, MoreIcon, + FileCreateModal, + FileView, } from '@difizen/libro-jupyter'; +import { + ModalService, + singleton, + useInject, + view, + ViewManager, +} from '@difizen/mana-app'; +import { BaseView } from '@difizen/mana-app'; import { Col, Row } from 'antd'; -import { forwardRef } from 'react'; +import { forwardRef, useEffect, useState } from 'react'; + import { KeybindIcon, PreferenceIcon, TerminalIcon } from '../common/icon.js'; import './index.less'; export const EntryPointComponent = forwardRef(function EntryPointComponent() { + const modalService = useInject(ModalService); + const viewManager = useInject(ViewManager); + const [fileView, setFileView] = useState(); + + useEffect(() => { + viewManager + .getOrCreateView(FileView) + .then((curfileView) => { + setFileView(curfileView); + return; + }) + .catch(() => { + // + }); + }, [viewManager]); + return (
请选择你要创建的文件类型:
@@ -23,7 +47,15 @@ export const EntryPointComponent = forwardRef(function EntryPointComponent() { className="gutter-row" style={{ paddingLeft: 'unset', paddingRight: '32px' }} > -
+
{ + modalService.openModal(FileCreateModal, { + path: fileView?.model.location?.path.toString() || '/', + fileType: '.ipynb', + }); + }} + > Notebook
@@ -32,7 +64,15 @@ export const EntryPointComponent = forwardRef(function EntryPointComponent() { className="gutter-row" style={{ paddingLeft: 'unset', paddingRight: '32px' }} > -
+
{ + modalService.openModal(FileCreateModal, { + path: fileView?.model.location?.path.toString() || '/', + fileType: '.py', + }); + }} + > Python
@@ -41,7 +81,15 @@ export const EntryPointComponent = forwardRef(function EntryPointComponent() { className="gutter-row" style={{ paddingLeft: 'unset', paddingRight: '32px' }} > -
+
{ + modalService.openModal(FileCreateModal, { + path: fileView?.model.location?.path.toString() || '/', + fileType: '.json', + }); + }} + > JSON
@@ -50,16 +98,14 @@ export const EntryPointComponent = forwardRef(function EntryPointComponent() { className="gutter-row" style={{ paddingLeft: 'unset', paddingRight: '32px' }} > -
- - SQL -
- - -
+
{ + modalService.openModal(FileCreateModal, { + path: fileView?.model.location?.path.toString() || '/', + }); + }} + > 其他
diff --git a/packages/libro-lab/src/welcome/index.tsx b/packages/libro-lab/src/welcome/index.tsx index 8ad96e01..6eae7106 100644 --- a/packages/libro-lab/src/welcome/index.tsx +++ b/packages/libro-lab/src/welcome/index.tsx @@ -10,8 +10,9 @@ import { } from '@difizen/mana-app'; import { BaseView } from '@difizen/mana-app'; import { forwardRef } from 'react'; -import { WelcomeIcon } from '../common/index.js'; + import { LayoutService } from '../layout/layout-service.js'; + import { EntryPointView } from './entry-point-view.js'; import './index.less'; @@ -35,7 +36,7 @@ export const WelcomeComponent = forwardRef(function WelcomeComponent() { WsURL: {`${serverConnection.settings.wsUrl}`}
- {layoutService.serverSatus !== 'loading' && ( + {layoutService.serverSatus === 'success' && ( )}
@@ -52,11 +53,12 @@ export class WelcomeView extends BaseView { super(); this.title.icon = '🙌 '; this.title.label = '欢迎使用'; + this.title.closable = false; this.viewManager = viewManager; this.viewManager .getOrCreateView(EntryPointView) - .then((view) => { - this.entryPointView = view; + .then((entryPointView) => { + this.entryPointView = entryPointView; return; }) .catch(() => {