@difizen/libro-jupyter 0.2.0 → 0.2.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 (146) hide show
  1. package/es/add-between-cell/add-between-cell.js +1 -1
  2. package/es/cell/jupyter-code-cell-view.d.ts +3 -1
  3. package/es/cell/jupyter-code-cell-view.d.ts.map +1 -1
  4. package/es/cell/jupyter-code-cell-view.js +12 -5
  5. package/es/command/command-contribution.d.ts.map +1 -1
  6. package/es/command/command-contribution.js +5 -5
  7. package/es/components/icons.js +1 -1
  8. package/es/contents/content-contribution.js +1 -1
  9. package/es/contents/save-content-contribution.d.ts +10 -0
  10. package/es/contents/save-content-contribution.d.ts.map +1 -0
  11. package/es/contents/save-content-contribution.js +110 -0
  12. package/es/file/file-create-modal.d.ts.map +1 -1
  13. package/es/file/file-create-modal.js +16 -5
  14. package/es/file/file-service.js +1 -1
  15. package/es/file/index.d.ts +1 -0
  16. package/es/file/index.d.ts.map +1 -1
  17. package/es/file/index.js +2 -1
  18. package/es/index.d.ts +1 -0
  19. package/es/index.d.ts.map +1 -1
  20. package/es/index.js +2 -1
  21. package/es/keybind-instructions/index.less +9 -9
  22. package/es/keybind-instructions/keybind-instructions-view.d.ts +2 -2
  23. package/es/keybind-instructions/keybind-instructions-view.d.ts.map +1 -1
  24. package/es/keybind-instructions/keybind-instructions-view.js +69 -63
  25. package/es/libro-jupyter-model.d.ts +2 -4
  26. package/es/libro-jupyter-model.d.ts.map +1 -1
  27. package/es/libro-jupyter-model.js +35 -120
  28. package/es/libro-jupyter-workspace.d.ts +18 -0
  29. package/es/libro-jupyter-workspace.d.ts.map +1 -0
  30. package/es/libro-jupyter-workspace.js +108 -0
  31. package/es/module.d.ts.map +1 -1
  32. package/es/module.js +5 -2
  33. package/es/output/libro-jupyter-outputarea.d.ts.map +1 -1
  34. package/es/output/libro-jupyter-outputarea.js +60 -56
  35. package/es/toolbar/save-file-error.d.ts.map +1 -1
  36. package/es/toolbar/save-file-error.js +20 -13
  37. package/es/widget/box/contribution.d.ts +10 -0
  38. package/es/widget/box/contribution.d.ts.map +1 -0
  39. package/es/widget/box/contribution.js +48 -0
  40. package/es/widget/box/index.d.ts +3 -0
  41. package/es/widget/box/index.d.ts.map +1 -0
  42. package/es/widget/box/index.js +2 -0
  43. package/es/widget/box/index.less +3 -0
  44. package/es/widget/box/view.d.ts +19 -0
  45. package/es/widget/box/view.d.ts.map +1 -0
  46. package/es/widget/box/view.js +114 -0
  47. package/es/widget/comm.d.ts +65 -0
  48. package/es/widget/comm.d.ts.map +1 -0
  49. package/es/widget/comm.js +153 -0
  50. package/es/widget/index.d.ts +10 -0
  51. package/es/widget/index.d.ts.map +1 -0
  52. package/es/widget/index.js +9 -0
  53. package/es/widget/index.less +7 -0
  54. package/es/widget/instance-progress/contribution.d.ts +10 -0
  55. package/es/widget/instance-progress/contribution.d.ts.map +1 -0
  56. package/es/widget/instance-progress/contribution.js +39 -0
  57. package/es/widget/instance-progress/index.d.ts +3 -0
  58. package/es/widget/instance-progress/index.d.ts.map +1 -0
  59. package/es/widget/instance-progress/index.js +2 -0
  60. package/es/widget/instance-progress/view.d.ts +30 -0
  61. package/es/widget/instance-progress/view.d.ts.map +1 -0
  62. package/es/widget/instance-progress/view.js +180 -0
  63. package/es/widget/libro-widgets.d.ts +84 -0
  64. package/es/widget/libro-widgets.d.ts.map +1 -0
  65. package/es/widget/libro-widgets.js +307 -0
  66. package/es/widget/module.d.ts +4 -0
  67. package/es/widget/module.d.ts.map +1 -0
  68. package/es/widget/module.js +38 -0
  69. package/es/widget/progress/contribution.d.ts +10 -0
  70. package/es/widget/progress/contribution.d.ts.map +1 -0
  71. package/es/widget/progress/contribution.js +39 -0
  72. package/es/widget/progress/index.d.ts +3 -0
  73. package/es/widget/progress/index.d.ts.map +1 -0
  74. package/es/widget/progress/index.js +2 -0
  75. package/es/widget/progress/progressBar.d.ts +15 -0
  76. package/es/widget/progress/progressBar.d.ts.map +1 -0
  77. package/es/widget/progress/progressBar.js +20 -0
  78. package/es/widget/progress/view.d.ts +19 -0
  79. package/es/widget/progress/view.d.ts.map +1 -0
  80. package/es/widget/progress/view.js +74 -0
  81. package/es/widget/protocol.d.ts +193 -0
  82. package/es/widget/protocol.d.ts.map +1 -0
  83. package/es/widget/protocol.js +33 -0
  84. package/es/widget/utils.d.ts +27 -0
  85. package/es/widget/utils.d.ts.map +1 -0
  86. package/es/widget/utils.js +59 -0
  87. package/es/widget/version.d.ts +3 -0
  88. package/es/widget/version.d.ts.map +1 -0
  89. package/es/widget/version.js +2 -0
  90. package/es/widget/widget-manager.d.ts +19 -0
  91. package/es/widget/widget-manager.d.ts.map +1 -0
  92. package/es/widget/widget-manager.js +77 -0
  93. package/es/widget/widget-render.d.ts +7 -0
  94. package/es/widget/widget-render.d.ts.map +1 -0
  95. package/es/widget/widget-render.js +46 -0
  96. package/es/widget/widget-rendermime-contribution.d.ts +16 -0
  97. package/es/widget/widget-rendermime-contribution.d.ts.map +1 -0
  98. package/es/widget/widget-rendermime-contribution.js +50 -0
  99. package/es/widget/widget-view-contribution.d.ts +10 -0
  100. package/es/widget/widget-view-contribution.d.ts.map +1 -0
  101. package/es/widget/widget-view-contribution.js +36 -0
  102. package/es/widget/widget-view.d.ts +71 -0
  103. package/es/widget/widget-view.d.ts.map +1 -0
  104. package/es/widget/widget-view.js +273 -0
  105. package/package.json +18 -18
  106. package/src/add-between-cell/add-between-cell.tsx +1 -1
  107. package/src/cell/jupyter-code-cell-view.tsx +14 -6
  108. package/src/command/command-contribution.ts +11 -10
  109. package/src/components/icons.tsx +1 -1
  110. package/src/contents/content-contribution.ts +1 -1
  111. package/src/contents/save-content-contribution.ts +67 -0
  112. package/src/file/file-create-modal.tsx +10 -1
  113. package/src/file/file-service.ts +1 -1
  114. package/src/file/index.ts +1 -0
  115. package/src/index.ts +1 -0
  116. package/src/keybind-instructions/index.less +9 -9
  117. package/src/keybind-instructions/keybind-instructions-view.tsx +72 -62
  118. package/src/libro-jupyter-model.ts +1 -69
  119. package/src/libro-jupyter-workspace.ts +49 -0
  120. package/src/module.ts +6 -0
  121. package/src/output/libro-jupyter-outputarea.tsx +56 -49
  122. package/src/toolbar/save-file-error.tsx +25 -15
  123. package/src/widget/box/contribution.ts +29 -0
  124. package/src/widget/box/index.less +3 -0
  125. package/src/widget/box/index.ts +2 -0
  126. package/src/widget/box/view.tsx +112 -0
  127. package/src/widget/comm.ts +152 -0
  128. package/src/widget/index.less +7 -0
  129. package/src/widget/index.ts +9 -0
  130. package/src/widget/instance-progress/contribution.ts +20 -0
  131. package/src/widget/instance-progress/index.ts +2 -0
  132. package/src/widget/instance-progress/view.tsx +155 -0
  133. package/src/widget/libro-widgets.ts +223 -0
  134. package/src/widget/module.ts +73 -0
  135. package/src/widget/progress/contribution.ts +24 -0
  136. package/src/widget/progress/index.ts +2 -0
  137. package/src/widget/progress/progressBar.tsx +29 -0
  138. package/src/widget/progress/view.tsx +70 -0
  139. package/src/widget/protocol.ts +255 -0
  140. package/src/widget/utils.ts +67 -0
  141. package/src/widget/version.ts +2 -0
  142. package/src/widget/widget-manager.ts +45 -0
  143. package/src/widget/widget-render.tsx +52 -0
  144. package/src/widget/widget-rendermime-contribution.ts +36 -0
  145. package/src/widget/widget-view-contribution.ts +14 -0
  146. package/src/widget/widget-view.tsx +259 -0
