@jupyterlab/settingregistry 4.0.0-alpha.9 → 4.0.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/src/tokens.ts ADDED
@@ -0,0 +1,776 @@
1
+ /* -----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ import { CellType } from '@jupyterlab/nbformat';
7
+ import { IDataConnector } from '@jupyterlab/statedb';
8
+ import {
9
+ PartialJSONObject,
10
+ PartialJSONValue,
11
+ ReadonlyPartialJSONObject,
12
+ ReadonlyPartialJSONValue,
13
+ Token
14
+ } from '@lumino/coreutils';
15
+ import { IDisposable } from '@lumino/disposable';
16
+ import { ISignal } from '@lumino/signaling';
17
+ import { ISchemaValidator } from './settingregistry';
18
+ import type { RJSFSchema, UiSchema } from '@rjsf/utils';
19
+
20
+ /**
21
+ * The setting registry token.
22
+ */
23
+ export const ISettingRegistry = new Token<ISettingRegistry>(
24
+ '@jupyterlab/coreutils:ISettingRegistry'
25
+ );
26
+
27
+ /**
28
+ * The settings registry interface.
29
+ */
30
+ export interface ISettingRegistry {
31
+ /**
32
+ * The data connector used by the setting registry.
33
+ */
34
+ readonly connector: IDataConnector<ISettingRegistry.IPlugin, string, string>;
35
+
36
+ /**
37
+ * The schema of the setting registry.
38
+ */
39
+ readonly schema: ISettingRegistry.ISchema;
40
+
41
+ /**
42
+ * The schema validator used by the setting registry.
43
+ */
44
+ readonly validator: ISchemaValidator;
45
+
46
+ /**
47
+ * A signal that emits the name of a plugin when its settings change.
48
+ */
49
+ readonly pluginChanged: ISignal<this, string>;
50
+
51
+ /**
52
+ * The collection of setting registry plugins.
53
+ */
54
+ readonly plugins: {
55
+ [name: string]: ISettingRegistry.IPlugin | undefined;
56
+ };
57
+
58
+ /**
59
+ * Get an individual setting.
60
+ *
61
+ * @param plugin - The name of the plugin whose settings are being retrieved.
62
+ *
63
+ * @param key - The name of the setting being retrieved.
64
+ *
65
+ * @returns A promise that resolves when the setting is retrieved.
66
+ */
67
+ get(
68
+ plugin: string,
69
+ key: string
70
+ ): Promise<{
71
+ composite: PartialJSONValue | undefined;
72
+ user: PartialJSONValue | undefined;
73
+ }>;
74
+
75
+ /**
76
+ * Load a plugin's settings into the setting registry.
77
+ *
78
+ * @param plugin - The name of the plugin whose settings are being loaded.
79
+ *
80
+ * @param forceTransform - An optional parameter to force replay the transforms methods.
81
+ *
82
+ * @returns A promise that resolves with a plugin settings object or rejects
83
+ * if the plugin is not found.
84
+ */
85
+ load(
86
+ plugin: string,
87
+ forceTransform?: boolean
88
+ ): Promise<ISettingRegistry.ISettings>;
89
+
90
+ /**
91
+ * Reload a plugin's settings into the registry even if they already exist.
92
+ *
93
+ * @param plugin - The name of the plugin whose settings are being reloaded.
94
+ *
95
+ * @returns A promise that resolves with a plugin settings object or rejects
96
+ * with a list of `ISchemaValidator.IError` objects if it fails.
97
+ */
98
+ reload(plugin: string): Promise<ISettingRegistry.ISettings>;
99
+
100
+ /**
101
+ * Remove a single setting in the registry.
102
+ *
103
+ * @param plugin - The name of the plugin whose setting is being removed.
104
+ *
105
+ * @param key - The name of the setting being removed.
106
+ *
107
+ * @returns A promise that resolves when the setting is removed.
108
+ */
109
+ remove(plugin: string, key: string): Promise<void>;
110
+
111
+ /**
112
+ * Set a single setting in the registry.
113
+ *
114
+ * @param plugin - The name of the plugin whose setting is being set.
115
+ *
116
+ * @param key - The name of the setting being set.
117
+ *
118
+ * @param value - The value of the setting being set.
119
+ *
120
+ * @returns A promise that resolves when the setting has been saved.
121
+ *
122
+ */
123
+ set(plugin: string, key: string, value: PartialJSONValue): Promise<void>;
124
+
125
+ /**
126
+ * Register a plugin transform function to act on a specific plugin.
127
+ *
128
+ * @param plugin - The name of the plugin whose settings are transformed.
129
+ *
130
+ * @param transforms - The transform functions applied to the plugin.
131
+ *
132
+ * @returns A disposable that removes the transforms from the registry.
133
+ *
134
+ * #### Notes
135
+ * - `compose` transformations: The registry automatically overwrites a
136
+ * plugin's default values with user overrides, but a plugin may instead wish
137
+ * to merge values. This behavior can be accomplished in a `compose`
138
+ * transformation.
139
+ * - `fetch` transformations: The registry uses the plugin data that is
140
+ * fetched from its connector. If a plugin wants to override, e.g. to update
141
+ * its schema with dynamic defaults, a `fetch` transformation can be applied.
142
+ */
143
+ transform(
144
+ plugin: string,
145
+ transforms: {
146
+ [phase in ISettingRegistry.IPlugin.Phase]?: ISettingRegistry.IPlugin.Transform;
147
+ }
148
+ ): IDisposable;
149
+
150
+ /**
151
+ * Upload a plugin's settings.
152
+ *
153
+ * @param plugin - The name of the plugin whose settings are being set.
154
+ *
155
+ * @param raw - The raw plugin settings being uploaded.
156
+ *
157
+ * @returns A promise that resolves when the settings have been saved.
158
+ */
159
+ upload(plugin: string, raw: string): Promise<void>;
160
+ }
161
+
162
+ /**
163
+ * A namespace for setting registry interfaces.
164
+ */
165
+ export namespace ISettingRegistry {
166
+ /**
167
+ * The primitive types available in a JSON schema.
168
+ */
169
+ export type Primitive =
170
+ | 'array'
171
+ | 'boolean'
172
+ | 'null'
173
+ | 'number'
174
+ | 'object'
175
+ | 'string';
176
+
177
+ /**
178
+ * The menu ids defined by default.
179
+ */
180
+ export type DefaultMenuId =
181
+ | 'jp-menu-file'
182
+ | 'jp-menu-file-new'
183
+ | 'jp-menu-edit'
184
+ | 'jp-menu-help'
185
+ | 'jp-menu-kernel'
186
+ | 'jp-menu-run'
187
+ | 'jp-menu-settings'
188
+ | 'jp-menu-view'
189
+ | 'jp-menu-tabs';
190
+
191
+ /**
192
+ * An interface defining a menu.
193
+ */
194
+ export interface IMenu extends PartialJSONObject {
195
+ /**
196
+ * Unique menu identifier
197
+ */
198
+ id: DefaultMenuId | string;
199
+
200
+ /**
201
+ * Menu items
202
+ */
203
+ items?: IMenuItem[];
204
+
205
+ /**
206
+ * The rank order of the menu among its siblings.
207
+ */
208
+ rank?: number;
209
+
210
+ /**
211
+ * Menu title
212
+ *
213
+ * #### Notes
214
+ * Default will be the capitalized id.
215
+ */
216
+ label?: string;
217
+
218
+ /**
219
+ * Menu icon id
220
+ *
221
+ * #### Note
222
+ * The icon id will looked for in registered LabIcon.
223
+ */
224
+ icon?: string;
225
+
226
+ /**
227
+ * Get the mnemonic index for the title.
228
+ *
229
+ * #### Notes
230
+ * The default value is `-1`.
231
+ */
232
+ mnemonic?: number;
233
+
234
+ /**
235
+ * Whether a menu is disabled. `False` by default.
236
+ *
237
+ * #### Notes
238
+ * This allows an user to suppress a menu.
239
+ */
240
+ disabled?: boolean;
241
+ }
242
+
243
+ /**
244
+ * An interface describing a menu item.
245
+ */
246
+ export interface IMenuItem extends PartialJSONObject {
247
+ /**
248
+ * The type of the menu item.
249
+ *
250
+ * The default value is `'command'`.
251
+ */
252
+ type?: 'command' | 'submenu' | 'separator';
253
+
254
+ /**
255
+ * The command to execute when the item is triggered.
256
+ *
257
+ * The default value is an empty string.
258
+ */
259
+ command?: string;
260
+
261
+ /**
262
+ * The arguments for the command.
263
+ *
264
+ * The default value is an empty object.
265
+ */
266
+ args?: PartialJSONObject;
267
+
268
+ /**
269
+ * The rank order of the menu item among its siblings.
270
+ */
271
+ rank?: number;
272
+
273
+ /**
274
+ * The submenu for a `'submenu'` type item.
275
+ *
276
+ * The default value is `null`.
277
+ */
278
+ submenu?: IMenu | null;
279
+
280
+ /**
281
+ * Whether a menu item is disabled. `false` by default.
282
+ *
283
+ * #### Notes
284
+ * This allows an user to suppress menu items.
285
+ */
286
+ disabled?: boolean;
287
+ }
288
+
289
+ /**
290
+ * An interface describing a context menu item
291
+ */
292
+ export interface IContextMenuItem extends IMenuItem {
293
+ /**
294
+ * The CSS selector for the context menu item.
295
+ *
296
+ * The context menu item will only be displayed in the context menu
297
+ * when the selector matches a node on the propagation path of the
298
+ * contextmenu event. This allows the menu item to be restricted to
299
+ * user-defined contexts.
300
+ *
301
+ * The selector must not contain commas.
302
+ */
303
+ selector: string;
304
+ }
305
+
306
+ /**
307
+ * The settings for a specific plugin.
308
+ */
309
+ export interface IPlugin extends PartialJSONObject {
310
+ /**
311
+ * The name of the plugin.
312
+ */
313
+ id: string;
314
+
315
+ /**
316
+ * The collection of values for a specified plugin.
317
+ */
318
+ data: ISettingBundle;
319
+
320
+ /**
321
+ * The raw user settings data as a string containing JSON with comments.
322
+ */
323
+ raw: string;
324
+
325
+ /**
326
+ * The JSON schema for the plugin.
327
+ */
328
+ schema: ISchema;
329
+
330
+ /**
331
+ * The published version of the NPM package containing the plugin.
332
+ */
333
+ version: string;
334
+ }
335
+
336
+ /**
337
+ * A namespace for plugin functionality.
338
+ */
339
+ export namespace IPlugin {
340
+ /**
341
+ * A function that transforms a plugin object before it is consumed by the
342
+ * setting registry.
343
+ */
344
+ export type Transform = (plugin: IPlugin) => IPlugin;
345
+
346
+ /**
347
+ * The phases during which a transformation may be applied to a plugin.
348
+ */
349
+ export type Phase = 'compose' | 'fetch';
350
+ }
351
+
352
+ /**
353
+ * A minimal subset of the formal JSON Schema that describes a property.
354
+ */
355
+ export interface IProperty extends PartialJSONObject {
356
+ /**
357
+ * The default value, if any.
358
+ */
359
+ default?: PartialJSONValue;
360
+
361
+ /**
362
+ * The schema description.
363
+ */
364
+ description?: string;
365
+
366
+ /**
367
+ * The schema's child properties.
368
+ */
369
+ properties?: { [property: string]: IProperty };
370
+
371
+ /**
372
+ * The title of a property.
373
+ */
374
+ title?: string;
375
+
376
+ /**
377
+ * The type or types of the data.
378
+ */
379
+ type?: Primitive | Primitive[];
380
+ }
381
+
382
+ /**
383
+ * A schema type that is a minimal subset of the formal JSON Schema along with
384
+ * optional JupyterLab rendering hints.
385
+ */
386
+ export interface ISchema extends IProperty {
387
+ /**
388
+ * The JupyterLab menus that are created by a plugin's schema.
389
+ */
390
+ 'jupyter.lab.menus'?: {
391
+ main: IMenu[];
392
+ context: IContextMenuItem[];
393
+ };
394
+
395
+ /**
396
+ * Whether the schema is deprecated.
397
+ *
398
+ * #### Notes
399
+ * This flag can be used by functionality that loads this plugin's settings
400
+ * from the registry. For example, the setting editor does not display a
401
+ * plugin's settings if it is set to `true`.
402
+ */
403
+ 'jupyter.lab.setting-deprecated'?: boolean;
404
+
405
+ /**
406
+ * The JupyterLab icon hint.
407
+ */
408
+ 'jupyter.lab.setting-icon'?: string;
409
+
410
+ /**
411
+ * The JupyterLab icon class hint.
412
+ */
413
+ 'jupyter.lab.setting-icon-class'?: string;
414
+
415
+ /**
416
+ * The JupyterLab icon label hint.
417
+ */
418
+ 'jupyter.lab.setting-icon-label'?: string;
419
+
420
+ /**
421
+ * The JupyterLab toolbars created by a plugin's schema.
422
+ *
423
+ * #### Notes
424
+ * The toolbar items are grouped by document or widget factory name
425
+ * that will contain a toolbar.
426
+ */
427
+ 'jupyter.lab.toolbars'?: { [factory: string]: IToolbarItem[] };
428
+
429
+ /**
430
+ * A flag that indicates plugin should be transformed before being used by
431
+ * the setting registry.
432
+ *
433
+ * #### Notes
434
+ * If this value is set to `true`, the setting registry will wait until a
435
+ * transformation has been registered (by calling the `transform()` method
436
+ * of the registry) for the plugin ID before resolving `load()` promises.
437
+ * This means that if the attribute is set to `true` but no transformation
438
+ * is registered in time, calls to `load()` a plugin will eventually time
439
+ * out and reject.
440
+ */
441
+ 'jupyter.lab.transform'?: boolean;
442
+
443
+ /**
444
+ * The JupyterLab shortcuts that are created by a plugin's schema.
445
+ */
446
+ 'jupyter.lab.shortcuts'?: IShortcut[];
447
+
448
+ /**
449
+ * The JupyterLab metadata-form schema
450
+ */
451
+ 'jupyter.lab.metadataforms'?: IMetadataForm[];
452
+
453
+ /**
454
+ * The root schema is always an object.
455
+ */
456
+ type: 'object';
457
+ }
458
+
459
+ /**
460
+ * The setting values for a plugin.
461
+ */
462
+ export interface ISettingBundle extends PartialJSONObject {
463
+ /**
464
+ * A composite of the user setting values and the plugin schema defaults.
465
+ *
466
+ * #### Notes
467
+ * The `composite` values will always be a superset of the `user` values.
468
+ */
469
+ composite: PartialJSONObject;
470
+
471
+ /**
472
+ * The user setting values.
473
+ */
474
+ user: PartialJSONObject;
475
+ }
476
+
477
+ /**
478
+ * An interface for manipulating the settings of a specific plugin.
479
+ */
480
+ export interface ISettings extends IDisposable {
481
+ /**
482
+ * A signal that emits when the plugin's settings have changed.
483
+ */
484
+ readonly changed: ISignal<this, void>;
485
+
486
+ /**
487
+ * The composite of user settings and extension defaults.
488
+ */
489
+ readonly composite: ReadonlyPartialJSONObject;
490
+
491
+ /**
492
+ * The plugin's ID.
493
+ */
494
+ readonly id: string;
495
+
496
+ /*
497
+ * The underlying plugin.
498
+ */
499
+ readonly plugin: ISettingRegistry.IPlugin;
500
+
501
+ /**
502
+ * The plugin settings raw text value.
503
+ */
504
+ readonly raw: string;
505
+
506
+ /**
507
+ * The plugin's schema.
508
+ */
509
+ readonly schema: ISettingRegistry.ISchema;
510
+
511
+ /**
512
+ * The user settings.
513
+ */
514
+ readonly user: ReadonlyPartialJSONObject;
515
+
516
+ /**
517
+ * The published version of the NPM package containing these settings.
518
+ */
519
+ readonly version: string;
520
+
521
+ /**
522
+ * Return the defaults in a commented JSON format.
523
+ */
524
+ annotatedDefaults(): string;
525
+
526
+ /**
527
+ * Calculate the default value of a setting by iterating through the schema.
528
+ *
529
+ * @param key - The name of the setting whose default value is calculated.
530
+ *
531
+ * @returns A calculated default JSON value for a specific setting.
532
+ */
533
+ default(key: string): PartialJSONValue | undefined;
534
+
535
+ /**
536
+ * Get an individual setting.
537
+ *
538
+ * @param key - The name of the setting being retrieved.
539
+ *
540
+ * @returns The setting value.
541
+ */
542
+ get(key: string): {
543
+ composite: ReadonlyPartialJSONValue | undefined;
544
+ user: ReadonlyPartialJSONValue | undefined;
545
+ };
546
+
547
+ /**
548
+ * Remove a single setting.
549
+ *
550
+ * @param key - The name of the setting being removed.
551
+ *
552
+ * @returns A promise that resolves when the setting is removed.
553
+ *
554
+ * #### Notes
555
+ * This function is asynchronous because it writes to the setting registry.
556
+ */
557
+ remove(key: string): Promise<void>;
558
+
559
+ /**
560
+ * Save all of the plugin's user settings at once.
561
+ */
562
+ save(raw: string): Promise<void>;
563
+
564
+ /**
565
+ * Set a single setting.
566
+ *
567
+ * @param key - The name of the setting being set.
568
+ *
569
+ * @param value - The value of the setting.
570
+ *
571
+ * @returns A promise that resolves when the setting has been saved.
572
+ *
573
+ * #### Notes
574
+ * This function is asynchronous because it writes to the setting registry.
575
+ */
576
+ set(key: string, value: PartialJSONValue): Promise<void>;
577
+
578
+ /**
579
+ * Validates raw settings with comments.
580
+ *
581
+ * @param raw - The JSON with comments string being validated.
582
+ *
583
+ * @returns A list of errors or `null` if valid.
584
+ */
585
+ validate(raw: string): ISchemaValidator.IError[] | null;
586
+ }
587
+
588
+ /**
589
+ * An interface describing a JupyterLab keyboard shortcut.
590
+ */
591
+ export interface IShortcut extends PartialJSONObject {
592
+ /**
593
+ * The optional arguments passed into the shortcut's command.
594
+ */
595
+ args?: PartialJSONObject;
596
+
597
+ /**
598
+ * The command invoked by the shortcut.
599
+ */
600
+ command: string;
601
+
602
+ /**
603
+ * Whether a keyboard shortcut is disabled. `False` by default.
604
+ */
605
+ disabled?: boolean;
606
+
607
+ /**
608
+ * The key sequence of the shortcut.
609
+ *
610
+ * ### Notes
611
+ *
612
+ * If this is a list like `['Ctrl A', 'B']`, the user needs to press
613
+ * `Ctrl A` followed by `B` to trigger the shortcuts.
614
+ */
615
+ keys: string[];
616
+
617
+ /**
618
+ * The CSS selector applicable to the shortcut.
619
+ */
620
+ selector: string;
621
+ }
622
+
623
+ /**
624
+ * An interface describing the metadata form.
625
+ */
626
+ export interface IMetadataForm extends PartialJSONObject {
627
+ /**
628
+ * The section unique ID.
629
+ */
630
+ id: string;
631
+
632
+ /**
633
+ * The metadata schema.
634
+ */
635
+ metadataSchema: IMetadataSchema;
636
+
637
+ /**
638
+ * The ui schema as used by react-JSON-schema-form.
639
+ */
640
+ uiSchema?: { [metadataKey: string]: UiSchema };
641
+
642
+ /**
643
+ * The jupyter properties.
644
+ */
645
+ metadataOptions?: { [metadataKey: string]: IMetadataOptions };
646
+
647
+ /**
648
+ * The section label.
649
+ */
650
+ label?: string;
651
+
652
+ /**
653
+ * The section rank in notebooktools panel.
654
+ */
655
+ rank?: number;
656
+
657
+ /**
658
+ * Whether to show the modified field from default value.
659
+ */
660
+ showModified?: boolean;
661
+
662
+ /**
663
+ * Keep the plugin at origin of the metadata form.
664
+ */
665
+ _origin?: string;
666
+ }
667
+
668
+ /**
669
+ * The metadata schema as defined in JSON schema.
670
+ */
671
+ export interface IMetadataSchema extends RJSFSchema {
672
+ /**
673
+ * The properties as defined in JSON schema, and interpretable by react-JSON-schema-form.
674
+ */
675
+ properties: { [option: string]: any };
676
+
677
+ /**
678
+ * The required fields.
679
+ */
680
+ required?: string[];
681
+
682
+ /**
683
+ * Support for allOf feature of JSON schema (useful for if/then/else).
684
+ */
685
+ allOf?: Array<PartialJSONObject>;
686
+ }
687
+
688
+ /**
689
+ * Options to customize the widget, the field and the relevant metadata.
690
+ */
691
+ export interface IMetadataOptions extends PartialJSONObject {
692
+ /**
693
+ * Name of a custom react widget registered.
694
+ */
695
+ customWidget?: string;
696
+
697
+ /**
698
+ * Name of a custom react field registered.
699
+ */
700
+ customField?: string;
701
+
702
+ /**
703
+ * Metadata applied to notebook or cell.
704
+ */
705
+ metadataLevel?: 'cell' | 'notebook';
706
+
707
+ /**
708
+ * Cells which should have this metadata.
709
+ */
710
+ cellTypes?: CellType[];
711
+
712
+ /**
713
+ * Whether to avoid writing default value in metadata.
714
+ */
715
+ writeDefault?: boolean;
716
+ }
717
+
718
+ /**
719
+ * An interface describing a toolbar item.
720
+ */
721
+ export interface IToolbarItem extends PartialJSONObject {
722
+ /**
723
+ * Unique toolbar item name
724
+ */
725
+ name: string;
726
+
727
+ /**
728
+ * The command to execute when the item is triggered.
729
+ *
730
+ * The default value is an empty string.
731
+ */
732
+ command?: string;
733
+
734
+ /**
735
+ * The arguments for the command.
736
+ *
737
+ * The default value is an empty object.
738
+ */
739
+ args?: PartialJSONObject;
740
+
741
+ /**
742
+ * Whether the toolbar item is ignored (i.e. not created). `false` by default.
743
+ *
744
+ * #### Notes
745
+ * This allows an user to suppress toolbar items.
746
+ */
747
+ disabled?: boolean;
748
+
749
+ /**
750
+ * Item icon id
751
+ *
752
+ * #### Note
753
+ * The id will be looked for in the LabIcon registry.
754
+ * The command icon will be overridden by this label if defined.
755
+ */
756
+ icon?: string;
757
+
758
+ /**
759
+ * Item label
760
+ *
761
+ * #### Note
762
+ * The command label will be overridden by this label if defined.
763
+ */
764
+ label?: string;
765
+
766
+ /**
767
+ * The rank order of the toolbar item among its siblings.
768
+ */
769
+ rank?: number;
770
+
771
+ /**
772
+ * The type of the toolbar item.
773
+ */
774
+ type?: 'command' | 'spacer';
775
+ }
776
+ }