@difizen/libro-jupyter 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/es/components/icons.d.ts +5 -0
  2. package/es/components/icons.d.ts.map +1 -0
  3. package/es/components/index.less +1 -0
  4. package/es/config/config.d.ts +3 -0
  5. package/es/config/config.d.ts.map +1 -0
  6. package/es/configuration/index.d.ts +3 -0
  7. package/es/configuration/index.d.ts.map +1 -0
  8. package/es/configuration/libro-configuration-contribution.d.ts +5 -0
  9. package/es/configuration/libro-configuration-contribution.d.ts.map +1 -0
  10. package/es/configuration/libro-configuration.d.ts +3 -0
  11. package/es/configuration/libro-configuration.d.ts.map +1 -0
  12. package/es/file/file-command.d.ts +1 -0
  13. package/es/file/file-command.d.ts.map +1 -1
  14. package/es/file/file-command.js +14 -6
  15. package/es/file/file-create-modal.d.ts +5 -1
  16. package/es/file/file-create-modal.d.ts.map +1 -1
  17. package/es/file/file-create-modal.js +178 -56
  18. package/es/file/file-createdir-modal-contribution.d.ts +1 -1
  19. package/es/file/file-createdir-modal.d.ts +4 -3
  20. package/es/file/file-createdir-modal.d.ts.map +1 -1
  21. package/es/file/file-createdir-modal.js +122 -59
  22. package/es/file/file-icon.d.ts +11 -0
  23. package/es/file/file-icon.d.ts.map +1 -0
  24. package/es/file/file-icon.js +475 -0
  25. package/es/file/file-name-alias.d.ts +7 -0
  26. package/es/file/file-name-alias.d.ts.map +1 -0
  27. package/es/file/file-protocol.d.ts +14 -0
  28. package/es/file/file-protocol.d.ts.map +1 -0
  29. package/es/file/file-rename-modal.d.ts +1 -0
  30. package/es/file/file-rename-modal.d.ts.map +1 -1
  31. package/es/file/file-rename-modal.js +100 -25
  32. package/es/file/file-tree-label-provider.d.ts +13 -0
  33. package/es/file/file-tree-label-provider.d.ts.map +1 -0
  34. package/es/file/index.d.ts +3 -0
  35. package/es/file/index.d.ts.map +1 -1
  36. package/es/file/index.js +4 -1
  37. package/es/file/index.less +98 -0
  38. package/es/file/navigatable-view.d.ts +7 -5
  39. package/es/file/navigatable-view.d.ts.map +1 -1
  40. package/es/file/navigatable-view.js +14 -3
  41. package/es/file/utils.d.ts +2 -0
  42. package/es/file/utils.d.ts.map +1 -0
  43. package/es/keybind-instructions/keybind-instructions-items.d.ts +14 -0
  44. package/es/keybind-instructions/keybind-instructions-items.d.ts.map +1 -0
  45. package/es/theme/color-registry.d.ts +6 -0
  46. package/es/theme/color-registry.d.ts.map +1 -0
  47. package/es/theme/index.d.ts +2 -0
  48. package/es/theme/index.d.ts.map +1 -0
  49. package/package.json +14 -14
  50. package/src/components/index.less +1 -0
  51. package/src/file/file-command.tsx +11 -6
  52. package/src/file/file-create-modal.tsx +129 -26
  53. package/src/file/file-createdir-modal.tsx +64 -32
  54. package/src/file/file-icon.tsx +502 -0
  55. package/src/file/file-rename-modal.tsx +55 -16
  56. package/src/file/index.less +98 -0
  57. package/src/file/index.ts +3 -0
  58. package/src/file/navigatable-view.tsx +23 -6
@@ -1,11 +1,12 @@
1
- import type { ModalItem, ModalItemProps, URI } from '@difizen/mana-app';
2
1
  import { useInject, ViewManager } from '@difizen/mana-app';
2
+ import type { ModalItem, ModalItemProps, URI } from '@difizen/mana-app';
3
+ import { Form, message, Input, Modal } from 'antd';
3
4
  import type { InputRef } from 'antd';
4
- import { Input, Modal } from 'antd';
5
5
  import { useEffect, useRef, useState } from 'react';
6
6
 
7
7
  import { JupyterFileService } from './file-service.js';
8
8
  import { FileView } from './file-view/index.js';
9
+ import './index.less';
9
10
 
