@jupyterlab/settingregistry
Advanced tools
Comparing version 3.3.0-alpha.17 to 3.3.0-alpha.18
@@ -270,2 +270,7 @@ import { IDataConnector } from '@jupyterlab/statedb'; | ||
/** | ||
* Checks if any fields are different from the default value. | ||
*/ | ||
isDefault(user: ReadonlyPartialJSONObject): boolean; | ||
get isModified(): boolean; | ||
/** | ||
* The user settings. | ||
@@ -289,3 +294,3 @@ */ | ||
*/ | ||
default(key: string): PartialJSONValue | undefined; | ||
default(key?: string): PartialJSONValue | undefined; | ||
/** | ||
@@ -292,0 +297,0 @@ * Dispose of the plugin settings resources. |
@@ -513,2 +513,26 @@ // Copyright (c) Jupyter Development Team. | ||
/** | ||
* Checks if any fields are different from the default value. | ||
*/ | ||
isDefault(user) { | ||
for (const key in this.schema.properties) { | ||
const value = user[key]; | ||
const defaultValue = this.default(key); | ||
if (value === undefined || | ||
value === null || | ||
defaultValue === undefined || | ||
defaultValue === null || | ||
JSONExt.deepEqual(value, JSONExt.emptyObject) || | ||
JSONExt.deepEqual(value, JSONExt.emptyArray)) { | ||
continue; | ||
} | ||
if (!JSONExt.deepEqual(value, defaultValue)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
get isModified() { | ||
return !this.isDefault(this.user); | ||
} | ||
/** | ||
* The user settings. | ||
@@ -976,17 +1000,42 @@ */ | ||
function reifyDefault(schema, root) { | ||
var _a; | ||
var _a, _b, _c; | ||
const definitions = schema.definitions; | ||
// If the property is at the root level, traverse its schema. | ||
schema = (root ? (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[root] : schema) || {}; | ||
// If the property has no default or is a primitive, return. | ||
if (!('default' in schema) || schema.type !== 'object') { | ||
if (schema.type === 'object') { | ||
// Make a copy of the default value to populate. | ||
const result = JSONExt.deepCopy(schema.default); | ||
// Iterate through and populate each child property. | ||
const props = schema.properties || {}; | ||
for (const property in props) { | ||
result[property] = reifyDefault(props[property]); | ||
} | ||
return result; | ||
} | ||
else if (schema.type === 'array') { | ||
// Make a copy of the default value to populate. | ||
const result = JSONExt.deepCopy(schema.default); | ||
// Items defines the properties of each item in the array | ||
let props = schema.items || {}; | ||
// Use referenced definition if one exists | ||
if (props['$ref'] && definitions) { | ||
const ref = props['$ref'].replace('#/definitions/', ''); | ||
props = (_b = definitions[ref]) !== null && _b !== void 0 ? _b : {}; | ||
} | ||
// Iterate through the items in the array and fill in defaults | ||
for (const item in result) { | ||
// Use the values that are hard-coded in the default array over the defaults for each field. | ||
const reified = reifyDefault(props) || {}; | ||
for (const prop in reified) { | ||
if ((_c = result[item]) === null || _c === void 0 ? void 0 : _c[prop]) { | ||
reified[prop] = result[item][prop]; | ||
} | ||
} | ||
result[item] = reified; | ||
} | ||
return result; | ||
} | ||
else { | ||
return schema.default; | ||
} | ||
// Make a copy of the default value to populate. | ||
const result = JSONExt.deepCopy(schema.default); | ||
// Iterate through and populate each child property. | ||
const props = schema.properties || {}; | ||
for (const property in props) { | ||
result[property] = reifyDefault(props[property]); | ||
} | ||
return result; | ||
} | ||
@@ -993,0 +1042,0 @@ Private.reifyDefault = reifyDefault; |
{ | ||
"name": "@jupyterlab/settingregistry", | ||
"version": "3.3.0-alpha.17", | ||
"version": "3.3.0-alpha.18", | ||
"description": "Settings registry for Jupyterlab", | ||
@@ -38,3 +38,3 @@ "homepage": "https://github.com/jupyterlab/jupyterlab", | ||
"dependencies": { | ||
"@jupyterlab/statedb": "^3.3.0-alpha.17", | ||
"@jupyterlab/statedb": "^3.3.0-alpha.18", | ||
"@lumino/commands": "^1.12.0", | ||
@@ -48,3 +48,3 @@ "@lumino/coreutils": "^1.5.3", | ||
"devDependencies": { | ||
"@jupyterlab/testutils": "^3.3.0-alpha.17", | ||
"@jupyterlab/testutils": "^3.3.0-alpha.18", | ||
"@types/jest": "^26.0.10", | ||
@@ -51,0 +51,0 @@ "@types/json5": "^0.0.30", |
Sorry, the diff of this file is not supported yet
108724
2333