@@ -0,0 +1,71 @@
1
+ /// <reference types="react" resolution-mode="require"/>
2
+ import type { JSONObject, JSONValue } from '@difizen/libro-common';
3
+ import type { CellView, LibroExecutableCellView } from '@difizen/libro-core';
4
+ import { LibroContextKey } from '@difizen/libro-core';
5
+ import type { KernelMessage } from '@difizen/libro-kernel';
6
+ import { BaseView } from '@difizen/mana-app';
7
+ import type { ViewComponent, Disposable } from '@difizen/mana-app';
8
+ import type { Dict, IWidgets, IWidgetView, IClassicComm, ICallbacks, IWidgetViewProps, WidgetState } from './protocol.js';
9
+ import { LibroWidgetManager } from './widget-manager.js';
10
+ export declare const LibroWidgetComponent: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
11
+ export declare class WidgetView extends BaseView implements IWidgetView {
12
+ view: ViewComponent;
13
+ libroContextKey: LibroContextKey;
14
+ widgetsId: string;
15
+ protected _msgHook: (msg: KernelMessage.IIOPubMessage) => boolean;
16
+ libroWidgetManager: LibroWidgetManager;
17
+ state: JSONObject & WidgetState;
18
+ cell?: LibroExecutableCellView;
19
+ get outputs(): import("@difizen/libro-core").BaseOutputArea | undefined;
20
+ disableCommandMode: boolean;
21
+ toDisposeOnMsgChanged?: Disposable;
22
+ constructor(props: IWidgetViewProps, libroContextKey: LibroContextKey);
23
+ setCell(cell: CellView): void;
24
+ /**
25
+ * Register a new kernel
26
+ */
27
+ handleKernelChanged: () => void;
28
+ /**
29
+ * Reset the message id.
30
+ */
31
+ resetMsgId(): void;
32
+ addFromMessage(msg: KernelMessage.IIOPubMessage): void;
33
+ clearOutput(wait?: boolean): void;
34
+ onViewMount(): void;
35
+ /**
36
+ * Handle incoming comm msg.
37
+ */
38
+ handleCommMsg(msg: KernelMessage.ICommMsgMsg): Promise<void>;
39
+ handleCommClosed: () => void;
40
+ /**
41
+ * Handle when a widget is updated from the backend.
42
+ *
43
+ * This function is meant for internal use only. Values set here will not be propagated on a sync.
44
+ */
45
+ setState(state: Dict<any>): void;
46
+ /**
47
+ * Serialize the model. See the deserialization function at the top of this file
48
+ * and the kernel-side serializer/deserializer.
49
+ */
50
+ toJSON(): string;
51
+ toModelKey(): string;
52
+ /**
53
+ * Send a custom msg over the comm.
54
+ */
55
+ send: (data: JSONValue, callbacks?: ICallbacks, buffers?: ArrayBuffer[] | ArrayBufferView[]) => string | undefined;
56
+ comm: IClassicComm;
57
+ widgets?: IWidgets;
58
+ model_id: string;
59
+ state_change: Promise<any>;
60
+ name: string;
61
+ module: string;
62
+ isCommClosed: boolean;
63
+ model_module: string;
64
+ model_name: string;
65
+ model_module_version: string;
66
+ view_module: string;
67
+ view_name: string | null;
68
+ view_module_version: string;
69
+ view_count: number | null;
70
+ }
71
+ //# sourceMappingURL=widget-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget-view.d.ts","sourceRoot":"","sources":["../../src/widget/widget-view.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAuB,MAAM,uBAAuB,CAAC;AACxF,OAAO,KAAK,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAKL,QAAQ,EAGT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAMnE,OAAO,KAAK,EACV,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,WAAW,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,eAAO,MAAM,oBAAoB,0FAIhC,CAAC;AAEF,qBAEa,UAAW,SAAQ,QAAS,YAAW,WAAW;IACpD,IAAI,EAAE,aAAa,CAAwB;IACpD,eAAe,EAAE,eAAe,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,aAAa,CAAC,aAAa,KAAK,OAAO,CAAC;IAEtC,kBAAkB,EAAE,kBAAkB,CAAC;IAGnE,KAAK,EAAE,UAAU,GAAG,WAAW,CAAsB;IAErD,IAAI,CAAC,EAAE,uBAAuB,CAAC;IAE/B,IAAI,OAAO,6DAKV;IAED,kBAAkB,UAAQ;IAE1B,qBAAqB,CAAC,EAAE,UAAU,CAAC;gBAGb,KAAK,EAAE,gBAAgB,EAClB,eAAe,EAAE,eAAe;IAqC3D,OAAO,CAAC,IAAI,EAAE,QAAQ;IAiBtB;;OAEG;IACH,mBAAmB,QAAO,IAAI,CAE5B;IAEF;;OAEG;IACH,UAAU,IAAI,IAAI;IAelB,cAAc,CAAC,GAAG,EAAE,aAAa,CAAC,aAAa;IAoB/C,WAAW,CAAC,IAAI,UAAQ,GAAG,IAAI;IAItB,WAAW;IAiBpB;;OAEG;IACH,aAAa,CAAC,GAAG,EAAE,aAAa,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5D,gBAAgB,aAEd;IACF;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI;IAUhC;;;OAGG;IACH,MAAM,IAAI,MAAM;IAIhB,UAAU,IAAI,MAAM;IAIpB;;OAEG;IACH,IAAI,SACI,SAAS,cACH,UAAU,YACZ,WAAW,EAAE,GAAG,eAAe,EAAE,wBAM3C;IAEF,IAAI,EAAE,YAAY,CAAC;IACX,OAAO,CAAC,EAAE,QAAQ,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,UAAS;IAErB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B"}
@@ -0,0 +1,273 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3;
3
+ function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
10
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
12
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
13
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
14
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
15
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
16
+ function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
17
+ function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
18
+ import { ExecutableCellView } from '@difizen/libro-core';
19
+ import { LibroContextKey } from '@difizen/libro-core';
20
+ import { inject, transient, ViewOption, view, BaseView, prop, watch } from '@difizen/mana-app';
21
+ import { forwardRef } from 'react';
22
+ import { LibroJupyterModel } from "../libro-jupyter-model.js";
23
+ import { defaultWidgetState } from "./protocol.js";
24
+ import { LibroWidgetManager } from "./widget-manager.js";
25
+ import { Fragment as _Fragment } from "react/jsx-runtime";
26
+ import { jsx as _jsx } from "react/jsx-runtime";
27
+ export var LibroWidgetComponent = /*#__PURE__*/forwardRef(function LibroWidgetComponent() {
28
+ return /*#__PURE__*/_jsx(_Fragment, {});
29
+ });
30
+ export var WidgetView = (_dec = transient(), _dec2 = view('libro-widget-view'), _dec3 = inject(LibroWidgetManager), _dec4 = prop(), _dec5 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_BaseView) {
31
+ _inherits(WidgetView, _BaseView);
32
+ var _super = _createSuper(WidgetView);
33
+ function WidgetView(props, libroContextKey) {
34
+ var _this;
35
+ _classCallCheck(this, WidgetView);
36
+ _this = _super.call(this);
37
+ _this.view = LibroWidgetComponent;
38
+ _this.libroContextKey = void 0;
39
+ _this.widgetsId = void 0;
40
+ _this._msgHook = void 0;
41
+ _initializerDefineProperty(_this, "libroWidgetManager", _descriptor, _assertThisInitialized(_this));
42
+ _initializerDefineProperty(_this, "state", _descriptor2, _assertThisInitialized(_this));
43
+ _this.cell = void 0;
44
+ _this.disableCommandMode = true;
45
+ _this.toDisposeOnMsgChanged = void 0;
46
+ /**
47
+ * Register a new kernel
48
+ */
49
+ _this.handleKernelChanged = function () {
50
+ _this.setState({
51
+ msg_id: undefined
52
+ });
53
+ };
54
+ _this.handleCommClosed = function () {
55
+ _this.isCommClosed = true;
56
+ };
57
+ /**
58
+ * Send a custom msg over the comm.
59
+ */
60
+ _this.send = function (data, callbacks, buffers) {
61
+ if (_this.comm !== undefined) {
62
+ return _this.comm.send(data, callbacks, {}, buffers);
63
+ }
64
+ return undefined;
65
+ };
66
+ _this.comm = void 0;
67
+ _initializerDefineProperty(_this, "widgets", _descriptor3, _assertThisInitialized(_this));
68
+ _this.model_id = void 0;
69
+ _this.state_change = void 0;
70
+ _this.name = void 0;
71
+ _this.module = void 0;
72
+ _this.isCommClosed = false;
73
+ _this.model_module = void 0;
74
+ _this.model_name = void 0;
75
+ _this.model_module_version = void 0;
76
+ _this.view_module = void 0;
77
+ _this.view_name = void 0;
78
+ _this.view_module_version = void 0;
79
+ _this.view_count = void 0;
80
+ _this.widgetsId = props.widgetsId;
81
+ var attributes = props.attributes;
82
+ _this.model_module = attributes._model_module;
83
+ _this.model_name = attributes._model_name;
84
+ _this.model_module_version = attributes._model_module_version;
85
+ _this.view_module = attributes._view_module;
86
+ _this.view_name = attributes._view_name;
87
+ _this.view_module_version = attributes._view_module_version;
88
+ _this.view_count = attributes._view_count;
89
+ _this._msgHook = function (msg) {
90
+ _this.addFromMessage(msg);
91
+ return false;
92
+ };
93
+
94
+ // Attributes should be initialized here, since user initialization may depend on it
95
+ var comm = props.options.comm;
96
+ if (comm) {
97
+ // Remember comm associated with the model.
98
+ _this.comm = comm;
99
+
100
+ // Hook comm messages up to model.
101
+ comm.onClose(_this.handleCommClosed.bind(_assertThisInitialized(_this)));
102
+ comm.onMsg(_this.handleCommMsg.bind(_assertThisInitialized(_this)));
103
+ } else {
104
+ _this.isCommClosed = false;
105
+ }
106
+ _this.model_id = props.options.model_id;
107
+ _this.state_change = Promise.resolve();
108
+ _this.setState(attributes);
109
+ _this.libroContextKey = libroContextKey;
110
+ return _this;
111
+ }
112
+ WidgetView = inject(LibroContextKey)(WidgetView, undefined, 1) || WidgetView;
113
+ WidgetView = inject(ViewOption)(WidgetView, undefined, 0) || WidgetView;
114
+ _createClass(WidgetView, [{
115
+ key: "outputs",
116
+ get: function get() {
117
+ if (this.cell) {
118
+ return this.cell.outputArea;
119
+ }
120
+ return undefined;
121
+ }
122
+ }, {
123
+ key: "setCell",
124
+ value: function setCell(cell) {
125
+ var _this2 = this;
126
+ if (ExecutableCellView.is(cell)) {
127
+ this.cell = cell;
128
+ if (this.cell) {
129
+ this.cell.parentReady.then(function () {
130
+ var _this2$cell;
131
+ var notebookModel = (_this2$cell = _this2.cell) === null || _this2$cell === void 0 ? void 0 : _this2$cell.parent.model;
132
+ if (notebookModel instanceof LibroJupyterModel) {
133
+ watch(notebookModel, 'kernelConnection', _this2.handleKernelChanged);
134
+ }
135
+ return;
136
+ }).catch(console.error);
137
+ }
138
+ }
139
+ }
140
+ }, {
141
+ key: "resetMsgId",
142
+ value:
143
+ /**
144
+ * Reset the message id.
145
+ */
146
+ function resetMsgId() {
147
+ var _this$toDisposeOnMsgC, _this$cell;
148
+ (_this$toDisposeOnMsgC = this.toDisposeOnMsgChanged) === null || _this$toDisposeOnMsgC === void 0 || _this$toDisposeOnMsgC.dispose();
149
+ var notebookModel = (_this$cell = this.cell) === null || _this$cell === void 0 || (_this$cell = _this$cell.parent) === null || _this$cell === void 0 ? void 0 : _this$cell.model;
150
+ if (notebookModel instanceof LibroJupyterModel) {
151
+ var kernel = notebookModel.kernelConnection;
152
+ if (kernel && this.state['msg_id']) {
153
+ this.toDisposeOnMsgChanged = kernel.registerMessageHook(this.state['msg_id'], this._msgHook);
154
+ }
155
+ }
156
+ }
157
+ }, {
158
+ key: "addFromMessage",
159
+ value: function addFromMessage(msg) {
160
+ var msgType = msg.header.msg_type;
161
+ switch (msgType) {
162
+ case 'execute_result':
163
+ case 'display_data':
164
+ case 'stream':
165
+ case 'error':
166
+ {
167
+ var _this$outputs;
168
+ var model = msg.content;
169
+ model.output_type = msgType;
170
+ (_this$outputs = this.outputs) === null || _this$outputs === void 0 || _this$outputs.add(model);
171
+ break;
172
+ }
173
+ case 'clear_output':
174
+ this.clearOutput(msg.content.wait);
175
+ break;
176
+ default:
177
+ break;
178
+ }
179
+ }
180
+ }, {
181
+ key: "clearOutput",
182
+ value: function clearOutput() {
183
+ var _this$outputs2;
184
+ var wait = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
185
+ (_this$outputs2 = this.outputs) === null || _this$outputs2 === void 0 || _this$outputs2.clear(wait);
186
+ }
187
+ }, {
188
+ key: "onViewMount",
189
+ value: function onViewMount() {
190
+ var _this3 = this;
191
+ this.widgets = this.libroWidgetManager.getWidgets(this.widgetsId);
192
+ if (this.container && this.container.current && this.disableCommandMode) {
193
+ this.container.current.addEventListener('focusin', function () {
194
+ _this3.libroContextKey.disableCommandMode();
195
+ });
196
+ this.container.current.addEventListener('blur', function (e) {
197
+ var _this3$container;
198
+ if ((_this3$container = _this3.container) !== null && _this3$container !== void 0 && (_this3$container = _this3$container.current) !== null && _this3$container !== void 0 && _this3$container.contains(e.relatedTarget)) {
199
+ _this3.libroContextKey.disableCommandMode();
200
+ } else {
201
+ _this3.libroContextKey.enableCommandMode();
202
+ }
203
+ });
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Handle incoming comm msg.
209
+ */
210
+ }, {
211
+ key: "handleCommMsg",
212
+ value: function handleCommMsg(msg) {
213
+ var data = msg.content.data;
214
+ var method = data.method;
215
+ switch (method) {
216
+ case 'update':
217
+ case 'echo_update':
218
+ this.setState(data.state);
219
+ }
220
+ return Promise.resolve();
221
+ }
222
+ }, {
223
+ key: "setState",
224
+ value:
225
+ /**
226
+ * Handle when a widget is updated from the backend.
227
+ *
228
+ * This function is meant for internal use only. Values set here will not be propagated on a sync.
229
+ */
230
+ function setState(state) {
231
+ for (var key in state) {
232
+ var oldMsgId = this.state['msg_id'];
233
+ this.state[key] = state[key];
234
+ if (key === 'msg_id' && oldMsgId !== state['msg_id']) {
235
+ this.resetMsgId();
236
+ }
237
+ }
238
+ }
239
+
240
+ /**
241
+ * Serialize the model. See the deserialization function at the top of this file
242
+ * and the kernel-side serializer/deserializer.
243
+ */
244
+ }, {
245
+ key: "toJSON",
246
+ value: function toJSON() {
247
+ return this.toModelKey();
248
+ }
249
+ }, {
250
+ key: "toModelKey",
251
+ value: function toModelKey() {
252
+ return "IPY_MODEL_".concat(this.model_id);
253
+ }
254
+ }]);
255
+ return WidgetView;
256
+ }(BaseView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "libroWidgetManager", [_dec3], {
257
+ configurable: true,
258
+ enumerable: true,
259
+ writable: true,
260
+ initializer: null
261
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "state", [_dec4], {
262
+ configurable: true,
263
+ enumerable: true,
264
+ writable: true,
265
+ initializer: function initializer() {
266
+ return defaultWidgetState;
267
+ }
268
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "widgets", [_dec5], {
269
+ configurable: true,
270
+ enumerable: true,
271
+ writable: true,
272
+ initializer: null
273
+ })), _class2)) || _class) || _class);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-jupyter",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "libro"
@@ -31,22 +31,22 @@
31
31
  "src"
