@difizen/libro-lab 0.3.0 → 0.3.2

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 (37) hide show
  1. package/es/command/lab-command.d.ts +4 -0
  2. package/es/command/lab-command.d.ts.map +1 -1
  3. package/es/command/lab-command.js +4 -0
  4. package/es/command/lab-menu-contribution.d.ts +3 -2
  5. package/es/command/lab-menu-contribution.d.ts.map +1 -1
  6. package/es/command/lab-menu-contribution.js +151 -110
  7. package/es/config/config.d.ts +2 -0
  8. package/es/config/config.d.ts.map +1 -1
  9. package/es/config/config.js +12 -1
  10. package/es/guide/content-contribution.d.ts +7 -0
  11. package/es/guide/content-contribution.d.ts.map +1 -0
  12. package/es/guide/content-contribution.js +74 -0
  13. package/es/guide/guide-view.d.ts +19 -0
  14. package/es/guide/guide-view.d.ts.map +1 -0
  15. package/es/guide/guide-view.js +141 -0
  16. package/es/guide/index.d.ts +3 -0
  17. package/es/guide/index.d.ts.map +1 -0
  18. package/es/guide/index.js +2 -0
  19. package/es/guide/index.less +8 -0
  20. package/es/guide/libro_guide_book.json +333 -0
  21. package/es/guide/libro_guide_book_zh.json +331 -0
  22. package/es/lab-app.d.ts.map +1 -1
  23. package/es/lab-app.js +51 -27
  24. package/es/module.d.ts.map +1 -1
  25. package/es/module.js +3 -1
  26. package/package.json +14 -14
  27. package/src/command/lab-command.ts +4 -0
  28. package/src/command/lab-menu-contribution.tsx +15 -2
  29. package/src/config/config.ts +12 -0
  30. package/src/guide/content-contribution.ts +50 -0
  31. package/src/guide/guide-view.tsx +77 -0
  32. package/src/guide/index.less +8 -0
  33. package/src/guide/index.ts +2 -0
  34. package/src/guide/libro_guide_book.json +333 -0
  35. package/src/guide/libro_guide_book_zh.json +331 -0
  36. package/src/lab-app.ts +10 -2
  37. package/src/module.tsx +4 -0
