@jupyterlab/settingregistry
Advanced tools
Comparing version 3.3.0-alpha.3 to 3.3.0-alpha.4
@@ -66,2 +66,15 @@ { | ||
}, | ||
"jupyter.lab.toolbars": { | ||
"properties": { | ||
"^\\w[\\w-\\.]*$": { | ||
"items": { | ||
"$ref": "#/definitions/toolbarItem" | ||
}, | ||
"type": "array", | ||
"default": [] | ||
} | ||
}, | ||
"type": "object", | ||
"default": {} | ||
}, | ||
"jupyter.lab.transform": { | ||
@@ -194,4 +207,50 @@ "type": "boolean", | ||
"type": "object" | ||
}, | ||
"toolbarItem": { | ||
"properties": { | ||
"name": { | ||
"title": "Unique name", | ||
"type": "string" | ||
}, | ||
"args": { | ||
"title": "Command arguments", | ||
"type": "object" | ||
}, | ||
"command": { | ||
"title": "Command id", | ||
"type": "string", | ||
"default": "" | ||
}, | ||
"disabled": { | ||
"title": "Whether the item is ignored or not", | ||
"type": "boolean", | ||
"default": false | ||
}, | ||
"icon": { | ||
"title": "Item icon id", | ||
"description": "If defined, it will override the command icon", | ||
"type": "string" | ||
}, | ||
"label": { | ||
"title": "Item label", | ||
"description": "If defined, it will override the command label", | ||
"type": "string" | ||
}, | ||
"type": { | ||
"title": "Item type", | ||
"type": "string", | ||
"enum": ["command", "spacer"] | ||
}, | ||
"rank": { | ||
"title": "Item rank", | ||
"type": "number", | ||
"minimum": 0, | ||
"default": 50 | ||
} | ||
}, | ||
"required": ["name"], | ||
"additionalProperties": false, | ||
"type": "object" | ||
} | ||
} | ||
} |
@@ -399,2 +399,8 @@ import { IDataConnector } from '@jupyterlab/statedb'; | ||
function reconcileItems<T extends ISettingRegistry.IMenuItem>(reference?: T[], addition?: T[], warn?: boolean, addNewItems?: boolean): T[] | undefined; | ||
/** | ||
* Remove disabled entries from menu items | ||
* | ||
* @param items Menu items | ||
* @returns Filtered menu items | ||
*/ | ||
function filterDisabledItems<T extends ISettingRegistry.IMenuItem>(items: T[]): T[]; | ||
@@ -411,2 +417,11 @@ /** | ||
function reconcileShortcuts(defaults: ISettingRegistry.IShortcut[], user: ISettingRegistry.IShortcut[]): ISettingRegistry.IShortcut[]; | ||
/** | ||
* Merge two set of toolbar items. | ||
* | ||
* @param reference Reference set of toolbar items | ||
* @param addition New items to add | ||
* @param warn Whether to warn if item is duplicated; default to false | ||
* @returns The merged set of items | ||
*/ | ||
function reconcileToolbarItems(reference?: ISettingRegistry.IToolbarItem[], addition?: ISettingRegistry.IToolbarItem[], warn?: boolean): ISettingRegistry.IToolbarItem[] | undefined; | ||
} | ||
@@ -413,0 +428,0 @@ /** |
@@ -724,2 +724,8 @@ // Copyright (c) Jupyter Development Team. | ||
SettingRegistry.reconcileItems = reconcileItems; | ||
/** | ||
* Remove disabled entries from menu items | ||
* | ||
* @param items Menu items | ||
* @returns Filtered menu items | ||
*/ | ||
function filterDisabledItems(items) { | ||
@@ -803,2 +809,58 @@ return items.reduce((final, value) => { | ||
SettingRegistry.reconcileShortcuts = reconcileShortcuts; | ||
/** | ||
* Merge two set of toolbar items. | ||
* | ||
* @param reference Reference set of toolbar items | ||
* @param addition New items to add | ||
* @param warn Whether to warn if item is duplicated; default to false | ||
* @returns The merged set of items | ||
*/ | ||
function reconcileToolbarItems(reference, addition, warn = false) { | ||
if (!reference) { | ||
return addition ? JSONExt.deepCopy(addition) : undefined; | ||
} | ||
if (!addition) { | ||
return JSONExt.deepCopy(reference); | ||
} | ||
const items = JSONExt.deepCopy(reference); | ||
// Merge array element depending on the type | ||
addition.forEach(item => { | ||
switch (item.type) { | ||
case 'command': | ||
if (item.command) { | ||
const refIndex = items.findIndex(ref => { | ||
var _a, _b; | ||
return ref.name === item.name && | ||
ref.command === item.command && | ||
JSONExt.deepEqual((_a = ref.args) !== null && _a !== void 0 ? _a : {}, (_b = item.args) !== null && _b !== void 0 ? _b : {}); | ||
}); | ||
if (refIndex < 0) { | ||
items.push(Object.assign({}, item)); | ||
} | ||
else { | ||
if (warn) { | ||
console.warn(`Toolbar item for command '${item.command}' is duplicated.`); | ||
} | ||
items[refIndex] = Object.assign(Object.assign({}, items[refIndex]), item); | ||
} | ||
} | ||
break; | ||
case 'spacer': | ||
default: { | ||
const refIndex = items.findIndex(ref => ref.name === item.name); | ||
if (refIndex < 0) { | ||
items.push(Object.assign({}, item)); | ||
} | ||
else { | ||
if (warn) { | ||
console.warn(`Toolbar item '${item.name}' is duplicated.`); | ||
} | ||
items[refIndex] = Object.assign(Object.assign({}, items[refIndex]), item); | ||
} | ||
} | ||
} | ||
}); | ||
return items; | ||
} | ||
SettingRegistry.reconcileToolbarItems = reconcileToolbarItems; | ||
})(SettingRegistry || (SettingRegistry = {})); | ||
@@ -805,0 +867,0 @@ /** |
@@ -135,3 +135,3 @@ import { IDataConnector } from '@jupyterlab/statedb'; | ||
/** | ||
* Menu defined by a specific plugin | ||
* An interface defining a menu. | ||
*/ | ||
@@ -180,2 +180,5 @@ interface IMenu extends PartialJSONObject { | ||
} | ||
/** | ||
* An interface describing a menu item. | ||
*/ | ||
interface IMenuItem extends PartialJSONObject { | ||
@@ -331,2 +334,12 @@ /** | ||
/** | ||
* The JupyterLab toolbars created by a plugin's schema. | ||
* | ||
* #### Notes | ||
* The toolbar items are grouped by document or widget factory name | ||
* that will contain a toolbar. | ||
*/ | ||
'jupyter.lab.toolbars'?: { | ||
[factory: string]: IToolbarItem[]; | ||
}; | ||
/** | ||
* A flag that indicates plugin should be transformed before being used by | ||
@@ -487,2 +500,53 @@ * the setting registry. | ||
} | ||
/** | ||
* An interface describing a toolbar item. | ||
*/ | ||
interface IToolbarItem extends PartialJSONObject { | ||
/** | ||
* Unique toolbar item name | ||
*/ | ||
name: string; | ||
/** | ||
* The command to execute when the item is triggered. | ||
* | ||
* The default value is an empty string. | ||
*/ | ||
command?: string; | ||
/** | ||
* The arguments for the command. | ||
* | ||
* The default value is an empty object. | ||
*/ | ||
args?: PartialJSONObject; | ||
/** | ||
* Whether the toolbar item is ignored (i.e. not created). `false` by default. | ||
* | ||
* #### Notes | ||
* This allows an user to suppress toolbar items. | ||
*/ | ||
disabled?: boolean; | ||
/** | ||
* Item icon id | ||
* | ||
* #### Note | ||
* The id will be looked for in the LabIcon registry. | ||
* The command icon will be overridden by this label if defined. | ||
*/ | ||
icon?: string; | ||
/** | ||
* Item label | ||
* | ||
* #### Note | ||
* The command label will be overridden by this label if defined. | ||
*/ | ||
label?: string; | ||
/** | ||
* The rank order of the toolbar item among its siblings. | ||
*/ | ||
rank?: number; | ||
/** | ||
* The type of the toolbar item. | ||
*/ | ||
type?: 'command' | 'spacer'; | ||
} | ||
} |
{ | ||
"name": "@jupyterlab/settingregistry", | ||
"version": "3.3.0-alpha.3", | ||
"version": "3.3.0-alpha.4", | ||
"description": "Settings registry for Jupyterlab", | ||
@@ -39,3 +39,3 @@ "homepage": "https://github.com/jupyterlab/jupyterlab", | ||
"dependencies": { | ||
"@jupyterlab/statedb": "^3.3.0-alpha.3", | ||
"@jupyterlab/statedb": "^3.3.0-alpha.4", | ||
"@lumino/commands": "^1.12.0", | ||
@@ -49,3 +49,3 @@ "@lumino/coreutils": "^1.5.3", | ||
"devDependencies": { | ||
"@jupyterlab/testutils": "^3.3.0-alpha.3", | ||
"@jupyterlab/testutils": "^3.3.0-alpha.4", | ||
"@types/jest": "^26.0.10", | ||
@@ -52,0 +52,0 @@ "@types/json5": "^0.0.30", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
104765
2263