Selaa lähdekoodia

Remove the concept of annotation for settings.

Afshin Darian 7 vuotta sitten
vanhempi
commit
ce783c7d51

+ 8 - 1
packages/apputils-extension/src/settingclientdatastore.ts

@@ -34,7 +34,8 @@ class SettingClientDatastore extends StateDB {
   fetch(id: string): Promise<JSONObject | null> {
     return super.fetch(id).then(result => {
       const schema = Private.schemas[id] || null;
-      console.log('schema', schema);
+
+      result.schema = schema;
       return result;
     });
   }
@@ -66,6 +67,12 @@ namespace Private {
       "jupyter.lab": {
         "iconClass": "jp-ImageTextEditor",
         "iconLabel": "CodeMirror"
+      },
+      "properties": {
+        "jupyter.lab": { type: "object" },
+        "keyMap": { type: "string", "title": "Key Map" },
+        "matchBrackets": { type: "boolean", "title": "Match Brackets" },
+        "theme": { type: "boolean", "title": "Theme" }
       }
     }
   };

+ 18 - 75
packages/coreutils/src/settingregistry.ts

@@ -29,8 +29,8 @@ import {
  * The schema for settings.
  */
 const SCHEMA = {
-  "$schema": "http://json-schema.org/draft-04/schema#",
-  "$id": "http://jupyter.org/settings/0.1.0/schema#",
+  "$schema": "http://json-schema.org/draft-06/schema",
+  "$id": "http://jupyter.org/settings/0.1.0/schema",
   "title": "Jupyter Settings/Preferences Schema",
   "description": "Jupyter settings/preferences schema v0.1.0",
   "type": "object",
@@ -66,16 +66,16 @@ const copy = JSONExt.deepCopy;
 export
 interface ISchemaValidator {
   /**
-   * Validate a data object against a JSON schema.
+   * Validate a data object against a plugin's JSON schema.
    *
-   * @param schema - The JSON schema.
+   * @param plugin - The plugin ID.
    *
    * @param data - The data being validated.
    *
    * @returns A promise that resolves with void if successful and rejects with a
    * list of errors if either the schema or data fails to validate.
    */
-  validate(schema: JSONObject, data: JSONObject): Promise<void | Ajv.ErrorObject[]>;
+  validateData(plugin: string, data: JSONObject): Promise<void | Ajv.ErrorObject[]>;
 }
 
 
@@ -99,37 +99,6 @@ namespace ISettingRegistry {
   export
   type Level = 'system' | 'user';
 
-  /**
-   * An annotation for a specific setting or a plugin.
-   */
-  export
-  interface IAnnotation extends JSONObject {
-    /**
-     * The caption for the setting.
-     */
-    caption?: string;
-
-    /**
-     * The extra class name for the setting.
-     */
-    className?: string;
-
-    /**
-     * The icon class for the setting.
-     */
-    iconClass?: string;
-
-    /**
-     * The icon label for the setting.
-     */
-    iconLabel?: string;
-
-    /**
-     * The label for the setting.
-     */
-    label?: string;
-  }
-
   /**
    * The settings for a specific plugin.
    */
@@ -146,15 +115,6 @@ namespace ISettingRegistry {
     data: ISettingBundle | null;
   }
 
-  /**
-   * The annotations for a plugin.
-   */
-  export
-  interface IPluginAnnotations extends JSONObject {
-    annotation: IAnnotation;
-    keys?: { [key: string]: IAnnotation };
-  }
-
   /**
    * The collection of user and system preferences for a plugin.
    */
@@ -169,11 +129,6 @@ namespace ISettingRegistry {
    */
   export
   interface ISettings extends IDisposable {
-    /**
-     * The annotation hints for a plugin.
-     */
-    readonly annotations: IPluginAnnotations | null;
-
     /**
      * A signal that emits when the plugin's settings have changed.
      */
@@ -254,21 +209,28 @@ class DefaultSchemaValidator implements ISchemaValidator {
    */
   constructor() {
     console.log('main schema', SCHEMA);
+    this._merger.addSchema(SCHEMA, 'main');
+    this._validator.addSchema(SCHEMA, 'main');
   }
 
   /**
-   * Validate a data object against a JSON schema.
+   * Validate a data object against a plugin's JSON schema.
    *
-   * @param schema - The JSON schema.
+   * @param plugin - The plugin ID.
    *
    * @param data - The data being validated.
    *
    * @returns A promise that resolves with void if successful and rejects with a
    * list of errors if either the schema or data fails to validate.
    */
-  validate(schema: JSONObject, data: JSONObject): Promise<void | Ajv.ErrorObject[]> {
+  validateData(plugin: string, data: JSONObject): Promise<void | Ajv.ErrorObject[]> {
     try {
-      const validate = this._validator.compile(schema);
+      const validate = this._validator.getSchema(plugin);
+
+      if (!validate) {
+        throw new Error(`Schema ${plugin} is unknown.`);
+      }
+
       const result = validate(data);
       const { errors } = validate;
 
@@ -287,6 +249,7 @@ class DefaultSchemaValidator implements ISchemaValidator {
     }
   }
 
+  private _merger = new Ajv({ useDefaults: true });
   private _validator = new Ajv();
 }
 
@@ -358,9 +321,8 @@ class SettingRegistry {
 
     // If the plugin exists, resolve.
     if (plugin in plugins) {
-      const annotations = this._annotations[plugin] || null;
       const content = plugins[plugin];
-      const settings = new Settings({ annotations, content, plugin, registry });
+      const settings = new Settings({ content, plugin, registry });
 
       return Promise.resolve(settings);
     }
@@ -385,11 +347,7 @@ class SettingRegistry {
       // Set the local copy.
       plugins[plugin] = result || { id: plugin, data: { } };
 
-      // Copy over any annotations that may be available.
-      const annotations = copy(this._annotations[plugin]);
-
       return new Settings({
-        annotations: annotations as ISettingRegistry.IPluginAnnotations,
         content: copy(plugins[plugin]) as ISettingRegistry.IPlugin,
         plugin,
         registry: this
@@ -484,7 +442,6 @@ class SettingRegistry {
       .then(() => { this._pluginChanged.emit(plugin); });
   }
 
-  private _annotations: { [plugin: string]: ISettingRegistry.IPluginAnnotations } = Object.create(null);
   private _datastore: IDatastore<ISettingRegistry.IPlugin, ISettingRegistry.IPlugin> | null = null;
   private _pluginChanged = new Signal<this, string>(this);
   private _plugins: { [name: string]: ISettingRegistry.IPlugin } = Object.create(null);
@@ -500,7 +457,6 @@ class Settings implements ISettingRegistry.ISettings {
    * Instantiate a new plugin settings manager.
    */
   constructor(options: Settings.IOptions) {
-    this._annotations = options.annotations;
     this._content = options.content;
     this.plugin = options.plugin;
     this.registry = options.registry;
@@ -508,13 +464,6 @@ class Settings implements ISettingRegistry.ISettings {
     this.registry.pluginChanged.connect(this._onPluginChanged, this);
   }
 
-  /**
-   * The annotation hints for the plugin.
-   */
-  get annotations(): ISettingRegistry.IPluginAnnotations {
-    return this._annotations;
-  }
-
   /**
    * A signal that emits when the plugin's settings have changed.
    */
@@ -625,7 +574,6 @@ class Settings implements ISettingRegistry.ISettings {
     }
   }
 
-  private _annotations: ISettingRegistry.IPluginAnnotations | null = null;
   private _changed = new Signal<this, void>(this);
   private _content: ISettingRegistry.IPlugin | null = null;
   private _isDisposed = false;
@@ -664,11 +612,6 @@ namespace Settings {
    */
   export
   interface IOptions {
-    /**
-     * The annotation hints for a plugin.
-     */
-    annotations: ISettingRegistry.IPluginAnnotations | null;
-
     /**
      * The setting values for a plugin.
      */

+ 12 - 30
packages/settingeditor-extension/src/settingeditor.ts

@@ -47,11 +47,6 @@ const PLUGIN_EDITOR_CLASS = 'jp-PluginEditor';
  */
 const PLUGIN_FIELDSET_CLASS = 'jp-PluginFieldset';
 
-/**
- * The class name added to key labels in the fieldset.
- */
-const KEY_LABEL_CLASS = 'jp-PluginFieldset-key';
-
 /**
  * The class name added to all plugin lists.
  */
@@ -310,7 +305,7 @@ class PluginList extends Widget {
 
     this.node.textContent = '';
     plugins.forEach(plugin => {
-      const item = Private.createListItem(plugin, null);
+      const item = Private.createListItem(plugin);
 
       if (plugin.id === this._selection) {
         item.classList.add(SELECTED_CLASS);
@@ -576,7 +571,7 @@ class PluginFieldset extends Widget {
 
     const settings = this._settings;
 
-    Private.populateFieldset(this.node, settings.raw, settings.annotations);
+    Private.populateFieldset(this.node, settings.raw);
   }
 
   private _settings: ISettingRegistry.ISettings | null = null;
@@ -602,41 +597,28 @@ namespace Private {
    * Create a plugin list item.
    */
   export
-  function createListItem(plugin: ISettingRegistry.IPlugin, annotations: ISettingRegistry.IPluginAnnotations): HTMLLIElement {
-    const annotation = annotations && annotations.annotation;
-    const caption = annotation && annotation.caption || plugin.id;
-    const className = annotation && annotation.className || '';
-    const iconClass = `${PLUGIN_ICON_CLASS} ${
-      annotation && annotation.iconClass || ''
-    }`;
-    const iconLabel = annotation && annotation.iconLabel || '';
-    const label = (annotation && annotation.label) || plugin.id;
+  function createListItem(plugin: ISettingRegistry.IPlugin): HTMLLIElement {
+    const caption = plugin.id;
+    const className = '';
+    const iconClass = `${PLUGIN_ICON_CLASS}`;
+    const iconLabel = '';
+    const title = plugin.id;
 
     return VirtualDOM.realize(
       h.li({ className, dataset: { id: plugin.id }, title: caption },
         h.span({ className: iconClass, title: iconLabel }),
-        h.span(label))
+        h.span(title))
     ) as HTMLLIElement;
   }
 
   /**
-   * Populate the fieldset with a specific plugin's annotation.
+   * Populate the fieldset with a specific plugin's metaata.
    */
   export
-  function populateFieldset(node: HTMLElement, plugin: ISettingRegistry.IPlugin, annotations: ISettingRegistry.IPluginAnnotations): void {
-    const label = annotations && annotations.annotation &&
-      `Available Fields - ${annotations.annotation.label}` ||
-      `Available Fields - ${plugin.id}`;
+  function populateFieldset(node: HTMLElement, plugin: ISettingRegistry.IPlugin): void {
+    const label = `Available Fields - ${plugin.id}`;
     const fields: { [key: string]: VirtualElement } = Object.create(null);
 
-    Object.keys(annotations && annotations.keys || { }).forEach(key => {
-      const annotation = annotations.keys[key];
-      const label = annotation.label ? `(${annotation.label})` : '';
-
-      fields[key] = h.li(
-        h.code(key),
-        h.span({ className: KEY_LABEL_CLASS }, label));
-    });
     Object.keys(plugin.data.system || { }).forEach(key => {
       if (!fields[key]) {
         fields[key] = h.li(h.code(key));

+ 0 - 4
packages/settingeditor-extension/style/settingeditor.css

@@ -134,7 +134,3 @@
   margin: 3px;
   padding: 3px;
 }
-
-#setting-editor.jp-SettingEditor .jp-PluginEditor .jp-PluginFieldset-key {
-  margin-left: 3px;
-}