@jupyterlab/settingeditor 4.0.0-alpha.8 → 4.0.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/SettingsFormEditor.d.ts +29 -11
- package/lib/SettingsFormEditor.js +79 -134
- package/lib/SettingsFormEditor.js.map +1 -1
- package/lib/inspector.js +1 -1
- package/lib/inspector.js.map +1 -1
- package/lib/jsonsettingeditor.d.ts +1 -1
- package/lib/jsonsettingeditor.js +1 -1
- package/lib/jsonsettingeditor.js.map +1 -1
- package/lib/plugineditor.js.map +1 -1
- package/lib/pluginlist.d.ts +27 -5
- package/lib/pluginlist.js +145 -50
- package/lib/pluginlist.js.map +1 -1
- package/lib/raweditor.d.ts +2 -6
- package/lib/raweditor.js +22 -33
- package/lib/raweditor.js.map +1 -1
- package/lib/settingseditor.d.ts +3 -2
- package/lib/settingseditor.js +9 -4
- package/lib/settingseditor.js.map +1 -1
- package/lib/settingspanel.d.ts +12 -3
- package/lib/settingspanel.js +46 -6
- package/lib/settingspanel.js.map +1 -1
- package/package.json +27 -24
- package/src/SettingsFormEditor.tsx +306 -0
- package/src/index.ts +10 -0
- package/src/inspector.ts +144 -0
- package/src/jsonsettingeditor.tsx +482 -0
- package/src/plugineditor.ts +257 -0
- package/src/pluginlist.tsx +538 -0
- package/src/raweditor.ts +422 -0
- package/src/settingseditor.tsx +210 -0
- package/src/settingspanel.tsx +218 -0
- package/src/tokens.ts +33 -0
- package/style/base.css +45 -199
- package/lib/splitpanel.d.ts +0 -13
- package/lib/splitpanel.js +0 -26
- package/lib/splitpanel.js.map +0 -1
package/src/raweditor.ts
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { CodeEditor, CodeEditorWrapper } from '@jupyterlab/codeeditor';
|
|
5
|
+
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
6
|
+
import { ISettingRegistry } from '@jupyterlab/settingregistry';
|
|
7
|
+
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
|
|
8
|
+
import { CommandToolbarButton, Toolbar } from '@jupyterlab/ui-components';
|
|
9
|
+
import { CommandRegistry } from '@lumino/commands';
|
|
10
|
+
import { Message } from '@lumino/messaging';
|
|
11
|
+
import { ISignal, Signal } from '@lumino/signaling';
|
|
12
|
+
import { BoxLayout, SplitPanel, Widget } from '@lumino/widgets';
|
|
13
|
+
import { createInspector } from './inspector';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A class name added to all raw editors.
|
|
17
|
+
*/
|
|
18
|
+
const RAW_EDITOR_CLASS = 'jp-SettingsRawEditor';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A class name added to the user settings editor.
|
|
22
|
+
*/
|
|
23
|
+
const USER_CLASS = 'jp-SettingsRawEditor-user';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A class name added to the user editor when there are validation errors.
|
|
27
|
+
*/
|
|
28
|
+
const ERROR_CLASS = 'jp-mod-error';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A raw JSON settings editor.
|
|
32
|
+
*/
|
|
33
|
+
export class RawEditor extends SplitPanel {
|
|
34
|
+
/**
|
|
35
|
+
* Create a new plugin editor.
|
|
36
|
+
*/
|
|
37
|
+
constructor(options: RawEditor.IOptions) {
|
|
38
|
+
super({
|
|
39
|
+
orientation: 'horizontal',
|
|
40
|
+
renderer: SplitPanel.defaultRenderer,
|
|
41
|
+
spacing: 1
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const { commands, editorFactory, registry, translator } = options;
|
|
45
|
+
this.registry = registry;
|
|
46
|
+
this.translator = translator || nullTranslator;
|
|
47
|
+
this._commands = commands;
|
|
48
|
+
|
|
49
|
+
// Create read-only defaults editor.
|
|
50
|
+
const defaults = (this._defaults = new CodeEditorWrapper({
|
|
51
|
+
editorOptions: {
|
|
52
|
+
config: { readOnly: true }
|
|
53
|
+
},
|
|
54
|
+
model: new CodeEditor.Model({ mimeType: 'text/javascript' }),
|
|
55
|
+
factory: editorFactory
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
// Create read-write user settings editor.
|
|
59
|
+
const user = (this._user = new CodeEditorWrapper({
|
|
60
|
+
editorOptions: {
|
|
61
|
+
config: { lineNumbers: true }
|
|
62
|
+
},
|
|
63
|
+
model: new CodeEditor.Model({ mimeType: 'text/javascript' }),
|
|
64
|
+
factory: editorFactory
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
user.addClass(USER_CLASS);
|
|
68
|
+
user.editor.model.sharedModel.changed.connect(this._onTextChanged, this);
|
|
69
|
+
|
|
70
|
+
// Create and set up an inspector.
|
|
71
|
+
this._inspector = createInspector(
|
|
72
|
+
this,
|
|
73
|
+
options.rendermime,
|
|
74
|
+
this.translator
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
this.addClass(RAW_EDITOR_CLASS);
|
|
78
|
+
this._onSaveError = options.onSaveError;
|
|
79
|
+
this.addWidget(Private.defaultsEditor(defaults, this.translator));
|
|
80
|
+
this.addWidget(
|
|
81
|
+
Private.userEditor(user, this._toolbar, this._inspector, this.translator)
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The setting registry used by the editor.
|
|
87
|
+
*/
|
|
88
|
+
readonly registry: ISettingRegistry;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Whether the raw editor revert functionality is enabled.
|
|
92
|
+
*/
|
|
93
|
+
get canRevert(): boolean {
|
|
94
|
+
return this._canRevert;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Whether the raw editor save functionality is enabled.
|
|
99
|
+
*/
|
|
100
|
+
get canSave(): boolean {
|
|
101
|
+
return this._canSave;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Emits when the commands passed in at instantiation change.
|
|
106
|
+
*/
|
|
107
|
+
get commandsChanged(): ISignal<any, string[]> {
|
|
108
|
+
return this._commandsChanged;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Tests whether the settings have been modified and need saving.
|
|
113
|
+
*/
|
|
114
|
+
get isDirty(): boolean {
|
|
115
|
+
return (
|
|
116
|
+
this._user.editor.model.sharedModel.getSource() !== this._settings?.raw ??
|
|
117
|
+
''
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The plugin settings being edited.
|
|
123
|
+
*/
|
|
124
|
+
get settings(): ISettingRegistry.ISettings | null {
|
|
125
|
+
return this._settings;
|
|
126
|
+
}
|
|
127
|
+
set settings(settings: ISettingRegistry.ISettings | null) {
|
|
128
|
+
if (!settings && !this._settings) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const samePlugin =
|
|
133
|
+
settings && this._settings && settings.plugin === this._settings.plugin;
|
|
134
|
+
|
|
135
|
+
if (samePlugin) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const defaults = this._defaults;
|
|
140
|
+
const user = this._user;
|
|
141
|
+
|
|
142
|
+
// Disconnect old settings change handler.
|
|
143
|
+
if (this._settings) {
|
|
144
|
+
this._settings.changed.disconnect(this._onSettingsChanged, this);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (settings) {
|
|
148
|
+
this._settings = settings;
|
|
149
|
+
this._settings.changed.connect(this._onSettingsChanged, this);
|
|
150
|
+
this._onSettingsChanged();
|
|
151
|
+
} else {
|
|
152
|
+
this._settings = null;
|
|
153
|
+
defaults.editor.model.sharedModel.setSource('');
|
|
154
|
+
user.editor.model.sharedModel.setSource('');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
this.update();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Get the relative sizes of the two editor panels.
|
|
162
|
+
*/
|
|
163
|
+
get sizes(): number[] {
|
|
164
|
+
return this.relativeSizes();
|
|
165
|
+
}
|
|
166
|
+
set sizes(sizes: number[]) {
|
|
167
|
+
this.setRelativeSizes(sizes);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The inspectable source editor for user input.
|
|
172
|
+
*/
|
|
173
|
+
get source(): CodeEditor.IEditor {
|
|
174
|
+
return this._user.editor;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Dispose of the resources held by the raw editor.
|
|
179
|
+
*/
|
|
180
|
+
dispose(): void {
|
|
181
|
+
if (this.isDisposed) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
this._defaults.model.dispose();
|
|
186
|
+
this._defaults.dispose();
|
|
187
|
+
this._user.model.dispose();
|
|
188
|
+
this._user.dispose();
|
|
189
|
+
super.dispose();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Revert the editor back to original settings.
|
|
194
|
+
*/
|
|
195
|
+
revert(): void {
|
|
196
|
+
this._user.editor.model.sharedModel.setSource(this.settings?.raw ?? '');
|
|
197
|
+
this._updateToolbar(false, false);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Save the contents of the raw editor.
|
|
202
|
+
*/
|
|
203
|
+
save(): Promise<void> {
|
|
204
|
+
if (!this.isDirty || !this._settings) {
|
|
205
|
+
return Promise.resolve(undefined);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const settings = this._settings;
|
|
209
|
+
const source = this._user.editor.model.sharedModel.getSource();
|
|
210
|
+
|
|
211
|
+
return settings
|
|
212
|
+
.save(source)
|
|
213
|
+
.then(() => {
|
|
214
|
+
this._updateToolbar(false, false);
|
|
215
|
+
})
|
|
216
|
+
.catch(reason => {
|
|
217
|
+
this._updateToolbar(true, false);
|
|
218
|
+
this._onSaveError(reason, this.translator);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Handle `after-attach` messages.
|
|
224
|
+
*/
|
|
225
|
+
protected onAfterAttach(msg: Message): void {
|
|
226
|
+
Private.populateToolbar(this._commands, this._toolbar);
|
|
227
|
+
this.update();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Handle text changes in the underlying editor.
|
|
232
|
+
*/
|
|
233
|
+
private _onTextChanged(): void {
|
|
234
|
+
const raw = this._user.editor.model.sharedModel.getSource();
|
|
235
|
+
const settings = this._settings;
|
|
236
|
+
|
|
237
|
+
this.removeClass(ERROR_CLASS);
|
|
238
|
+
|
|
239
|
+
// If there are no settings loaded or there are no changes, bail.
|
|
240
|
+
if (!settings || settings.raw === raw) {
|
|
241
|
+
this._updateToolbar(false, false);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const errors = settings.validate(raw);
|
|
246
|
+
|
|
247
|
+
if (errors) {
|
|
248
|
+
this.addClass(ERROR_CLASS);
|
|
249
|
+
this._updateToolbar(true, false);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
this._updateToolbar(true, true);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Handle updates to the settings.
|
|
258
|
+
*/
|
|
259
|
+
private _onSettingsChanged(): void {
|
|
260
|
+
const settings = this._settings;
|
|
261
|
+
const defaults = this._defaults;
|
|
262
|
+
const user = this._user;
|
|
263
|
+
|
|
264
|
+
defaults.editor.model.sharedModel.setSource(
|
|
265
|
+
settings?.annotatedDefaults() ?? ''
|
|
266
|
+
);
|
|
267
|
+
user.editor.model.sharedModel.setSource(settings?.raw ?? '');
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private _updateToolbar(revert = this._canRevert, save = this._canSave): void {
|
|
271
|
+
const commands = this._commands;
|
|
272
|
+
|
|
273
|
+
this._canRevert = revert;
|
|
274
|
+
this._canSave = save;
|
|
275
|
+
this._commandsChanged.emit([commands.revert, commands.save]);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
protected translator: ITranslator;
|
|
279
|
+
private _canRevert = false;
|
|
280
|
+
private _canSave = false;
|
|
281
|
+
private _commands: RawEditor.ICommandBundle;
|
|
282
|
+
private _commandsChanged = new Signal<this, string[]>(this);
|
|
283
|
+
private _defaults: CodeEditorWrapper;
|
|
284
|
+
private _inspector: Widget;
|
|
285
|
+
private _onSaveError: (reason: any, translator?: ITranslator) => void;
|
|
286
|
+
private _settings: ISettingRegistry.ISettings | null = null;
|
|
287
|
+
private _toolbar = new Toolbar<Widget>();
|
|
288
|
+
private _user: CodeEditorWrapper;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* A namespace for `RawEditor` statics.
|
|
293
|
+
*/
|
|
294
|
+
export namespace RawEditor {
|
|
295
|
+
/**
|
|
296
|
+
* The toolbar commands and registry for the setting editor toolbar.
|
|
297
|
+
*/
|
|
298
|
+
export interface ICommandBundle {
|
|
299
|
+
/**
|
|
300
|
+
* The command registry.
|
|
301
|
+
*/
|
|
302
|
+
registry: CommandRegistry;
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* The revert command ID.
|
|
306
|
+
*/
|
|
307
|
+
revert: string;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* The save command ID.
|
|
311
|
+
*/
|
|
312
|
+
save: string;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The instantiation options for a raw editor.
|
|
317
|
+
*/
|
|
318
|
+
export interface IOptions {
|
|
319
|
+
/**
|
|
320
|
+
* The toolbar commands and registry for the setting editor toolbar.
|
|
321
|
+
*/
|
|
322
|
+
commands: ICommandBundle;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* The editor factory used by the raw editor.
|
|
326
|
+
*/
|
|
327
|
+
editorFactory: CodeEditor.Factory;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* A function the raw editor calls on save errors.
|
|
331
|
+
*/
|
|
332
|
+
onSaveError: (reason: any, translator?: ITranslator) => void;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* The setting registry used by the editor.
|
|
336
|
+
*/
|
|
337
|
+
registry: ISettingRegistry;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* The optional MIME renderer to use for rendering debug messages.
|
|
341
|
+
*/
|
|
342
|
+
rendermime?: IRenderMimeRegistry;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* The application language translator.
|
|
346
|
+
*/
|
|
347
|
+
translator?: ITranslator;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* A namespace for private module data.
|
|
353
|
+
*/
|
|
354
|
+
namespace Private {
|
|
355
|
+
/**
|
|
356
|
+
* Returns the wrapped setting defaults editor.
|
|
357
|
+
*/
|
|
358
|
+
export function defaultsEditor(
|
|
359
|
+
editor: Widget,
|
|
360
|
+
translator?: ITranslator
|
|
361
|
+
): Widget {
|
|
362
|
+
translator = translator || nullTranslator;
|
|
363
|
+
const trans = translator.load('jupyterlab');
|
|
364
|
+
const widget = new Widget();
|
|
365
|
+
const layout = (widget.layout = new BoxLayout({ spacing: 0 }));
|
|
366
|
+
const banner = new Widget();
|
|
367
|
+
const bar = new Toolbar();
|
|
368
|
+
const defaultTitle = trans.__('System Defaults');
|
|
369
|
+
|
|
370
|
+
banner.node.innerText = defaultTitle;
|
|
371
|
+
bar.insertItem(0, 'banner', banner);
|
|
372
|
+
layout.addWidget(bar);
|
|
373
|
+
layout.addWidget(editor);
|
|
374
|
+
|
|
375
|
+
return widget;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Populate the raw editor toolbar.
|
|
380
|
+
*/
|
|
381
|
+
export function populateToolbar(
|
|
382
|
+
commands: RawEditor.ICommandBundle,
|
|
383
|
+
toolbar: Toolbar<Widget>
|
|
384
|
+
): void {
|
|
385
|
+
const { registry, revert, save } = commands;
|
|
386
|
+
|
|
387
|
+
toolbar.addItem('spacer', Toolbar.createSpacerItem());
|
|
388
|
+
|
|
389
|
+
// Note the button order. The rationale here is that no matter what state
|
|
390
|
+
// the toolbar is in, the relative location of the revert button in the
|
|
391
|
+
// toolbar remains the same.
|
|
392
|
+
[revert, save].forEach(name => {
|
|
393
|
+
const item = new CommandToolbarButton({ commands: registry, id: name });
|
|
394
|
+
toolbar.addItem(name, item);
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Returns the wrapped user overrides editor.
|
|
400
|
+
*/
|
|
401
|
+
export function userEditor(
|
|
402
|
+
editor: Widget,
|
|
403
|
+
toolbar: Toolbar<Widget>,
|
|
404
|
+
inspector: Widget,
|
|
405
|
+
translator?: ITranslator
|
|
406
|
+
): Widget {
|
|
407
|
+
translator = translator || nullTranslator;
|
|
408
|
+
const trans = translator.load('jupyterlab');
|
|
409
|
+
const userTitle = trans.__('User Preferences');
|
|
410
|
+
const widget = new Widget();
|
|
411
|
+
const layout = (widget.layout = new BoxLayout({ spacing: 0 }));
|
|
412
|
+
const banner = new Widget();
|
|
413
|
+
|
|
414
|
+
banner.node.innerText = userTitle;
|
|
415
|
+
toolbar.insertItem(0, 'banner', banner);
|
|
416
|
+
layout.addWidget(toolbar);
|
|
417
|
+
layout.addWidget(editor);
|
|
418
|
+
layout.addWidget(inspector);
|
|
419
|
+
|
|
420
|
+
return widget;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Jupyter Development Team.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ILabStatus } from '@jupyterlab/application';
|
|
7
|
+
import { showDialog } from '@jupyterlab/apputils';
|
|
8
|
+
import { ISettingRegistry, Settings } from '@jupyterlab/settingregistry';
|
|
9
|
+
import { IStateDB } from '@jupyterlab/statedb';
|
|
10
|
+
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
|
|
11
|
+
import { IFormRendererRegistry, ReactWidget } from '@jupyterlab/ui-components';
|
|
12
|
+
import { CommandRegistry } from '@lumino/commands';
|
|
13
|
+
import { IDisposable } from '@lumino/disposable';
|
|
14
|
+
import { Message } from '@lumino/messaging';
|
|
15
|
+
import { ISignal, Signal } from '@lumino/signaling';
|
|
16
|
+
import { SplitPanel } from '@lumino/widgets';
|
|
17
|
+
import React from 'react';
|
|
18
|
+
import { PluginList } from './pluginlist';
|
|
19
|
+
import { SettingsPanel } from './settingspanel';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Form based interface for editing settings.
|
|
23
|
+
*/
|
|
24
|
+
export class SettingsEditor extends SplitPanel {
|
|
25
|
+
constructor(options: SettingsEditor.IOptions) {
|
|
26
|
+
super({
|
|
27
|
+
orientation: 'horizontal',
|
|
28
|
+
renderer: SplitPanel.defaultRenderer,
|
|
29
|
+
spacing: 1
|
|
30
|
+
});
|
|
31
|
+
this.translator = options.translator || nullTranslator;
|
|
32
|
+
this._status = options.status;
|
|
33
|
+
const list = (this._list = new PluginList({
|
|
34
|
+
registry: options.registry,
|
|
35
|
+
toSkip: options.toSkip,
|
|
36
|
+
translator: this.translator,
|
|
37
|
+
query: options.query
|
|
38
|
+
}));
|
|
39
|
+
this.addWidget(list);
|
|
40
|
+
this.setDirtyState = this.setDirtyState.bind(this);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Initializes the settings panel after loading the schema for all plugins.
|
|
44
|
+
*/
|
|
45
|
+
void Promise.all(
|
|
46
|
+
PluginList.sortPlugins(options.registry)
|
|
47
|
+
.filter(plugin => {
|
|
48
|
+
const { schema } = plugin;
|
|
49
|
+
const deprecated = schema['jupyter.lab.setting-deprecated'] === true;
|
|
50
|
+
const editable = Object.keys(schema.properties || {}).length > 0;
|
|
51
|
+
const extensible = schema.additionalProperties !== false;
|
|
52
|
+
|
|
53
|
+
return !deprecated && (editable || extensible);
|
|
54
|
+
})
|
|
55
|
+
.map(async plugin => await options.registry.load(plugin.id))
|
|
56
|
+
)
|
|
57
|
+
.then(settings => {
|
|
58
|
+
const settingsPanel = ReactWidget.create(
|
|
59
|
+
<SettingsPanel
|
|
60
|
+
settings={
|
|
61
|
+
settings.filter(
|
|
62
|
+
pluginSettings =>
|
|
63
|
+
!(options.toSkip ?? []).includes(pluginSettings.id)
|
|
64
|
+
) as Settings[]
|
|
65
|
+
}
|
|
66
|
+
editorRegistry={options.editorRegistry}
|
|
67
|
+
handleSelectSignal={this._list.handleSelectSignal}
|
|
68
|
+
onSelect={(id: string) => (this._list.selection = id)}
|
|
69
|
+
hasError={this._list.setError}
|
|
70
|
+
updateFilterSignal={this._list.updateFilterSignal}
|
|
71
|
+
updateDirtyState={this.setDirtyState}
|
|
72
|
+
translator={this.translator}
|
|
73
|
+
initialFilter={this._list.filter}
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
this.addWidget(settingsPanel);
|
|
77
|
+
})
|
|
78
|
+
.catch(reason => {
|
|
79
|
+
console.error(`Fail to load the setting plugins:\n${reason}`);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A signal emitted on the start and end of a saving operation.
|
|
85
|
+
*/
|
|
86
|
+
get saveStateChanged(): ISignal<this, SettingsEditor.SaveState> {
|
|
87
|
+
return this._saveStateChange;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Set the dirty state status
|
|
92
|
+
*
|
|
93
|
+
* @param dirty New status
|
|
94
|
+
*/
|
|
95
|
+
setDirtyState(dirty: boolean): void {
|
|
96
|
+
this._dirty = dirty;
|
|
97
|
+
if (this._dirty && !this._clearDirty) {
|
|
98
|
+
this._clearDirty = this._status.setDirty();
|
|
99
|
+
} else if (!this._dirty && this._clearDirty) {
|
|
100
|
+
this._clearDirty.dispose();
|
|
101
|
+
this._clearDirty = null;
|
|
102
|
+
}
|
|
103
|
+
if (dirty) {
|
|
104
|
+
if (!this.title.className.includes('jp-mod-dirty')) {
|
|
105
|
+
this.title.className += ' jp-mod-dirty';
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
this.title.className = this.title.className.replace('jp-mod-dirty', '');
|
|
109
|
+
}
|
|
110
|
+
this._saveStateChange.emit(dirty ? 'started' : 'completed');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* A message handler invoked on a `'close-request'` message.
|
|
115
|
+
*
|
|
116
|
+
* @param msg Widget message
|
|
117
|
+
*/
|
|
118
|
+
protected onCloseRequest(msg: Message): void {
|
|
119
|
+
const trans = this.translator.load('jupyterlab');
|
|
120
|
+
if (this._list.hasErrors) {
|
|
121
|
+
void showDialog({
|
|
122
|
+
title: trans.__('Warning'),
|
|
123
|
+
body: trans.__(
|
|
124
|
+
'Unsaved changes due to validation error. Continue without saving?'
|
|
125
|
+
)
|
|
126
|
+
}).then(value => {
|
|
127
|
+
if (value.button.accept) {
|
|
128
|
+
this.dispose();
|
|
129
|
+
super.onCloseRequest(msg);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
} else if (this._dirty) {
|
|
133
|
+
void showDialog({
|
|
134
|
+
title: trans.__('Warning'),
|
|
135
|
+
body: trans.__(
|
|
136
|
+
'Some changes have not been saved. Continue without saving?'
|
|
137
|
+
)
|
|
138
|
+
}).then(value => {
|
|
139
|
+
if (value.button.accept) {
|
|
140
|
+
this.dispose();
|
|
141
|
+
super.onCloseRequest(msg);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
} else {
|
|
145
|
+
this.dispose();
|
|
146
|
+
super.onCloseRequest(msg);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
protected translator: ITranslator;
|
|
151
|
+
private _clearDirty: IDisposable | null = null;
|
|
152
|
+
private _status: ILabStatus;
|
|
153
|
+
private _dirty: boolean = false;
|
|
154
|
+
private _list: PluginList;
|
|
155
|
+
private _saveStateChange = new Signal<this, SettingsEditor.SaveState>(this);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export namespace SettingsEditor {
|
|
159
|
+
/**
|
|
160
|
+
* Settings editor save state
|
|
161
|
+
*/
|
|
162
|
+
export type SaveState = 'started' | 'failed' | 'completed';
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Settings editor options
|
|
166
|
+
*/
|
|
167
|
+
export interface IOptions {
|
|
168
|
+
/**
|
|
169
|
+
* Form component registry
|
|
170
|
+
*/
|
|
171
|
+
editorRegistry: IFormRendererRegistry;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The state database key for the editor's state management.
|
|
175
|
+
*/
|
|
176
|
+
key: string;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* The setting registry the editor modifies.
|
|
180
|
+
*/
|
|
181
|
+
registry: ISettingRegistry;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The state database used to store layout.
|
|
185
|
+
*/
|
|
186
|
+
state: IStateDB;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Command registry used to open the JSON settings editor.
|
|
190
|
+
*/
|
|
191
|
+
commands: CommandRegistry;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Application status
|
|
195
|
+
*/
|
|
196
|
+
status: ILabStatus;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* List of plugins to skip
|
|
200
|
+
*/
|
|
201
|
+
toSkip?: string[];
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The application language translator.
|
|
205
|
+
*/
|
|
206
|
+
translator?: ITranslator;
|
|
207
|
+
|
|
208
|
+
query?: string;
|
|
209
|
+
}
|
|
210
|
+
}
|