@jupyterlab/settingeditor-extension 4.0.0-alpha.19 → 4.0.0-alpha.20

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.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @packageDocumentation
3
3
  * @module settingeditor-extension
4
4
  */
5
- import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application';
5
+ import { JupyterFrontEndPlugin } from '@jupyterlab/application';
6
6
  import { IJSONSettingEditorTracker, ISettingEditorTracker } from '@jupyterlab/settingeditor/lib/tokens';
7
- declare const _default: (JupyterFrontEndPlugin<ISettingEditorTracker, JupyterFrontEnd.IShell, "desktop" | "mobile"> | JupyterFrontEndPlugin<IJSONSettingEditorTracker, JupyterFrontEnd.IShell, "desktop" | "mobile">)[];
7
+ declare const _default: (JupyterFrontEndPlugin<ISettingEditorTracker> | JupyterFrontEndPlugin<IJSONSettingEditorTracker>)[];
8
8
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlab/settingeditor-extension",
3
- "version": "4.0.0-alpha.19",
3
+ "version": "4.0.0-alpha.20",
4
4
  "description": "JupyterLab - Setting Editor Extension",
5
5
  "homepage": "https://github.com/jupyterlab/jupyterlab",
6
6
  "bugs": {
@@ -28,7 +28,8 @@
28
28
  "lib/*.js",
29
29
  "schema/*.json",
30
30
  "style/**/*.css",
31
- "style/index.js"
31
+ "style/index.js",
32
+ "src/**/*.{ts,tsx}"
32
33
  ],
33
34
  "scripts": {
34
35
  "build": "tsc -b",
@@ -37,21 +38,21 @@
37
38
  "watch": "tsc -b --watch"
38
39
  },
39
40
  "dependencies": {
40
- "@jupyterlab/application": "^4.0.0-alpha.19",
41
- "@jupyterlab/apputils": "^4.0.0-alpha.19",
42
- "@jupyterlab/codeeditor": "^4.0.0-alpha.19",
43
- "@jupyterlab/rendermime": "^4.0.0-alpha.19",
44
- "@jupyterlab/settingeditor": "^4.0.0-alpha.19",
45
- "@jupyterlab/settingregistry": "^4.0.0-alpha.19",
46
- "@jupyterlab/statedb": "^4.0.0-alpha.19",
47
- "@jupyterlab/translation": "^4.0.0-alpha.19",
48
- "@jupyterlab/ui-components": "^4.0.0-alpha.34",
49
- "@lumino/disposable": "^2.0.0-beta.1"
41
+ "@jupyterlab/application": "^4.0.0-alpha.20",
42
+ "@jupyterlab/apputils": "^4.0.0-alpha.20",
43
+ "@jupyterlab/codeeditor": "^4.0.0-alpha.20",
44
+ "@jupyterlab/rendermime": "^4.0.0-alpha.20",
45
+ "@jupyterlab/settingeditor": "^4.0.0-alpha.20",
46
+ "@jupyterlab/settingregistry": "^4.0.0-alpha.20",
47
+ "@jupyterlab/statedb": "^4.0.0-alpha.20",
48
+ "@jupyterlab/translation": "^4.0.0-alpha.20",
49
+ "@jupyterlab/ui-components": "^4.0.0-alpha.35",
50
+ "@lumino/disposable": "^2.0.0-rc.0"
50
51
  },
51
52
  "devDependencies": {
52
53
  "rimraf": "~3.0.0",
53
- "typedoc": "~0.22.10",
54
- "typescript": "~4.7.3"
54
+ "typedoc": "~0.23.25",
55
+ "typescript": "~5.0.0-beta"
55
56
  },