10
11
  export interface ModalItemType {
11
12
  resource: URI;
@@ -19,8 +20,8 @@ export const FileRenameModalComponent: React.FC<ModalItemProps<ModalItemType>> =
19
20
  }: ModalItemProps<ModalItemType>) => {
20
21
  const fileService = useInject(JupyterFileService);
21
22
  const viewManager = useInject(ViewManager);
22
- const [newFileName, setNewFileName] = useState(data.fileName);
23
23
  const inputRef = useRef<InputRef>(null);
24
+ const [form] = Form.useForm();
24
25
  const [fileView, setFileView] = useState<FileView>();
25
26
  useEffect(() => {
26
27
  viewManager
@@ -34,26 +35,64 @@ export const FileRenameModalComponent: React.FC<ModalItemProps<ModalItemType>> =
34
35
  });
35
36
  inputRef.current?.focus();
36
37
  });
38
+
39
+ const onFinish = async (values: { rename: string }) => {
40
+ await form.validateFields();
41
+ close();
42
+ try {
43
+ await fileService.rename(data.resource, values.rename);
44
+
45
+ if (fileView) {
46
+ fileView.model.refresh();
47
+ }
48
+ } catch {
49
+ message.error('重命名文件/文件夹失败');
50
+ }
51
+ };
52
+
53
+ const validateRename = async (rule: any, value: string, callback: any) => {
54
+ if (!value || !value.length) {
55
+ throw new Error('请输入文件夹名');
56
+ } else {
57
+ if (value === data.fileName) {
58
+ throw new Error('文件/文件夹名称已存在,请重新输入');
59
+ }
60
+ }
61
+ };
62
+
37
63
  return (
38
64
  <Modal
39
65
  title="文件重命名"
40
66
  open={visible}
41
67
  onCancel={close}
42
- onOk={async () => {
43
- await fileService.rename(data.resource, newFileName);
44
- if (fileView) {
45
- fileView.model.refresh();
46
- }
47
- close();
68
+ onOk={() => {
69
+ form.submit();
48
70
  }}
71
+ wrapClassName="libro-rename-file-modal"
49
72
  >
50
- <Input
51
- value={newFileName}
52
- onChange={(e) => {
53
- setNewFileName(e.target.value);
54
- }}
55
- ref={inputRef}
56
- />
73
+ <Form
74
+ layout="vertical"
75
+ autoComplete="off"
76
+ form={form}
77
+ onFinish={onFinish}
78
+ className="libro-rename-file-form"
79
+ >
80
+ <Form.Item
81
+ name="rename"
82
+ label="文件/文件夹名称"
83
+ rules={[{ required: true, validator: validateRename }]}
84
+ initialValue={data.fileName}
85
+ >
86
+ <Input
87
+ ref={inputRef}
88
+ onKeyDown={async (e) => {
89
+ if (e.keyCode === 13) {
90
+ form.submit();
91
+ }
92
+ }}
93
+ />
94
+ </Form.Item>
95
+ </Form>
57
96
  </Modal>
58
97
  );
59
98
  };
@@ -0,0 +1,98 @@
1
+ .libro-create-file-type {
2
+ display: flex;
3
+ align-items: center;
4
+ justify-content: center;
5
+ flex-direction: column;
6
+ margin-bottom: 24px;
7
+ height: 100px;
8
+ width: 100px;
9
+ border: 1px solid rgba(0, 10, 26, 10%);
10
+ border-radius: 4px;
11
+ cursor: pointer;
12
+
13
+ &.active {
14
+ border: 1px solid #1677ff;
15
+ background-color: rgba(22, 122, 255, 9%);
16
+ }
17
+
18
+ &.active::before {
19
+ content: '';
20
+ position: absolute;
21
+ top: 2px;
22
+ right: 18px;
23
+ height: 0;
24
+ width: 0;
25
+ border-top: 12px solid #1677ff;
26
+ border-left: 12px solid transparent;
27
+ }
28
+ }
29
+
30
+ .libro-create-file-modal,
31
+ .libro-create-dir-modal,
32
+ .libro-rename-file-modal {
33
+ .ant-modal-content {
34
+ padding: unset;
35
+ }
36
+
37
+ .ant-modal-body {
38
+ padding: 20px 24px;
39
+ }
40
+
41
+ .ant-modal-header {
42
+ padding: 16px 24px;
43
+ border-bottom: 1px solid rgba(0, 10, 26, 7%);
44
+ margin: unset;
45
+ }
46
+
47
+ .ant-modal-footer {
48
+ margin: unset;
49
+ padding: 10px 24px;
50
+ border-top: 1px solid rgba(0, 10, 26, 7%);
51
+ }
52
+
53
+ .ant-modal-title {
54
+ font-weight: 500;
55
+ color: rgba(0, 10, 26, 89%);
56
+ }
57
+ }
58
+
59
+ .libro-remove-file-modal {
60
+ .ant-modal-confirm-title {
61
+ font-weight: 500;
62
+ color: rgba(0, 0, 0, 88%);
63
+ }
64
+ }
65
+
66
+ .libro-create-file-modal {
67
+ .ant-form-item-control-input {
68
+ width: 370px;
69
+ }
70
+ }
71
+
72
+ .libro-create-dir-modal,
73
+ .libro-rename-file-modal {
74
+ .ant-form-item-control-input {
75
+ width: 316px;
76
+ }
77
+ }
78
+
79
+ .libro-create-file-path-container {
80
+ margin-bottom: 8px;
81
+ }
82
+
83
+ .libro-create-file-des {
84
+ margin-bottom: 8px;
85
+ display: inline-block;
86
+ color: rgba(0, 0, 0, 85%);
87
+ letter-spacing: 0;
88
+ line-height: 22px;
89
+ }
90
+
91
+ .libro-create-file-path {
92
+ color: rgba(0, 0, 0, 65%);
93
+ }
94
+
95
+ .libro-create-file-type-text {
96
+ margin-top: 8px;
97
+ color: rgba(0, 10, 26, 68%);
98
+ }
package/src/file/index.ts CHANGED
@@ -4,3 +4,6 @@ export * from './navigatable-view.js';
4
4
  export * from './open-handler-contribution.js';
5
5
  export * from './file-service.js';
6
6
  export * from './file-protocol.js';
7
+ export * from './file-icon.js';
8
+ export * from './file-create-modal.js';
9
+ export * from './file-createdir-modal.js';
@@ -1,7 +1,6 @@
1
1
  import type { LibroView } from '@difizen/libro-core';
2
- import { LibroService } from '@difizen/libro-core';
3
- import type { NavigatableView } from '@difizen/mana-app';
4
- import { CommandRegistry } from '@difizen/mana-app';
2
+ import { LibroService, DocumentCommands } from '@difizen/libro-core';
3
+ import type { NavigatableView, Saveable } from '@difizen/mana-app';
5
4
  import {
6
5
  BaseView,
7
6
  inject,
@@ -17,11 +16,11 @@ import {
17
16
  ViewRender,
18
17
  Deferred,
19
18
  URI,
19
+ CommandRegistry,
20
+ Emitter,
20
21
  } from '@difizen/mana-app';
21
22
  import { createRef, forwardRef } from 'react';
22
23
 
23
- import type { EditorView } from './file-protocol.js';
24
-
25
24
  export const LibroEditorComponent = forwardRef(function LibroEditorComponent() {
26
25
  const instance = useInject<LibroNavigatableView>(ViewInstance);
27
26
 
@@ -37,7 +36,7 @@ export const LibroNavigatableViewFactoryId = 'libro-navigatable-view-factory';
37
36
  @view(LibroNavigatableViewFactoryId)
38
37
  export class LibroNavigatableView
39
38
  extends BaseView
40
- implements NavigatableView, EditorView
39
+ implements NavigatableView, Saveable
41
40
  {
42
41
  @inject(LibroService) protected libroService: LibroService;
43
42
 
@@ -49,6 +48,14 @@ export class LibroNavigatableView
49
48
 
50
49
  @prop() filePath?: string;
51
50
 
51
+ dirtyEmitter = new Emitter<void>();
52
+
53
+ get onDirtyChanged() {
54
+ return this.dirtyEmitter.event;
55
+ }
56
+
57
+ readonly autoSave = 'off';
58
+
52
59
  @prop()
53
60
  dirty: boolean;
54
61
 
@@ -80,6 +87,14 @@ export class LibroNavigatableView
80
87
  this.getOrCreateLibroView();
81
88
  }
82
89
 
90
+ save = () => {
91
+ this.commandRegistry.executeCommand(
92
+ DocumentCommands['Save'].id,
93
+ undefined,
94
+ this.libroView,
95
+ );
96
+ };
97
+
83
98
  protected async getOrCreateLibroView() {
84
99
  const libroView = await this.libroService.getOrCreateView({
85
100
  id: this.filePath,
@@ -91,9 +106,11 @@ export class LibroNavigatableView
91
106
  this.libroView = libroView;
92
107
  this.libroView.model.onContentChanged(() => {
93
108
  this.dirty = true;
109
+ this.dirtyEmitter.fire();
94
110
  });
95
111
  this.libroView.onSave(() => {
96
112
  this.dirty = false;
113
+ this.dirtyEmitter.fire();
97
114
  });
98
115
  await this.libroView.initialized;
99
116
  this.libroView.focus();