@jupyter-notebook/notebook-extension 7.5.0-alpha.2 → 7.5.0-beta.0

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.
package/lib/index.js CHANGED
@@ -57,8 +57,8 @@ const checkpoints = {
57
57
  description: 'A plugin for the checkpoint indicator.',
58
58
  autoStart: true,
59
59
  requires: [IDocumentManager, ITranslator],
60
- optional: [INotebookShell, IToolbarWidgetRegistry],
61
- activate: (app, docManager, translator, notebookShell, toolbarRegistry) => {
60
+ optional: [INotebookShell, IToolbarWidgetRegistry, ISettingRegistry],
61
+ activate: (app, docManager, translator, notebookShell, toolbarRegistry, settingRegistry) => {
62
62
  const { shell } = app;
63
63
  const trans = translator.load('notebook');
64
64
  const node = document.createElement('div');
@@ -70,33 +70,92 @@ const checkpoints = {
70
70
  return widget;
71
71
  });
72
72
  }
73
- const onChange = async () => {
73
+ const getCurrent = () => {
74
74
  const current = shell.currentWidget;
75
75
  if (!current) {
76
- return;
76
+ return null;
77
77
  }
78
78
  const context = docManager.contextForWidget(current);
79
- context === null || context === void 0 ? void 0 : context.fileChanged.disconnect(onChange);
80
- context === null || context === void 0 ? void 0 : context.fileChanged.connect(onChange);
81
- const checkpoints = await (context === null || context === void 0 ? void 0 : context.listCheckpoints());
79
+ if (!context) {
80
+ return null;
81
+ }
82
+ return context;
83
+ };
84
+ const updateCheckpointDisplay = async () => {
85
+ const current = getCurrent();
86
+ if (!current) {
87
+ return;
88
+ }
89
+ const checkpoints = await current.listCheckpoints();
82
90
  if (!checkpoints || !checkpoints.length) {
91
+ node.textContent = '';
83
92
  return;
84
93
  }
85
94
  const checkpoint = checkpoints[checkpoints.length - 1];
86
95
  node.textContent = trans.__('Last Checkpoint: %1', Time.formatHuman(new Date(checkpoint.last_modified)));
87
96
  };
97
+ const onSaveState = async (sender, state) => {
98
+ if (state !== 'completed') {
99
+ return;
100
+ }
101
+ // Add a small artificial delay so that the UI can pick up the newly created checkpoint.
102
+ // Since the save state signal is emitted after a file save, but not after a checkpoint has been created.
103
+ setTimeout(() => {
104
+ void updateCheckpointDisplay();
105
+ }, 500);
106
+ };
107
+ const onChange = async () => {
108
+ const context = getCurrent();
109
+ if (!context) {
110
+ return;
111
+ }
112
+ context.saveState.disconnect(onSaveState);
113
+ context.saveState.connect(onSaveState);
114
+ await updateCheckpointDisplay();
115
+ };
88
116
  if (notebookShell) {
89
117
  notebookShell.currentChanged.connect(onChange);
90
118
  }
91
- new Poll({
92
- auto: true,
93
- factory: () => onChange(),
94
- frequency: {
95
- interval: 2000,
96
- backoff: false,
97
- },
98
- standby: 'when-hidden',
99
- });
119
+ let checkpointPollingInterval = 30; // Default 30 seconds
120
+ let poll = null;
121
+ const createPoll = () => {
122
+ if (poll) {
123
+ poll.dispose();
124
+ }
125
+ if (checkpointPollingInterval > 0) {
126
+ poll = new Poll({
127
+ auto: true,
128
+ factory: () => updateCheckpointDisplay(),
129
+ frequency: {
130
+ interval: checkpointPollingInterval * 1000,
131
+ backoff: false,
132
+ },
133
+ standby: 'when-hidden',
134
+ });
135
+ }
136
+ };
137
+ const updateSettings = (settings) => {
138
+ checkpointPollingInterval = settings.get('checkpointPollingInterval')
139
+ .composite;
140
+ createPoll();
141
+ };
142
+ if (settingRegistry) {
143
+ const loadSettings = settingRegistry.load(checkpoints.id);
144
+ Promise.all([loadSettings, app.restored])
145
+ .then(([settings]) => {
146
+ updateSettings(settings);
147
+ settings.changed.connect(updateSettings);
148
+ })
149
+ .catch((reason) => {
150
+ console.error(`Failed to load settings for ${checkpoints.id}: ${reason.message}`);
151
+ // Fall back to creating poll with default settings
152
+ createPoll();
153
+ });
154
+ }
155
+ else {
156
+ // Create poll with default settings
157
+ createPoll();
158
+ }
100
159
  },
101
160
  };
102
161
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyter-notebook/notebook-extension",
3
- "version": "7.5.0-alpha.2",
3
+ "version": "7.5.0-beta.0",
4
4
  "description": "Jupyter Notebook - Notebook Extension",
5
5
  "homepage": "https://github.com/jupyter/notebook",
6
6
  "bugs": {
@@ -38,14 +38,14 @@
38
38
  "watch": "tsc -b --watch"
39
39
  },
40
40
  "dependencies": {
41
- "@jupyter-notebook/application": "^7.5.0-alpha.2",
42
- "@jupyterlab/application": "~4.5.0-alpha.3",
43
- "@jupyterlab/apputils": "~4.6.0-alpha.3",
44
- "@jupyterlab/cells": "~4.5.0-alpha.3",
45
- "@jupyterlab/docmanager": "~4.5.0-alpha.3",
46
- "@jupyterlab/notebook": "~4.5.0-alpha.3",
47
- "@jupyterlab/settingregistry": "~4.5.0-alpha.3",
48
- "@jupyterlab/translation": "~4.5.0-alpha.3",
41
+ "@jupyter-notebook/application": "^7.5.0-beta.0",
42
+ "@jupyterlab/application": "~4.5.0-beta.0",
43
+ "@jupyterlab/apputils": "~4.6.0-beta.0",
44
+ "@jupyterlab/cells": "~4.5.0-beta.0",
45
+ "@jupyterlab/docmanager": "~4.5.0-beta.0",
46
+ "@jupyterlab/notebook": "~4.5.0-beta.0",
47
+ "@jupyterlab/settingregistry": "~4.5.0-beta.0",
48
+ "@jupyterlab/translation": "~4.5.0-beta.0",
49
49
  "@lumino/polling": "^2.1.4",
50
50
  "@lumino/widgets": "^2.7.1",
51
51
  "react": "^18.2.0",
@@ -4,7 +4,15 @@
4
4
  "jupyter.lab.toolbars": {
5
5
  "TopBar": [{ "name": "checkpoint", "rank": 20 }]
6
6
  },
7
- "properties": {},
7
+ "properties": {
8
+ "checkpointPollingInterval": {
9
+ "type": "number",
10
+ "title": "Checkpoint Polling Interval (seconds)",
11
+ "description": "How often to check for checkpoints (in seconds). Set to 0 to disable polling.",
12
+ "default": 30,
13
+ "minimum": 0
14
+ }
15
+ },
8
16
  "additionalProperties": false,
9
17
  "type": "object"
10
18
  }