1 |
|
2 |
|
3 | import { TextItem } from '@jupyterlab/statusbar';
|
4 | import { nullTranslator } from '@jupyterlab/translation';
|
5 | import { VDomModel, VDomRenderer } from '@jupyterlab/ui-components';
|
6 | import React from 'react';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function SavingStatusComponent(props) {
|
15 | return React.createElement(TextItem, { source: props.fileStatus });
|
16 | }
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | const SAVING_COMPLETE_MESSAGE_MILLIS = 2000;
|
22 |
|
23 |
|
24 |
|
25 | export class SavingStatus extends VDomRenderer {
|
26 | |
27 |
|
28 |
|
29 | constructor(opts) {
|
30 | super(new SavingStatus.Model(opts.docManager));
|
31 | const translator = opts.translator || nullTranslator;
|
32 | const trans = translator.load('jupyterlab');
|
33 | this._statusMap = {
|
34 | completed: trans.__('Saving completed'),
|
35 | started: trans.__('Saving started'),
|
36 | failed: trans.__('Saving failed')
|
37 | };
|
38 | }
|
39 | |
40 |
|
41 |
|
42 | render() {
|
43 | if (this.model === null || this.model.status === null) {
|
44 | return null;
|
45 | }
|
46 | else {
|
47 | return (React.createElement(SavingStatusComponent, { fileStatus: this._statusMap[this.model.status] }));
|
48 | }
|
49 | }
|
50 | }
|
51 |
|
52 |
|
53 |
|
54 | (function (SavingStatus) {
|
55 | |
56 |
|
57 |
|
58 | class Model extends VDomModel {
|
59 | |
60 |
|
61 |
|
62 | constructor(docManager) {
|
63 | super();
|
64 | |
65 |
|
66 |
|
67 | this._onStatusChange = (_, newStatus) => {
|
68 | this._status = newStatus;
|
69 | if (this._status === 'completed') {
|
70 | setTimeout(() => {
|
71 | this._status = null;
|
72 | this.stateChanged.emit(void 0);
|
73 | }, SAVING_COMPLETE_MESSAGE_MILLIS);
|
74 | this.stateChanged.emit(void 0);
|
75 | }
|
76 | else {
|
77 | this.stateChanged.emit(void 0);
|
78 | }
|
79 | };
|
80 | this._status = null;
|
81 | this._widget = null;
|
82 | this._status = null;
|
83 | this.widget = null;
|
84 | this._docManager = docManager;
|
85 | }
|
86 | |
87 |
|
88 |
|
89 | get status() {
|
90 | return this._status;
|
91 | }
|
92 | |
93 |
|
94 |
|
95 |
|
96 |
|
97 | get widget() {
|
98 | return this._widget;
|
99 | }
|
100 | set widget(widget) {
|
101 | var _a, _b;
|
102 | const oldWidget = this._widget;
|
103 | if (oldWidget !== null) {
|
104 | const oldContext = this._docManager.contextForWidget(oldWidget);
|
105 | if (oldContext) {
|
106 | oldContext.saveState.disconnect(this._onStatusChange);
|
107 | }
|
108 | else if ((_a = this._widget.content) === null || _a === void 0 ? void 0 : _a.saveStateChanged) {
|
109 | this._widget.content.saveStateChanged.disconnect(this._onStatusChange);
|
110 | }
|
111 | }
|
112 | this._widget = widget;
|
113 | if (this._widget === null) {
|
114 | this._status = null;
|
115 | }
|
116 | else {
|
117 | const widgetContext = this._docManager.contextForWidget(this._widget);
|
118 | if (widgetContext) {
|
119 | widgetContext.saveState.connect(this._onStatusChange);
|
120 | }
|
121 | else if ((_b = this._widget.content) === null || _b === void 0 ? void 0 : _b.saveStateChanged) {
|
122 | this._widget.content.saveStateChanged.connect(this._onStatusChange);
|
123 | }
|
124 | }
|
125 | }
|
126 | }
|
127 | SavingStatus.Model = Model;
|
128 | })(SavingStatus || (SavingStatus = {}));
|
129 |
|
\ | No newline at end of file |