32
32
  ],
33
33
  "dependencies": {
34
- "@difizen/libro-cofine-editor": "^0.2.0",
35
- "@difizen/libro-code-editor": "^0.2.0",
36
- "@difizen/libro-code-cell": "^0.2.0",
37
- "@difizen/libro-codemirror": "^0.2.0",
38
- "@difizen/libro-rendermime": "^0.2.0",
39
- "@difizen/libro-common": "^0.2.0",
40
- "@difizen/libro-core": "^0.2.0",
41
- "@difizen/libro-kernel": "^0.2.0",
42
- "@difizen/libro-l10n": "^0.2.0",
43
- "@difizen/libro-output": "^0.2.0",
44
- "@difizen/libro-search": "^0.2.0",
45
- "@difizen/libro-search-code-cell": "^0.2.0",
46
- "@difizen/libro-lsp": "^0.2.0",
47
- "@difizen/libro-markdown-cell": "^0.2.0",
48
- "@difizen/libro-raw-cell": "^0.2.0",
49
- "@difizen/libro-language-client": "^0.2.0",
34
+ "@difizen/libro-cofine-editor": "^0.2.1",
35
+ "@difizen/libro-code-editor": "^0.2.1",
36
+ "@difizen/libro-code-cell": "^0.2.1",
37
+ "@difizen/libro-codemirror": "^0.2.1",
38
+ "@difizen/libro-rendermime": "^0.2.1",
39
+ "@difizen/libro-common": "^0.2.1",
40
+ "@difizen/libro-core": "^0.2.1",
41
+ "@difizen/libro-kernel": "^0.2.1",
42
+ "@difizen/libro-l10n": "^0.2.1",
43
+ "@difizen/libro-output": "^0.2.1",
44
+ "@difizen/libro-search": "^0.2.1",
45
+ "@difizen/libro-search-code-cell": "^0.2.1",
46
+ "@difizen/libro-lsp": "^0.2.1",
47
+ "@difizen/libro-markdown-cell": "^0.2.1",
48
+ "@difizen/libro-raw-cell": "^0.2.1",
49
+ "@difizen/libro-language-client": "^0.2.1",
50
50
  "@difizen/mana-app": "latest",
51
51
  "@difizen/mana-l10n": "latest",
52
52
  "@ant-design/colors": "^7.0.0",
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "peerDependencies": {
59
59
  "antd": "^5.8.6",
60
- "react": "^18.2.0"
60
+ "react": ">=16"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/react": "^18.2.25"
@@ -203,7 +203,7 @@ export const LibroWrappedBetweenCellContent: BetweenCellProvider = (props: {
203
203
  const { index, addCell } = props;
204
204
  const instance = useInject<LibroView>(ViewInstance);
205
205
  return (
206
- <DisplayWrapComponent mode={instance.model.readOnly}>
206
+ <DisplayWrapComponent mode={instance.model.cellsEditable}>
207
207
  <LibroCommonBetweenCellContent index={index} addCell={addCell} />
208
208
  </DisplayWrapComponent>
209
209
  );
@@ -7,8 +7,8 @@ import type {
7
7
  TooltipProviderOption,
8
8
  } from '@difizen/libro-code-editor';
9
9
  import { KernelError } from '@difizen/libro-kernel';
10
- import { LibroCellURIScheme } from '@difizen/libro-language-client';
11
- import { transient, URI } from '@difizen/mana-app';
10
+ import { getCellURI } from '@difizen/libro-language-client';
11
+ import { transient } from '@difizen/mana-app';
12
12
  import { view, ViewInstance } from '@difizen/mana-app';
13
13
  import { getOrigin, useInject } from '@difizen/mana-app';
14
14
  import { l10n } from '@difizen/mana-l10n';
@@ -39,7 +39,16 @@ const JupyterCodeCellComponent = forwardRef<HTMLDivElement>(
39
39
  @transient()
40
40
  @view('jupyter-code-cell-view')
41
41
  export class JupyterCodeCellView extends LibroCodeCellView {
42
- declare parent: LibroJupyterView;
42
+ protected declare _parent: LibroJupyterView;
43
+
44
+ override get parent() {
45
+ return this._parent;
46
+ }
47
+ override set parent(value: LibroJupyterView) {
48
+ this._parent = value;
49
+ this.parentDefer.resolve(this.parent);
50
+ }
51
+
43
52
  override view = JupyterCodeCellComponent;
44
53
  declare model: JupyterCodeCellModel;
45
54
 
@@ -55,9 +64,8 @@ export class JupyterCodeCellView extends LibroCodeCellView {
55
64
 
56
65
  protected override getEditorOption(): CodeEditorViewOptions {
57
66
  const options = super.getEditorOption();
58
- let uri = new URI(this.parent.model.filePath);
59
- uri = URI.withScheme(uri, LibroCellURIScheme);
60
- uri = URI.withQuery(uri, `cellid=${this.model.id}`);
67
+ const uri = getCellURI(this.parent.model, this.model);
68
+
61
69
  return {
62
70
  ...options,
63
71
  uuid: uri.toString(),
@@ -1,3 +1,4 @@
1
+ import type { LibroModel } from '@difizen/libro-core';
1
2
  import {
2
3
  KernelCommands,
3
4
  LibroCommandRegister,
@@ -40,8 +41,7 @@ export class LibroJupyterCommandContribution implements CommandContribution {
40
41
  return false;
41
42
  }
42
43
  return (
43
- !libro?.model.quickEditMode &&
44
- !libro?.model.readOnly &&
44
+ (libro?.model as LibroModel).executable &&
45
45
  path === LibroToolbarArea.HeaderLeft
46
46
  );
47
47
  },
@@ -72,8 +72,7 @@ export class LibroJupyterCommandContribution implements CommandContribution {
72
72
  }
73
73
  if (
74
74
  path !== LibroToolbarArea.HeaderCenter ||
75
- libro.model.quickEditMode ||
76
- libro.model.readOnly
75
+ !(libro?.model as LibroModel).executable
77
76
  ) {
78
77
  return false;
79
78
  }
@@ -108,8 +107,7 @@ export class LibroJupyterCommandContribution implements CommandContribution {
108
107
  return false;
109
108
  }
110
109
  return (
111
- !libro?.model.quickEditMode &&
112
- !libro?.model.readOnly &&
110
+ (libro?.model as LibroModel).executable &&
113
111
  path === LibroToolbarArea.CellRight
114
112
  );
115
113
  },
@@ -142,13 +140,16 @@ export class LibroJupyterCommandContribution implements CommandContribution {
142
140
  return false;
143
141
  }
144
142
  return (
145
- !libro?.model.quickEditMode &&
146
- path === LibroToolbarArea.HeaderCenter &&
147
- !libro.model.readOnly
143
+ (libro?.model as LibroJupyterModel).executable &&
144
+ path === LibroToolbarArea.HeaderCenter
148
145
  );
149
146
  },
150
147
  isEnabled: (cell, libro) => {
151
- if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
148
+ if (
149
+ !libro ||
150
+ !(libro instanceof LibroView) ||
151
+ !(libro?.model as LibroJupyterModel).executable
152
+ ) {
152
153
  return false;
153
154
  }
154
155
  return (
@@ -100,7 +100,7 @@ export const Location: React.FC = () => (
100
100
  <g
101
101
  id="2.0-kernel-启动前"
102
102
  transform="translate(-738.000000, -80.000000)"
103
- fill="#7B7B7B"
103
+ fill="currentColor"
104
104
  // fillRule="nonzero"
105
105
  >
106
106
  <g id="编组-24" transform="translate(637.000000, 80.000000)">
@@ -22,7 +22,7 @@ export class LibroJupyterContentContribution implements ContentContribution {
22
22
  jupyterModel.filePath = currentFileContents.path;
23
23
  jupyterModel.lastModified = jupyterModel.currentFileContents.last_modified;
24
24
 
25
- if (!jupyterModel.quickEditMode && !jupyterModel.readOnly) {
25
+ if (jupyterModel.executable) {
26
26
  jupyterModel.startKernelConnection();
27
27
  }
28
28
 
@@ -0,0 +1,67 @@
1
+ import type { NotebookOption } from '@difizen/libro-core';
2
+ import { ContentSaveContribution } from '@difizen/libro-core';
3
+ import type { IContentsModel } from '@difizen/libro-kernel';
4
+ import { ModalService, inject, singleton } from '@difizen/mana-app';
5
+
6
+ import type { LibroJupyterModel } from '../libro-jupyter-model.js';
7
+ import { SaveFileErrorModal } from '../toolbar/save-file-error.js';
8
+
9
+ @singleton({ contrib: ContentSaveContribution })
10
+ export class LibroJupyterContentSaveContribution implements ContentSaveContribution {
11
+ @inject(ModalService) protected readonly modalService: ModalService;
12
+
13
+ canHandle = () => {
14
+ return 2;
15
+ };
16
+ saveContent = async (options: NotebookOption, model: LibroJupyterModel) => {
17
+ const notebookContent = model.toJSON();
18
+ if (!model.currentFileContents) {
19
+ throw new Error('currentFileContents is undefined');
20
+ }
21
+
22
+ let res = {} as IContentsModel | undefined;
23
+
24
+ try {
25
+ res = await model.fileService.write(notebookContent, model.currentFileContents);
26
+ if (!res) {
27
+ return;
28
+ }
29
+ // 文件保存失败
30
+ if (res.last_modified === model.lastModified || res.size === 0) {
31
+ const errorMsg = `File Save Error: ${res?.message} `;
32
+ model.fileService.fileSaveErrorEmitter.fire({
33
+ cause: res.message,
34
+ msg: errorMsg,
35
+ name: res.name,
36
+ path: res.path,
37
+ created: res.created,
38
+ last_modified: res.last_modified,
39
+ size: res.size,
40
+ type: res.type,
41
+ });
42
+ this.modalService.openModal(SaveFileErrorModal);
43
+
44
+ throw new Error(errorMsg);
45
+ }
46
+ } catch (e: any) {
47
+ if (!res) {
48
+ return;
49
+ }
50
+ model.fileService.fileSaveErrorEmitter.fire({
51
+ cause: e.errorCause,
52
+ msg: e.message,
53
+ name: res.name || model.currentFileContents.name,
54
+ path: res.path || model.currentFileContents.path,
55
+ created: res.created || model.currentFileContents.created,
56
+ last_modified: res.last_modified || model.currentFileContents.last_modified,
57
+ size: res.size || model.currentFileContents.size,
58
+ type: res.type || model.currentFileContents.type,
59
+ });
60
+ this.modalService.openModal(SaveFileErrorModal);
61
+
62
+ throw new Error('File Save Error');
63
+ }
64
+
65
+ await model.createCheckpoint();
66
+ };
67
+ }
@@ -1,4 +1,5 @@
1
1
  import type { ModalItemProps, ModalItem } from '@difizen/mana-app';
2
+ import { CommandRegistry } from '@difizen/mana-app';
2
3
  import { URI, useInject, ViewManager } from '@difizen/mana-app';
3
4
  import { Col, Form, message, Row, Input, Modal } from 'antd';
4
5
  import type { InputRef } from 'antd';
@@ -27,6 +28,7 @@ export const FileCreateModalComponent: React.FC<ModalItemProps<ModalItemType>> =
27
28
  data,
28
29
  }: ModalItemProps<ModalItemType>) => {
29
30
  const fileService = useInject(JupyterFileService);
31
+ const commands = useInject(CommandRegistry);
30
32
  const viewManager = useInject(ViewManager);
31
33
  const [fileType, setFileType] = useState<FileType>(data?.fileType);
32
34
  const [fileView, setFileView] = useState<FileView>();
@@ -37,13 +39,20 @@ export const FileCreateModalComponent: React.FC<ModalItemProps<ModalItemType>> =
37
39
  await form.validateFields();
38
40
  close();
39
41
  try {
40
- await fileService.newFile(
42
+ const stat = await fileService.newFile(
41
43
  values.fileName + (fileType || ''),
42
44
  new URI(data?.path),
43
45
  );
44
46
  if (fileView) {
45
47
  fileView.model.refresh();
46
48
  }
49
+ if (stat.isFile) {
50
+ commands.executeCommand('fileTree.command.openfile', {
51
+ fileStat: stat,
52
+ uri: stat.resource,
53
+ });
54
+ }
55
+ // message.success('新建文件成功');
47
56
  } catch {
48
57
  message.error('新建文件失败');
49
58
  }
@@ -205,7 +205,7 @@ export class JupyterFileService extends FileService {
205
205
  ext,
206
206
  });
207
207
  await this.rename(new URI(res.path.toString()), fileName);
208
- return this.resolve(target);
208
+ return this.resolve(targetFileUri);
209
209
  }
210
210
 
211
211
  async newFileDir(dirName: string, target: URI): Promise<FileStatWithMetadata> {
package/src/file/index.ts CHANGED
@@ -7,3 +7,4 @@ export * from './file-protocol.js';
7
7
  export * from './file-icon.js';
8
8
  export * from './file-create-modal.js';
9
9
  export * from './file-createdir-modal.js';
10
+ export * from './file-command.js';
package/src/index.ts CHANGED
@@ -32,3 +32,4 @@ export * from './toolbar/index.js';
32
32
  export * from './file/index.js';
33
33
  export * from './libro-jupyter-view.js';
34
34
  export * from './config/index.js';
35
+ export * from './widget/index.js';