56
57
  "publishConfig": {
57
58
  "access": "public"
package/src/index.ts ADDED
@@ -0,0 +1,341 @@
1
+ /* -----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+ /**
6
+ * @packageDocumentation
7
+ * @module settingeditor-extension
8
+ */
9
+
10
+ import {
11
+ ILabStatus,
12
+ ILayoutRestorer,
13
+ JupyterFrontEnd,
14
+ JupyterFrontEndPlugin
15
+ } from '@jupyterlab/application';
16
+ import {
17
+ ICommandPalette,
18
+ MainAreaWidget,
19
+ WidgetTracker
20
+ } from '@jupyterlab/apputils';
21
+ import { IEditorServices } from '@jupyterlab/codeeditor';
22
+ import {
23
+ CommandToolbarButton,
24
+ IFormRendererRegistry,
25
+ launchIcon,
26
+ Toolbar
27
+ } from '@jupyterlab/ui-components';
28
+ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
29
+ import {
30
+ IJSONSettingEditorTracker,
31
+ ISettingEditorTracker
32
+ } from '@jupyterlab/settingeditor/lib/tokens';
33
+ import type {
34
+ JsonSettingEditor,
35
+ SettingsEditor
36
+ } from '@jupyterlab/settingeditor';
37
+ import { ISettingRegistry } from '@jupyterlab/settingregistry';
38
+ import { IStateDB } from '@jupyterlab/statedb';
39
+ import { ITranslator } from '@jupyterlab/translation';
40
+ import { saveIcon, settingsIcon, undoIcon } from '@jupyterlab/ui-components';
41
+ import { IDisposable } from '@lumino/disposable';
42
+
43
+ /**
44
+ * The command IDs used by the setting editor.
45
+ */
46
+ namespace CommandIDs {
47
+ export const open = 'settingeditor:open';
48
+
49
+ export const openJSON = 'settingeditor:open-json';
50
+
51
+ export const revert = 'settingeditor:revert';
52
+
53
+ export const save = 'settingeditor:save';
54
+ }
55
+
56
+ type SettingEditorType = 'ui' | 'json';
57
+
58
+ /**
59
+ * The default setting editor extension.
60
+ */
61
+ const plugin: JupyterFrontEndPlugin<ISettingEditorTracker> = {
62
+ id: '@jupyterlab/settingeditor-extension:form-ui',
63
+ requires: [
64
+ ISettingRegistry,
65
+ IStateDB,
66
+ ITranslator,
67
+ IFormRendererRegistry,
68
+ ILabStatus
69
+ ],
70
+ optional: [ILayoutRestorer, ICommandPalette, IJSONSettingEditorTracker],
71
+ autoStart: true,
72
+ provides: ISettingEditorTracker,
73
+ activate
74
+ };
75
+
76
+ /**
77
+ * Activate the setting editor extension.
78
+ */
79
+ function activate(
80
+ app: JupyterFrontEnd,
81
+ registry: ISettingRegistry,
82
+ state: IStateDB,
83
+ translator: ITranslator,
84
+ editorRegistry: IFormRendererRegistry,
85
+ status: ILabStatus,
86
+ restorer: ILayoutRestorer | null,
87
+ palette: ICommandPalette | null,
88
+ jsonEditor: IJSONSettingEditorTracker | null
89
+ ): ISettingEditorTracker {
90
+ const trans = translator.load('jupyterlab');
91
+ const { commands, shell } = app;
92
+ const namespace = 'setting-editor';
93
+ const tracker = new WidgetTracker<MainAreaWidget<SettingsEditor>>({
94
+ namespace
95
+ });
96
+
97
+ // Handle state restoration.
98
+ if (restorer) {
99
+ void restorer.restore(tracker, {
100
+ command: CommandIDs.open,
101
+ args: widget => ({}),
102
+ name: widget => namespace
103
+ });
104
+ }
105
+
106
+ const openUi = async (args: { query: string }) => {
107
+ if (tracker.currentWidget && !tracker.currentWidget.isDisposed) {
108
+ if (!tracker.currentWidget.isAttached) {
109
+ shell.add(tracker.currentWidget, 'main', { type: 'Settings' });
110
+ }
111
+ shell.activateById(tracker.currentWidget.id);
112
+ return;
113
+ }
114
+
115
+ const key = plugin.id;
116
+
117
+ const { SettingsEditor } = await import('@jupyterlab/settingeditor');
118
+
119
+ const editor = new MainAreaWidget<SettingsEditor>({
120
+ content: new SettingsEditor({
121
+ editorRegistry,
122
+ key,
123
+ registry,
124
+ state,
125
+ commands,
126
+ toSkip: [
127
+ '@jupyterlab/application-extension:context-menu',
128
+ '@jupyterlab/mainmenu-extension:plugin'
129
+ ],
130
+ translator,
131
+ status,
132
+ query: args.query as string
133
+ })
134
+ });
135
+
136
+ if (jsonEditor) {
137
+ editor.toolbar.addItem('spacer', Toolbar.createSpacerItem());
138
+ editor.toolbar.addItem(
139
+ 'open-json-editor',
140
+ new CommandToolbarButton({
141
+ commands,
142
+ id: CommandIDs.openJSON,
143
+ icon: launchIcon,
144
+ label: trans.__('JSON Settings Editor')
145
+ })
146
+ );
147
+ }
148
+
149
+ editor.id = namespace;
150
+ editor.title.icon = settingsIcon;
151
+ editor.title.label = trans.__('Settings');
152
+ editor.title.closable = true;
153
+
154
+ void tracker.add(editor);
155
+ shell.add(editor, 'main', { type: 'Settings' });
156
+ };
157
+
158
+ commands.addCommand(CommandIDs.open, {
159
+ execute: async (args: {
160
+ query?: string;
161
+ settingEditorType?: SettingEditorType;
162
+ }) => {
163
+ if (args.settingEditorType === 'ui') {
164
+ void commands.execute(CommandIDs.open, { query: args.query ?? '' });
165
+ } else if (args.settingEditorType === 'json') {
166
+ void commands.execute(CommandIDs.openJSON);
167
+ } else {
168
+ void registry.load(plugin.id).then(settings => {
169
+ (settings.get('settingEditorType').composite as SettingEditorType) ===
170
+ 'json'
171
+ ? void commands.execute(CommandIDs.openJSON)
172
+ : void openUi({ query: args.query ?? '' });
173
+ });
174
+ }
175
+ },
176
+ label: args => {
177
+ if (args.label) {
178
+ return args.label as string;
179
+ }
180
+ return trans.__('Settings Editor');
181
+ }
182
+ });
183
+
184
+ if (palette) {
185
+ palette.addItem({
186
+ category: trans.__('Settings'),
187
+ command: CommandIDs.open,
188
+ args: { settingEditorType: 'ui' }
189
+ });
190
+ }
191
+
192
+ return tracker;
193
+ }
194
+
195
+ /**
196
+ * The default setting editor extension.
197
+ */
198
+ const jsonPlugin: JupyterFrontEndPlugin<IJSONSettingEditorTracker> = {
199
+ id: '@jupyterlab/settingeditor-extension:plugin',
200
+ requires: [
201
+ ISettingRegistry,
202
+ IEditorServices,
203
+ IStateDB,
204
+ IRenderMimeRegistry,
205
+ ILabStatus,
206
+ ITranslator
207
+ ],
208
+ optional: [ILayoutRestorer, ICommandPalette],
209
+ autoStart: true,
210
+ provides: IJSONSettingEditorTracker,
211
+ activate: activateJSON
212
+ };
213
+
214
+ /**
215
+ * Activate the setting editor extension.
216
+ */
217
+ function activateJSON(
218
+ app: JupyterFrontEnd,
219
+ registry: ISettingRegistry,
220
+ editorServices: IEditorServices,
221
+ state: IStateDB,
222
+ rendermime: IRenderMimeRegistry,
223
+ status: ILabStatus,
224
+ translator: ITranslator,
225
+ restorer: ILayoutRestorer | null,
226
+ palette: ICommandPalette | null
227
+ ): IJSONSettingEditorTracker {
228
+ const trans = translator.load('jupyterlab');
229
+ const { commands, shell } = app;
230
+ const namespace = 'json-setting-editor';
231
+ const factoryService = editorServices.factoryService;
232
+ const editorFactory = factoryService.newInlineEditor;
233
+ const tracker = new WidgetTracker<MainAreaWidget<JsonSettingEditor>>({
234
+ namespace
235
+ });
236
+
237
+ // Handle state restoration.
238
+ if (restorer) {
239
+ void restorer.restore(tracker, {
240
+ command: CommandIDs.openJSON,
241
+ args: widget => ({}),
242
+ name: widget => namespace
243
+ });
244
+ }
245
+
246
+ commands.addCommand(CommandIDs.openJSON, {
247
+ execute: async () => {
248
+ if (tracker.currentWidget && !tracker.currentWidget.isDisposed) {
249
+ if (!tracker.currentWidget.isAttached) {
250
+ shell.add(tracker.currentWidget, 'main', {
251
+ type: 'Advanced Settings'
252
+ });
253
+ }
254
+ shell.activateById(tracker.currentWidget.id);
255
+ return;
256
+ }
257
+
258
+ const key = plugin.id;
259
+ const when = app.restored;
260
+
261
+ const { JsonSettingEditor } = await import('@jupyterlab/settingeditor');
262
+
263
+ const editor = new JsonSettingEditor({
264
+ commands: {
265
+ registry: commands,
266
+ revert: CommandIDs.revert,
267
+ save: CommandIDs.save
268
+ },
269
+ editorFactory,
270
+ key,
271
+ registry,
272
+ rendermime,
273
+ state,
274
+ translator,
275
+ when
276
+ });
277
+
278
+ let disposable: IDisposable | null = null;
279
+ // Notify the command registry when the visibility status of the setting
280
+ // editor's commands change. The setting editor toolbar listens for this
281
+ // signal from the command registry.
282
+ editor.commandsChanged.connect((sender: any, args: string[]) => {
283
+ args.forEach(id => {
284
+ commands.notifyCommandChanged(id);
285
+ });
286
+ if (editor.canSaveRaw) {
287
+ if (!disposable) {
288
+ disposable = status.setDirty();
289
+ }
290
+ } else if (disposable) {
291
+ disposable.dispose();
292
+ disposable = null;
293
+ }
294
+ editor.disposed.connect(() => {
295
+ if (disposable) {
296
+ disposable.dispose();
297
+ }
298
+ });
299
+ });
300
+
301
+ const container = new MainAreaWidget<JsonSettingEditor>({
302
+ content: editor
303
+ });
304
+
305
+ container.id = namespace;
306
+ container.title.icon = settingsIcon;
307
+ container.title.label = trans.__('Advanced Settings Editor');
308
+ container.title.closable = true;
309
+
310
+ void tracker.add(container);
311
+ shell.add(container, 'main', { type: 'Advanced Settings' });
312
+ },
313
+ label: trans.__('Advanced Settings Editor')
314
+ });
315
+ if (palette) {
316
+ palette.addItem({
317
+ category: trans.__('Settings'),
318
+ command: CommandIDs.openJSON
319
+ });
320
+ }
321
+
322
+ commands.addCommand(CommandIDs.revert, {
323
+ execute: () => {
324
+ tracker.currentWidget?.content.revert();
325
+ },
326
+ icon: undoIcon,
327
+ label: trans.__('Revert User Settings'),
328
+ isEnabled: () => tracker.currentWidget?.content.canRevertRaw ?? false
329
+ });
330
+
331
+ commands.addCommand(CommandIDs.save, {
332
+ execute: () => tracker.currentWidget?.content.save(),
333
+ icon: saveIcon,
334
+ label: trans.__('Save User Settings'),
335
+ isEnabled: () => tracker.currentWidget?.content.canSaveRaw ?? false
336
+ });
337
+
338
+ return tracker;
339
+ }
340
+
341
+ export default [plugin, jsonPlugin];