package/es/lab-app.js CHANGED
@@ -14,7 +14,8 @@ function _initializerWarningHelper(descriptor, context) { throw new Error('Decor
14
14
  import { LibroService, LibroJupyterConfiguration, ServerConnection, ServerManager } from '@difizen/libro-jupyter';
15
15
  import { terminalDefaultSlot } from '@difizen/libro-terminal';
16
16
  import { ConfigurationService, FileTreeViewFactory, URI, ApplicationContribution, SlotViewManager, ViewManager, inject, singleton } from '@difizen/mana-app';
17
- import { LibroLabConfiguration } from "./config/index.js";
17
+ import { LibroLabConfiguration, LibroLabGuideViewEnabled } from "./config/index.js";
18
+ import { GuideView } from "./guide/index.js";
18
19
  import { KernelAndTerminalPanelView } from "./kernel-and-terminal-panel/index.js";
19
20
  import { LibroLabLayoutSlots } from "./layout/index.js";
20
21
  import { LayoutService } from "./layout/layout-service.js";
@@ -45,11 +46,11 @@ export var LibroLabApp = (_dec = singleton({
45
46
  _createClass(LibroLabApp, [{
46
47
  key: "onStart",
47
48
  value: function () {
48
- var _onStart = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
49
+ var _onStart = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
49
50
  var _this = this;
50
51
  var _i, _leftPanelConfigs, _leftPanelConfigs$_i, configKey, viewClass, isEnabled, view;
51
- return _regeneratorRuntime().wrap(function _callee$(_context) {
52
- while (1) switch (_context.prev = _context.next) {
52
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
53
+ while (1) switch (_context2.prev = _context2.next) {
53
54
  case 0:
54
55
  localStorage.setItem(ShouldPreventStoreViewKey, 'true');
55
56
  this.configurationService.set(LibroJupyterConfiguration['OpenSlot'], LibroLabLayoutSlots.content);
@@ -57,40 +58,63 @@ export var LibroLabApp = (_dec = singleton({
57
58
  _i = 0, _leftPanelConfigs = leftPanelConfigs;
58
59
  case 4:
59
60
  if (!(_i < _leftPanelConfigs.length)) {
60
- _context.next = 17;
61
+ _context2.next = 17;
61
62
  break;
62
63
  }
63
64
  _leftPanelConfigs$_i = _leftPanelConfigs[_i], configKey = _leftPanelConfigs$_i.configKey, viewClass = _leftPanelConfigs$_i.viewClass;
64
- _context.next = 8;
65
+ _context2.next = 8;
65
66
  return this.configurationService.get(LibroLabConfiguration[configKey]);
66
67
  case 8:
67
- isEnabled = _context.sent;
68
+ isEnabled = _context2.sent;
68
69
  if (!isEnabled) {
69
- _context.next = 14;
70
+ _context2.next = 14;
70
71
  break;
71
72
  }
72
- _context.next = 12;
73
+ _context2.next = 12;
73
74
  return this.viewManager.getOrCreateView(viewClass);
74
75
  case 12:
75
- view = _context.sent;
76
+ view = _context2.sent;
76
77
  this.slotViewManager.addView(view, LibroLabLayoutSlots.navigator);
77
78
  case 14:
78
79
  _i++;
79
- _context.next = 4;
80
+ _context2.next = 4;
80
81
  break;
81
82
  case 17:
82
- this.serverManager.ready.then(function () {
83
- _this.layoutService.setAreaVisible(LibroLabLayoutSlots.navigator, true);
84
- _this.layoutService.setAreaVisible(LibroLabLayoutSlots.alert, false);
85
- _this.layoutService.serverSatus = 'success';
86
- _this.initialWorkspace();
87
- return;
88
- }).catch(console.error);
83
+ this.serverManager.ready.then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
84
+ var isGuideEnabled, _view;
85
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
86
+ while (1) switch (_context.prev = _context.next) {
87
+ case 0:
88
+ _this.layoutService.setAreaVisible(LibroLabLayoutSlots.navigator, true);
89
+ _this.layoutService.setAreaVisible(LibroLabLayoutSlots.alert, false);
90
+ _this.layoutService.serverSatus = 'success';
91
+ _this.initialWorkspace();
92
+ _context.next = 6;
93
+ return _this.configurationService.get(LibroLabGuideViewEnabled);
94
+ case 6:
95
+ isGuideEnabled = _context.sent;
96
+ if (!isGuideEnabled) {
97
+ _context.next = 12;
98
+ break;
99
+ }
100
+ _context.next = 10;
101
+ return _this.viewManager.getOrCreateView(GuideView);
102
+ case 10:
103
+ _view = _context.sent;
104
+ _this.slotViewManager.addView(_view, LibroLabLayoutSlots.content);
105
+ case 12:
106
+ return _context.abrupt("return");
107
+ case 13:
108
+ case "end":
109
+ return _context.stop();
110
+ }
111
+ }, _callee);
112
+ }))).catch(console.error);
89
113
  case 18:
90
114
  case "end":
91
- return _context.stop();
115
+ return _context2.stop();
92
116
  }
93
- }, _callee, this);
117
+ }, _callee2, this);
94
118
  }));
95
119
  function onStart() {
96
120
  return _onStart.apply(this, arguments);
@@ -100,24 +124,24 @@ export var LibroLabApp = (_dec = singleton({
100
124
  }, {
101
125
  key: "initialWorkspace",
102
126
  value: function () {
103
- var _initialWorkspace = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
127
+ var _initialWorkspace = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
104
128
  var view;
105
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
106
- while (1) switch (_context2.prev = _context2.next) {
129
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
130
+ while (1) switch (_context3.prev = _context3.next) {
107
131
  case 0:
108
- _context2.next = 2;
132
+ _context3.next = 2;
109
133
  return this.viewManager.getOrCreateView(FileTreeViewFactory);
110
134
  case 2:
111
- view = _context2.sent;
135
+ view = _context3.sent;
112
136
  if (view) {
113
137
  view.model.rootVisible = false;
114
138
  view.model.location = new URI('/');
115
139
  }
116
140
  case 4:
117
141
  case "end":
118
- return _context2.stop();
142
+ return _context3.stop();
119
143
  }
120
- }, _callee2, this);
144
+ }, _callee3, this);
121
145
  }));
122
146
  function initialWorkspace() {
123
147
  return _initialWorkspace.apply(this, arguments);
@@ -1 +1 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.tsx"],"names":[],"mappings":"AAQA,OAAO,EACL,UAAU,EAKX,MAAM,mBAAmB,CAAC;AAoB3B,OAAO,cAAc,CAAC;AAMtB,eAAO,MAAM,cAAc,YA+FxB,CAAC"}
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.tsx"],"names":[],"mappings":"AAQA,OAAO,EACL,UAAU,EAKX,MAAM,mBAAmB,CAAC;AAsB3B,OAAO,cAAc,CAAC;AAMtB,eAAO,MAAM,cAAc,YAiGxB,CAAC"}
package/es/module.js CHANGED
@@ -12,6 +12,8 @@ import { LibroLabHeaderMenuModule } from "./command/module.js";
12
12
  import { LabConfigAppContribution } from "./config/config-contribution.js";
13
13
  import { CodeEditorViewerModule } from "./editor-viewer/index.js";
14
14
  import { GithubLinkView } from "./github-link/index.js";
15
+ import { LibroGuidebookContentContribution } from "./guide/content-contribution.js";
16
+ import { GuideView } from "./guide/guide-view.js";
15
17
  import { ImageViewerModule } from "./image-viewer/index.js";
16
18
  // import { KernelManagerView } from './kernel-manager/index.js';
17
19
  import { LibroKernelAndTerminalPanelModule } from "./kernel-and-terminal-panel/module.js";
@@ -86,4 +88,4 @@ createSlotPreference({
86
88
  reveal: true,
87
89
  order: 'welcome'
88
90
  }
89
- }), EntryPointView).dependOn(LibroJupyterModule, CommonWidgetsModule, LibroLabLayoutModule, LibroLabHeaderMenuModule, LibroLabTocModule, LibroKernelAndTerminalPanelModule, LibroPromptCellModule, LibroSqlCellModule, TerminalModule, ImageViewerModule, CodeEditorViewerModule, LibroAINativeModule, LibroAppModule);
91
+ }), LibroGuidebookContentContribution, GuideView, EntryPointView).dependOn(LibroJupyterModule, CommonWidgetsModule, LibroLabLayoutModule, LibroLabHeaderMenuModule, LibroLabTocModule, LibroKernelAndTerminalPanelModule, LibroPromptCellModule, LibroSqlCellModule, TerminalModule, ImageViewerModule, CodeEditorViewerModule, LibroAINativeModule, LibroAppModule);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-lab",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "libro",
@@ -34,19 +34,19 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "@ant-design/icons": "^5.1.0",
37
- "@difizen/libro-core": "^0.3.0",
38
- "@difizen/libro-jupyter": "^0.3.0",
39
- "@difizen/libro-kernel": "^0.3.0",
40
- "@difizen/libro-prompt-cell": "^0.3.0",
41
- "@difizen/libro-sql-cell": "^0.3.0",
42
- "@difizen/libro-terminal": "^0.3.0",
43
- "@difizen/libro-toc": "^0.3.0",
44
- "@difizen/libro-app": "^0.3.0",
45
- "@difizen/libro-cofine-editor-core": "^0.3.0",
46
- "@difizen/libro-language-client": "^0.3.0",
47
- "@difizen/libro-widget": "^0.3.0",
48
- "@difizen/libro-l10n": "^0.3.0",
49
- "@difizen/libro-ai-native": "^0.3.0",
37
+ "@difizen/libro-core": "^0.3.2",
38
+ "@difizen/libro-jupyter": "^0.3.2",
39
+ "@difizen/libro-kernel": "^0.3.2",
40
+ "@difizen/libro-prompt-cell": "^0.3.2",
41
+ "@difizen/libro-sql-cell": "^0.3.2",
42
+ "@difizen/libro-terminal": "^0.3.2",
43
+ "@difizen/libro-toc": "^0.3.2",
44
+ "@difizen/libro-app": "^0.3.2",
45
+ "@difizen/libro-cofine-editor-core": "^0.3.2",
46
+ "@difizen/libro-language-client": "^0.3.2",
47
+ "@difizen/libro-widget": "^0.3.2",
48
+ "@difizen/libro-l10n": "^0.3.2",
49
+ "@difizen/libro-ai-native": "^0.3.2",
50
50
  "@difizen/mana-app": "latest",
