@jupyterlab/apputils-extension 4.4.0-alpha.3 → 4.4.0-beta.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.
- package/lib/announcements.js +13 -16
- package/lib/announcements.js.map +1 -1
- package/lib/index.js +11 -9
- package/lib/index.js.map +1 -1
- package/lib/licensesplugin.d.ts +10 -0
- package/lib/licensesplugin.js +174 -0
- package/lib/licensesplugin.js.map +1 -0
- package/lib/notificationplugin.js.map +1 -1
- package/lib/palette.js.map +1 -1
- package/lib/settingconnector.d.ts +2 -2
- package/lib/settingconnector.js.map +1 -1
- package/lib/settingsplugin.d.ts +7 -1
- package/lib/settingsplugin.js +19 -6
- package/lib/settingsplugin.js.map +1 -1
- package/lib/shortcuts.js.map +1 -1
- package/lib/statusbarplugin.js.map +1 -1
- package/lib/themesplugins.js.map +1 -1
- package/lib/workspacesplugin.js.map +1 -1
- package/package.json +16 -16
- package/schema/notification.json +8 -3
- package/src/announcements.ts +16 -11
- package/src/index.ts +15 -13
- package/src/licensesplugin.ts +228 -0
- package/src/settingconnector.ts +8 -5
- package/src/settingsplugin.ts +29 -6
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Jupyter Development Team.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
ILayoutRestorer,
|
|
8
|
+
JupyterFrontEnd,
|
|
9
|
+
JupyterFrontEndPlugin
|
|
10
|
+
} from '@jupyterlab/application';
|
|
11
|
+
import {
|
|
12
|
+
ICommandPalette,
|
|
13
|
+
ILicensesClient,
|
|
14
|
+
Licenses,
|
|
15
|
+
MainAreaWidget,
|
|
16
|
+
WidgetTracker
|
|
17
|
+
} from '@jupyterlab/apputils';
|
|
18
|
+
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
|
|
19
|
+
import { IMainMenu } from '@jupyterlab/mainmenu';
|
|
20
|
+
import { ITranslator } from '@jupyterlab/translation';
|
|
21
|
+
import {
|
|
22
|
+
CommandToolbarButton,
|
|
23
|
+
copyrightIcon,
|
|
24
|
+
refreshIcon,
|
|
25
|
+
Toolbar
|
|
26
|
+
} from '@jupyterlab/ui-components';
|
|
27
|
+
import { ReadonlyJSONObject } from '@lumino/coreutils';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The command IDs used by the licenses plugin.
|
|
31
|
+
*/
|
|
32
|
+
namespace CommandIDs {
|
|
33
|
+
export const licenses = 'apputils:licenses';
|
|
34
|
+
|
|
35
|
+
export const licenseReport = 'apputils:license-report';
|
|
36
|
+
|
|
37
|
+
export const refreshLicenses = 'apputils:licenses-refresh';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The license client plugin for fetching licenses.
|
|
42
|
+
*/
|
|
43
|
+
export const licensesClient: JupyterFrontEndPlugin<ILicensesClient> = {
|
|
44
|
+
id: '@jupyterlab/apputils-extension:licenses-client',
|
|
45
|
+
description: 'The licenses client plugin for fetching licenses.',
|
|
46
|
+
autoStart: true,
|
|
47
|
+
provides: ILicensesClient,
|
|
48
|
+
activate: (app: JupyterFrontEnd) => {
|
|
49
|
+
const licensesUrl =
|
|
50
|
+
URLExt.join(
|
|
51
|
+
PageConfig.getBaseUrl(),
|
|
52
|
+
PageConfig.getOption('licensesUrl')
|
|
53
|
+
) + '/';
|
|
54
|
+
const serverSettings = app.serviceManager.serverSettings;
|
|
55
|
+
return new Licenses.LicensesClient({ licensesUrl, serverSettings });
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A plugin to add a licenses reporting tools.
|
|
61
|
+
*/
|
|
62
|
+
export const licensesPlugin: JupyterFrontEndPlugin<void> = {
|
|
63
|
+
id: '@jupyterlab/apputils-extension:licenses-plugin',
|
|
64
|
+
description: 'Adds licenses reporting tools.',
|
|
65
|
+
requires: [ILicensesClient, ITranslator],
|
|
66
|
+
optional: [ILayoutRestorer, IMainMenu, ICommandPalette],
|
|
67
|
+
autoStart: true,
|
|
68
|
+
activate: (
|
|
69
|
+
app: JupyterFrontEnd,
|
|
70
|
+
client: ILicensesClient,
|
|
71
|
+
translator: ITranslator,
|
|
72
|
+
restorer: ILayoutRestorer | null,
|
|
73
|
+
menu: IMainMenu | null,
|
|
74
|
+
palette: ICommandPalette | null
|
|
75
|
+
) => {
|
|
76
|
+
const { commands, shell } = app;
|
|
77
|
+
|
|
78
|
+
const trans = translator.load('jupyterlab');
|
|
79
|
+
|
|
80
|
+
const category = trans.__('Help');
|
|
81
|
+
const downloadAsText = trans.__('Download All Licenses as');
|
|
82
|
+
const refreshLicenses = trans.__('Refresh Licenses');
|
|
83
|
+
|
|
84
|
+
const licensesNamespace = 'help-licenses';
|
|
85
|
+
const licensesTracker = new WidgetTracker<MainAreaWidget<Licenses>>({
|
|
86
|
+
namespace: licensesNamespace
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// translation strings
|
|
90
|
+
const licensesText = trans.__('Licenses');
|
|
91
|
+
|
|
92
|
+
// an incrementer for license widget ids
|
|
93
|
+
let counter = 0;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Create a MainAreaWidget for a license viewer
|
|
97
|
+
*/
|
|
98
|
+
function createLicenseWidget(args: Licenses.ICreateArgs) {
|
|
99
|
+
const licensesModel = new Licenses.Model({
|
|
100
|
+
...args,
|
|
101
|
+
client,
|
|
102
|
+
trans
|
|
103
|
+
});
|
|
104
|
+
const content = new Licenses({ model: licensesModel });
|
|
105
|
+
content.id = `${licensesNamespace}-${++counter}`;
|
|
106
|
+
content.title.label = licensesText;
|
|
107
|
+
content.title.icon = copyrightIcon;
|
|
108
|
+
const main = new MainAreaWidget({
|
|
109
|
+
content,
|
|
110
|
+
reveal: licensesModel.licensesReady
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
main.toolbar.addItem(
|
|
114
|
+
'refresh-licenses',
|
|
115
|
+
new CommandToolbarButton({
|
|
116
|
+
id: CommandIDs.refreshLicenses,
|
|
117
|
+
args: { noLabel: 1 },
|
|
118
|
+
commands
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
main.toolbar.addItem('spacer', Toolbar.createSpacerItem());
|
|
123
|
+
|
|
124
|
+
for (const format of Object.keys(Licenses.REPORT_FORMATS)) {
|
|
125
|
+
const button = new CommandToolbarButton({
|
|
126
|
+
id: CommandIDs.licenseReport,
|
|
127
|
+
args: { format, noLabel: 1 },
|
|
128
|
+
commands
|
|
129
|
+
});
|
|
130
|
+
main.toolbar.addItem(`download-${format}`, button);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return main;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Return a full license report format based on a format name
|
|
138
|
+
*/
|
|
139
|
+
function formatOrDefault(format: string): Licenses.IReportFormat {
|
|
140
|
+
return (
|
|
141
|
+
Licenses.REPORT_FORMATS[format] ||
|
|
142
|
+
Licenses.REPORT_FORMATS[Licenses.DEFAULT_FORMAT]
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// register license-related commands
|
|
147
|
+
commands.addCommand(CommandIDs.licenses, {
|
|
148
|
+
label: licensesText,
|
|
149
|
+
execute: (args: any) => {
|
|
150
|
+
// bail if no license API is available from the server
|
|
151
|
+
if (!PageConfig.getOption('licensesUrl')) {
|
|
152
|
+
console.warn('No license API available from the server');
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const licenseMain = createLicenseWidget(args as Licenses.ICreateArgs);
|
|
156
|
+
shell.add(licenseMain, 'main', { type: 'Licenses' });
|
|
157
|
+
|
|
158
|
+
// add to tracker so it can be restored, and update when choices change
|
|
159
|
+
void licensesTracker.add(licenseMain);
|
|
160
|
+
licenseMain.content.model.trackerDataChanged.connect(() => {
|
|
161
|
+
void licensesTracker.save(licenseMain);
|
|
162
|
+
});
|
|
163
|
+
return licenseMain;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
commands.addCommand(CommandIDs.refreshLicenses, {
|
|
168
|
+
label: args => (args.noLabel ? '' : refreshLicenses),
|
|
169
|
+
caption: refreshLicenses,
|
|
170
|
+
icon: refreshIcon,
|
|
171
|
+
execute: async () => {
|
|
172
|
+
return licensesTracker.currentWidget?.content.model.initLicenses();
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
commands.addCommand(CommandIDs.licenseReport, {
|
|
177
|
+
label: args => {
|
|
178
|
+
if (args.noLabel) {
|
|
179
|
+
return '';
|
|
180
|
+
}
|
|
181
|
+
const format = formatOrDefault(`${args.format}`);
|
|
182
|
+
return `${downloadAsText} ${format.title}`;
|
|
183
|
+
},
|
|
184
|
+
caption: args => {
|
|
185
|
+
const format = formatOrDefault(`${args.format}`);
|
|
186
|
+
return `${downloadAsText} ${format.title}`;
|
|
187
|
+
},
|
|
188
|
+
icon: args => {
|
|
189
|
+
const format = formatOrDefault(`${args.format}`);
|
|
190
|
+
return format.icon;
|
|
191
|
+
},
|
|
192
|
+
execute: async args => {
|
|
193
|
+
const format = formatOrDefault(`${args.format}`);
|
|
194
|
+
return await licensesTracker.currentWidget?.content.model.download({
|
|
195
|
+
format: format.id
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// handle optional integrations
|
|
201
|
+
if (palette) {
|
|
202
|
+
palette.addItem({ command: CommandIDs.licenses, category });
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (menu) {
|
|
206
|
+
const helpMenu = menu.helpMenu;
|
|
207
|
+
helpMenu.addGroup([{ command: CommandIDs.licenses }], 0);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (restorer) {
|
|
211
|
+
void restorer.restore(licensesTracker, {
|
|
212
|
+
command: CommandIDs.licenses,
|
|
213
|
+
name: widget => 'licenses',
|
|
214
|
+
args: widget => {
|
|
215
|
+
const { currentBundleName, currentPackageIndex, packageFilter } =
|
|
216
|
+
widget.content.model;
|
|
217
|
+
|
|
218
|
+
const args: Licenses.ICreateArgs = {
|
|
219
|
+
currentBundleName,
|
|
220
|
+
currentPackageIndex,
|
|
221
|
+
packageFilter
|
|
222
|
+
};
|
|
223
|
+
return args as ReadonlyJSONObject;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
package/src/settingconnector.ts
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { PageConfig } from '@jupyterlab/coreutils';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
ISettingConnector,
|
|
9
|
+
ISettingRegistry
|
|
10
|
+
} from '@jupyterlab/settingregistry';
|
|
8
11
|
import { DataConnector, IDataConnector } from '@jupyterlab/statedb';
|
|
9
12
|
import { Throttler } from '@lumino/polling';
|
|
10
13
|
|
|
@@ -14,10 +17,10 @@ import { Throttler } from '@lumino/polling';
|
|
|
14
17
|
* #### Notes
|
|
15
18
|
* This connector adds a query parameter to the base services setting manager.
|
|
16
19
|
*/
|
|
17
|
-
export class SettingConnector
|
|
18
|
-
ISettingRegistry.IPlugin,
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
export class SettingConnector
|
|
21
|
+
extends DataConnector<ISettingRegistry.IPlugin, string>
|
|
22
|
+
implements ISettingConnector
|
|
23
|
+
{
|
|
21
24
|
constructor(connector: IDataConnector<ISettingRegistry.IPlugin, string>) {
|
|
22
25
|
super();
|
|
23
26
|
this._connector = connector;
|
package/src/settingsplugin.ts
CHANGED
|
@@ -8,18 +8,43 @@ import {
|
|
|
8
8
|
JupyterFrontEndPlugin
|
|
9
9
|
} from '@jupyterlab/application';
|
|
10
10
|
import { PageConfig } from '@jupyterlab/coreutils';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
ISettingConnector,
|
|
13
|
+
ISettingRegistry,
|
|
14
|
+
SettingRegistry
|
|
15
|
+
} from '@jupyterlab/settingregistry';
|
|
12
16
|
import { SettingConnector } from './settingconnector';
|
|
13
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Provides the settings connector as a separate plugin to allow for alternative
|
|
20
|
+
* implementations that may want to fetch settings from a different source or
|
|
21
|
+
* endpoint.
|
|
22
|
+
*/
|
|
23
|
+
export const settingsConnector: JupyterFrontEndPlugin<ISettingConnector> = {
|
|
24
|
+
id: '@jupyterlab/apputils-extension:settings-connector',
|
|
25
|
+
description: 'Provides the settings connector.',
|
|
26
|
+
autoStart: true,
|
|
27
|
+
provides: ISettingConnector,
|
|
28
|
+
activate: (app: JupyterFrontEnd) =>
|
|
29
|
+
new SettingConnector(app.serviceManager.settings)
|
|
30
|
+
};
|
|
31
|
+
|
|
14
32
|
/**
|
|
15
33
|
* The default setting registry provider.
|
|
16
34
|
*/
|
|
17
35
|
export const settingsPlugin: JupyterFrontEndPlugin<ISettingRegistry> = {
|
|
18
36
|
id: '@jupyterlab/apputils-extension:settings',
|
|
37
|
+
autoStart: true,
|
|
38
|
+
provides: ISettingRegistry,
|
|
39
|
+
optional: [ISettingConnector],
|
|
19
40
|
description: 'Provides the setting registry.',
|
|
20
|
-
activate: async (
|
|
41
|
+
activate: async (
|
|
42
|
+
app: JupyterFrontEnd,
|
|
43
|
+
settingsConnector: ISettingConnector | null
|
|
44
|
+
): Promise<ISettingRegistry> => {
|
|
21
45
|
const { isDisabled } = PageConfig.Extension;
|
|
22
|
-
const connector =
|
|
46
|
+
const connector =
|
|
47
|
+
settingsConnector ?? new SettingConnector(app.serviceManager.settings);
|
|
23
48
|
|
|
24
49
|
// On startup, check if a plugin is available in the application.
|
|
25
50
|
// This helps avoid loading plugin files from other lab-based applications
|
|
@@ -61,7 +86,5 @@ export const settingsPlugin: JupyterFrontEndPlugin<ISettingRegistry> = {
|
|
|
61
86
|
});
|
|
62
87
|
|
|
63
88
|
return registry;
|
|
64
|
-
}
|
|
65
|
-
autoStart: true,
|
|
66
|
-
provides: ISettingRegistry
|
|
89
|
+
}
|
|
67
90
|
};
|