51
51
  "@difizen/mana-l10n": "latest",
52
52
  "@difizen/mana-common": "latest",
@@ -3,6 +3,10 @@ export const LabCommands = {
3
3
  id: 'libro-lab-header-menu-help-about',
4
4
  label: '关于',
5
5
  },
6
+ Guide: {
7
+ id: 'libro-lab-header-menu-help-guide',
8
+ label: '使用指南',
9
+ },
6
10
  Save: {
7
11
  id: 'libro-lab-save',
8
12
  label: '保存',
@@ -5,8 +5,8 @@ import {
5
5
  NotebookCommands,
6
6
  } from '@difizen/libro-jupyter';
7
7
  import { TerminalCommands, TerminalManager } from '@difizen/libro-terminal';
8
- import type { MenuRegistry } from '@difizen/mana-app';
9
- import type { KeybindingRegistry } from '@difizen/mana-app';
8
+ import type { KeybindingRegistry, MenuRegistry } from '@difizen/mana-app';
9
+ import { SlotViewManager } from '@difizen/mana-app';
10
10
  import { KeybindingContribution } from '@difizen/mana-app';
11
11
  import { Saveable } from '@difizen/mana-app';
12
12
  import {
@@ -20,6 +20,7 @@ import {
20
20
  } from '@difizen/mana-app';
21
21
  import { l10n } from '@difizen/mana-l10n';
22
22
 
23
+ import { GuideView } from '../guide/index.js';
23
24
  import { LibroLabLayoutSlots } from '../layout/index.js';
24
25
  import { LayoutService } from '../layout/layout-service.js';
25
26
 
@@ -43,6 +44,7 @@ export class LabMenu
43
44
  @inject(LayoutService) protected layoutService: LayoutService;
44
45
  @inject(TerminalManager) terminalManager: TerminalManager;
45
46
  @inject(ViewManager) viewManager: ViewManager;
47
+ @inject(SlotViewManager) slotManager: SlotViewManager;
46
48
 
47
49
  registerKeybindings(keybindings: KeybindingRegistry) {
48
50
  keybindings.registerKeybinding({
@@ -75,6 +77,11 @@ export class LabMenu
75
77
  command: LabCommands.About.id,
76
78
  label: () => <div>{l10n.t(LabCommands.About.label)}</div>,
77
79
  });
80
+ menu.registerMenuAction(LabMenus.HELP, {
81
+ id: LabCommands.Guide.id,
82
+ command: LabCommands.Guide.id,
83
+ label: () => <div>{l10n.t(LabCommands.Guide.label)}</div>,
84
+ });
78
85
  menu.registerMenuAction(LabMenus.FILE, {
79
86
  id: LabCommands.Save.id,
80
87
  command: LabCommands.Save.id,
@@ -261,6 +268,12 @@ export class LabMenu
261
268
  //TODO: 关于
262
269
  },
263
270
  });
271
+ commands.registerCommand(LabCommands.Guide, {
272
+ execute: async () => {
273
+ const view = await this.viewManager.getOrCreateView(GuideView);
274
+ this.slotManager.addView(view, LibroLabLayoutSlots.content);
275
+ },
276
+ });
264
277
  commands.registerCommand(LabCommands.Save);
265
278
  commands.registerHandler(LabCommands.Save.id, {
266
279
  execute: async () => {
@@ -23,7 +23,19 @@ export const LibroLabTocPanelEnabled: ConfigurationNode<boolean> = {
23
23
  },
24
24
  };
25
25
 
26
+ export const LibroLabGuideViewEnabled: ConfigurationNode<boolean> = {
27
+ id: 'libro.lab.guide.view.enabled',
28
+ description: 'whether enable guide view ',
29
+ title: l10n.t('是否激活使用指南'),
30
+ type: 'checkbox',
31
+ defaultValue: false,
32
+ schema: {
33
+ type: 'boolean',
34
+ },
35
+ };
36
+
26
37
  export const LibroLabConfiguration = {
27
38
  LibroLabKernelAndTerminalPanelEnabled: LibroLabKernelAndTerminalPanelEnabled,
28
39
  LibroLabTocPanelEnabled: LibroLabTocPanelEnabled,
40
+ LibroLabGuideViewEnabled: LibroLabGuideViewEnabled,
29
41
  };
@@ -0,0 +1,50 @@
1
+ import type { NotebookModel, NotebookOption } from '@difizen/libro-core';
2
+ import { ContentContribution } from '@difizen/libro-core';
3
+ import type {
4
+ IContentsModel,
5
+ INotebookContent,
6
+ LibroJupyterModel,
7
+ } from '@difizen/libro-jupyter';
8
+ import { URI } from '@difizen/mana-app';
9
+ import { singleton } from '@difizen/mana-app';
10
+ import { l10n, L10nLang } from '@difizen/mana-l10n';
11
+
12
+ import contentJson from './libro_guide_book.json';
13
+ import contentZhJson from './libro_guide_book_zh.json';
14
+
15
+ @singleton({ contrib: ContentContribution })
16
+ export class LibroGuidebookContentContribution implements ContentContribution {
17
+ canHandle = (options: NotebookOption) => {
18
+ if (options['loadType'] === 'libro-guide-book') {
19
+ return 50;
20
+ }
21
+ return 1;
22
+ };
23
+ async loadContent(options: NotebookOption, model: NotebookModel) {
24
+ const jupyterModel = model as LibroJupyterModel;
25
+ const fireUri = new URI(options['resource']);
26
+ const filePath = fireUri.path.toString();
27
+ let notebookContent: INotebookContent = {
28
+ cells: [],
29
+ metadata: {},
30
+ nbformat: 4,
31
+ nbformat_minor: 5,
32
+ };
33
+ notebookContent = l10n.getLang() === L10nLang.zhCN ? contentZhJson : contentJson;
34
+ const currentFileContents: IContentsModel = {
35
+ name: 'Guide book',
36
+ path: filePath,
37
+ type: 'notebook',
38
+ writable: true,
39
+ created: 'libro',
40
+ last_modified: 'libro',
41
+ content: notebookContent,
42
+ };
43
+ currentFileContents.content.nbformat_minor = 5;
44
+ jupyterModel.currentFileContents = currentFileContents;
45
+ jupyterModel.filePath = currentFileContents.path;
46
+ jupyterModel.lastModified = jupyterModel.currentFileContents.last_modified;
47
+
48
+ return jupyterModel.currentFileContents.content;
49
+ }
50
+ }
@@ -0,0 +1,77 @@
1
+ import type { LibroView } from '@difizen/libro-jupyter';
2
+ import { LibroService } from '@difizen/libro-jupyter';
3
+ import {
4
+ Deferred,
5
+ inject,
6
+ prop,
7
+ singleton,
8
+ useInject,
9
+ view,
10
+ ViewInstance,
11
+ ViewRender,
12
+ } from '@difizen/mana-app';
13
+ import { BaseView } from '@difizen/mana-app';
14
+ import { l10n, L10nLang } from '@difizen/mana-l10n';
15
+ import { forwardRef } from 'react';
16
+ import './index.less';
17
+
18
+ import { Logo } from '../common/icon.js';
19
+
20
+ export const GuideComponent = forwardRef(function WelcomeComponent() {
21
+ const instance = useInject<GuideView>(ViewInstance);
22
+
23
+ if (!instance.libroView) {
24
+ return null;
25
+ }
26
+ return <ViewRender view={instance.libroView} key={instance.filePath} />;
27
+ });
28
+
29
+ @singleton()
30
+ @view('guide-view')
31
+ export class GuideView extends BaseView {
32
+ override view = GuideComponent;
33
+
34
+ @prop()
35
+ libroView?: LibroView;
36
+
37
+ @prop() filePath?: string;
38
+
39
+ @inject(LibroService) protected libroService: LibroService;
40
+
41
+ protected defer = new Deferred<void>();
42
+
43
+ get ready() {
44
+ return this.defer.promise;
45
+ }
46
+
47
+ constructor() {
48
+ super();
49
+ this.title.icon = <Logo></Logo>;
50
+ this.title.label = () => <div>{l10n.t('使用指南')}</div>;
51
+ this.title.closable = true;
52
+ this.filePath =
53
+ l10n.getLang() === L10nLang.zhCN
54
+ ? 'libro_guide_book_zh.json'
55
+ : 'libro_guide_book.json';
56
+ }
57
+
58
+ override async onViewMount(): Promise<void> {
59
+ this.getOrCreateLibroView();
60
+ }
61
+
62
+ protected async getOrCreateLibroView() {
63
+ const libroView = await this.libroService.getOrCreateView({
64
+ id: this.filePath,
65
+ resource: this.filePath,
66
+ loadType: 'libro-guide-book',
67
+ });
68
+ if (!libroView) {
69
+ return;
70
+ }
71
+ this.libroView = libroView;
72
+ await this.libroView.initialized;
73
+ this.libroView.model.savable = false;
74
+ this.libroView.focus();
75
+ this.defer.resolve();
76
+ }
77
+ }
@@ -0,0 +1,8 @@
1
+ .libro-lab-content-layout-main {
2
+ .mana-tab-icon {
3
+ svg {
4
+ display: inline-block;
5
+ width: 14px;
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,2 @@
1
+ export * from './content-contribution.js';
2
+ export * from './guide-view.js';