@jupyterlab/settingeditor 0.6.2 → 0.7.4
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/raweditor.js +2 -4
- package/lib/raweditor.js.map +1 -1
- package/package.json +6 -6
package/lib/raweditor.js
CHANGED
|
@@ -291,10 +291,8 @@ var Private;
|
|
|
291
291
|
// the toolbar is in, the relative location of the revert button in the
|
|
292
292
|
// toolbar remains the same.
|
|
293
293
|
[revert, debug, save].forEach(name => {
|
|
294
|
-
const item = apputils_1.
|
|
295
|
-
|
|
296
|
-
toolbar.addItem(name, item);
|
|
297
|
-
}
|
|
294
|
+
const item = new apputils_1.CommandToolbarButton({ commands: registry, id: name });
|
|
295
|
+
toolbar.addItem(name, item);
|
|
298
296
|
});
|
|
299
297
|
}
|
|
300
298
|
Private.populateToolbar = populateToolbar;
|
package/lib/raweditor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raweditor.js","sourceRoot":"","sources":["../../../../settingeditor/src/raweditor.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D,mDAA+C;AAE/C,uDAAuE;AAUvE,mDAAsD;AAEtD,+CAAsD;AAEtD,2CAA8C;AAE9C,6CAA0C;AAE1C;;GAEG;AACH,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAEhD;;GAEG;AACH,MAAM,UAAU,GAAG,2BAA2B,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,GAAG,cAAc,CAAC;AAEnC;;GAEG;AACH,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAExC;;GAEG;AACH,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAEpC;;GAEG;AACH,eAAuB,SAAQ,uBAAU;IACvC;;OAEG;IACH,YAAY,OAA2B;QACrC,KAAK,CAAC;YACJ,WAAW,EAAE,YAAY;YACzB,QAAQ,EAAE,uBAAU,CAAC,eAAe;YACpC,OAAO,EAAE,C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OAAO,QA6DhB","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport { Toolbar } from '@jupyterlab/apputils';\n\nimport { CodeEditor, CodeEditorWrapper } from '@jupyterlab/codeeditor';\n\nimport { ISettingRegistry } from '@jupyterlab/coreutils';\n\nimport { RenderMimeRegistry } from '@jupyterlab/rendermime';\n\nimport { CommandRegistry } from '@phosphor/commands';\n\nimport { Message } from '@phosphor/messaging';\n\nimport { ISignal, Signal } from '@phosphor/signaling';\n\nimport { BoxLayout, Widget } from '@phosphor/widgets';\n\nimport { createInspector } from './inspector';\n\nimport { SplitPanel } from './splitpanel';\n\n/**\n * A class name added to all raw editors.\n */\nconst RAW_EDITOR_CLASS = 'jp-SettingsRawEditor';\n\n/**\n * A class name added to the user settings editor.\n */\nconst USER_CLASS = 'jp-SettingsRawEditor-user';\n\n/**\n * A class name added to the user editor when there are validation errors.\n */\nconst ERROR_CLASS = 'jp-mod-error';\n\n/**\n * The banner text for the default editor.\n */\nconst DEFAULT_TITLE = 'System Defaults';\n\n/**\n * The banner text for the user settings editor.\n */\nconst USER_TITLE = 'User Overrides';\n\n/**\n * A raw JSON settings editor.\n */\nexport class RawEditor extends SplitPanel {\n /**\n * Create a new plugin editor.\n */\n constructor(options: RawEditor.IOptions) {\n super({\n orientation: 'horizontal',\n renderer: SplitPanel.defaultRenderer,\n spacing: 1\n });\n\n const { commands, editorFactory, registry } = options;\n\n this.registry = registry;\n this._commands = commands;\n\n // Create read-only defaults editor.\n const defaults = (this._defaults = new CodeEditorWrapper({\n model: new CodeEditor.Model(),\n factory: editorFactory\n }));\n\n defaults.editor.model.value.text = '';\n defaults.editor.model.mimeType = 'text/javascript';\n defaults.editor.setOption('readOnly', true);\n\n // Create read-write user settings editor.\n const user = (this._user = new CodeEditorWrapper({\n model: new CodeEditor.Model(),\n factory: editorFactory,\n config: { lineNumbers: true }\n }));\n\n user.addClass(USER_CLASS);\n user.editor.model.mimeType = 'text/javascript';\n user.editor.model.value.changed.connect(this._onTextChanged, this);\n\n // Create and set up an inspector.\n this._inspector = createInspector(this, options.rendermime);\n\n this.addClass(RAW_EDITOR_CLASS);\n this._onSaveError = options.onSaveError;\n this.addWidget(Private.defaultsEditor(defaults));\n this.addWidget(Private.userEditor(user, this._toolbar, this._inspector));\n }\n\n /**\n * The setting registry used by the editor.\n */\n readonly registry: ISettingRegistry;\n\n /**\n * Whether the raw editor revert functionality is enabled.\n */\n get canRevert(): boolean {\n return this._canRevert;\n }\n\n /**\n * Whether the raw editor save functionality is enabled.\n */\n get canSave(): boolean {\n return this._canSave;\n }\n\n /**\n * Emits when the commands passed in at instantiation change.\n */\n get commandsChanged(): ISignal<any, string[]> {\n return this._commandsChanged;\n }\n\n /**\n * Whether the debug panel is visible.\n */\n get isDebugVisible(): boolean {\n return this._inspector.isVisible;\n }\n\n /**\n * Tests whether the settings have been modified and need saving.\n */\n get isDirty(): boolean {\n return this._user.editor.model.value.text !== this._settings.raw;\n }\n\n /**\n * The plugin settings being edited.\n */\n get settings(): ISettingRegistry.ISettings | null {\n return this._settings;\n }\n set settings(settings: ISettingRegistry.ISettings | null) {\n if (!settings && !this._settings) {\n return;\n }\n\n const samePlugin =\n settings && this._settings && settings.plugin === this._settings.plugin;\n\n if (samePlugin) {\n return;\n }\n\n const defaults = this._defaults;\n const user = this._user;\n\n // Disconnect old settings change handler.\n if (this._settings) {\n this._settings.changed.disconnect(this._onSettingsChanged, this);\n }\n\n if (settings) {\n this._settings = settings;\n this._settings.changed.connect(this._onSettingsChanged, this);\n this._onSettingsChanged();\n } else {\n this._settings = null;\n defaults.editor.model.value.text = '';\n user.editor.model.value.text = '';\n }\n\n this.update();\n }\n\n /**\n * Get the relative sizes of the two editor panels.\n */\n get sizes(): number[] {\n return this.relativeSizes();\n }\n set sizes(sizes: number[]) {\n this.setRelativeSizes(sizes);\n }\n\n /**\n * The inspectable source editor for user input.\n */\n get source(): CodeEditor.IEditor {\n return this._user.editor;\n }\n\n /**\n * Dispose of the resources held by the raw editor.\n */\n dispose(): void {\n if (this.isDisposed) {\n return;\n }\n\n super.dispose();\n this._defaults.dispose();\n this._user.dispose();\n }\n\n /**\n * Revert the editor back to original settings.\n */\n revert(): void {\n this._user.editor.model.value.text = this.settings.raw;\n this._updateToolbar(false, false);\n }\n\n /**\n * Save the contents of the raw editor.\n */\n save(): Promise<void> {\n if (!this.isDirty) {\n return Promise.resolve(undefined);\n }\n\n const settings = this._settings;\n const source = this._user.editor.model.value.text;\n\n return settings\n .save(source)\n .then(() => {\n this._updateToolbar(false, false);\n })\n .catch(reason => {\n this._updateToolbar(true, false);\n this._onSaveError(reason);\n });\n }\n\n /**\n * Toggle the debug functionality.\n */\n toggleDebug(): void {\n const inspector = this._inspector;\n\n if (inspector.isHidden) {\n inspector.show();\n } else {\n inspector.hide();\n }\n this._updateToolbar();\n }\n\n /**\n * Handle `after-attach` messages.\n */\n protected onAfterAttach(msg: Message): void {\n Private.populateToolbar(this._commands, this._toolbar);\n this.update();\n }\n\n /**\n * Handle `'update-request'` messages.\n */\n protected onUpdateRequest(msg: Message): void {\n const settings = this._settings;\n const defaults = this._defaults;\n const user = this._user;\n\n if (settings) {\n defaults.editor.refresh();\n user.editor.refresh();\n }\n }\n\n /**\n * Handle text changes in the underlying editor.\n */\n private _onTextChanged(): void {\n const raw = this._user.editor.model.value.text;\n const settings = this._settings;\n\n this.removeClass(ERROR_CLASS);\n\n // If there are no settings loaded or there are no changes, bail.\n if (!settings || settings.raw === raw) {\n this._updateToolbar(false, false);\n return;\n }\n\n const errors = settings.validate(raw);\n\n if (errors) {\n this.addClass(ERROR_CLASS);\n this._updateToolbar(true, false);\n return;\n }\n\n this._updateToolbar(true, true);\n }\n\n /**\n * Handle updates to the settings.\n */\n private _onSettingsChanged(): void {\n const settings = this._settings;\n const defaults = this._defaults;\n const user = this._user;\n\n defaults.editor.model.value.text = settings.annotatedDefaults();\n user.editor.model.value.text = settings.raw;\n }\n\n private _updateToolbar(revert = this._canRevert, save = this._canSave): void {\n const commands = this._commands;\n\n this._canRevert = revert;\n this._canSave = save;\n this._commandsChanged.emit([\n commands.debug,\n commands.revert,\n commands.save\n ]);\n }\n\n private _canRevert = false;\n private _canSave = false;\n private _commands: RawEditor.ICommandBundle;\n private _commandsChanged = new Signal<this, string[]>(this);\n private _defaults: CodeEditorWrapper;\n private _inspector: Widget;\n private _onSaveError: (reason: any) => void;\n private _settings: ISettingRegistry.ISettings | null = null;\n private _toolbar: Toolbar<Widget> = new Toolbar();\n private _user: CodeEditorWrapper;\n}\n\n/**\n * A namespace for `RawEditor` statics.\n */\nexport namespace RawEditor {\n /**\n * The toolbar commands and registry for the setting editor toolbar.\n */\n export interface ICommandBundle {\n /**\n * The command registry.\n */\n registry: CommandRegistry;\n\n /**\n * The debug command ID.\n */\n debug: string;\n\n /**\n * The revert command ID.\n */\n revert: string;\n\n /**\n * The save command ID.\n */\n save: string;\n }\n\n /**\n * The instantiation options for a raw editor.\n */\n export interface IOptions {\n /**\n * The toolbar commands and registry for the setting editor toolbar.\n */\n commands: ICommandBundle;\n\n /**\n * The editor factory used by the raw editor.\n */\n editorFactory: CodeEditor.Factory;\n\n /**\n * A function the raw editor calls on save errors.\n */\n onSaveError: (reason: any) => void;\n\n /**\n * The setting registry used by the editor.\n */\n registry: ISettingRegistry;\n\n /**\n * The optional MIME renderer to use for rendering debug messages.\n */\n rendermime?: RenderMimeRegistry;\n }\n}\n\n/**\n * A namespace for private module data.\n */\nnamespace Private {\n /**\n * Returns the wrapped setting defaults editor.\n */\n export function defaultsEditor(editor: Widget): Widget {\n const widget = new Widget();\n const layout = (widget.layout = new BoxLayout({ spacing: 0 }));\n const banner = new Widget();\n const bar = new Toolbar();\n\n banner.node.innerText = DEFAULT_TITLE;\n bar.insertItem(0, 'banner', banner);\n layout.addWidget(bar);\n layout.addWidget(editor);\n\n return widget;\n }\n\n /**\n * Populate the raw editor toolbar.\n */\n export function populateToolbar(\n commands: RawEditor.ICommandBundle,\n toolbar: Toolbar<Widget>\n ): void {\n const { debug, registry, revert, save } = commands;\n\n toolbar.addItem('spacer', Toolbar.createSpacerItem());\n\n // Note the button order. The rationale here is that no matter what state\n // the toolbar is in, the relative location of the revert button in the\n // toolbar remains the same.\n [revert, debug, save].forEach(name => {\n const item = Toolbar.createFromCommand(registry, name);\n\n if (item) {\n toolbar.addItem(name, item);\n }\n });\n }\n\n /**\n * Returns the wrapped user overrides editor.\n */\n export function userEditor(\n editor: Widget,\n toolbar: Toolbar<Widget>,\n inspector: Widget\n ): Widget {\n const widget = new Widget();\n const layout = (widget.layout = new BoxLayout({ spacing: 0 }));\n const banner = new Widget();\n\n banner.node.innerText = USER_TITLE;\n toolbar.insertItem(0, 'banner', banner);\n layout.addWidget(toolbar);\n layout.addWidget(editor);\n layout.addWidget(inspector);\n\n return widget;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"raweditor.js","sourceRoot":"","sources":["../../../../settingeditor/src/raweditor.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D,mDAAqE;AAErE,uDAAuE;AAUvE,mDAAsD;AAEtD,+CAAsD;AAEtD,2CAA8C;AAE9C,6CAA0C;AAE1C;;GAEG;AACH,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAEhD;;GAEG;AACH,MAAM,UAAU,GAAG,2BAA2B,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,GAAG,cAAc,CAAC;AAEnC;;GAEG;AACH,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAExC;;GAEG;AACH,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAEpC;;GAEG;AACH,eAAuB,SAAQ,uBAAU;IACvC;;OAEG;IACH,YAAY,OAA2B;QACrC,KAAK,CAAC;YACJ,WAAW,EAAE,YAAY;YACzB,QAAQ,EAAE,uBAAU,CAAC,eAAe;YACpC,OAAO,EAAE,CAAC;SACX,CAAC,CAAC;QAsQG,eAAU,GAAG,KAAK,CAAC;QACnB,aAAQ,GAAG,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nimport { Toolbar, CommandToolbarButton } from '@jupyterlab/apputils';\n\nimport { CodeEditor, CodeEditorWrapper } from '@jupyterlab/codeeditor';\n\nimport { ISettingRegistry } from '@jupyterlab/coreutils';\n\nimport { RenderMimeRegistry } from '@jupyterlab/rendermime';\n\nimport { CommandRegistry } from '@phosphor/commands';\n\nimport { Message } from '@phosphor/messaging';\n\nimport { ISignal, Signal } from '@phosphor/signaling';\n\nimport { BoxLayout, Widget } from '@phosphor/widgets';\n\nimport { createInspector } from './inspector';\n\nimport { SplitPanel } from './splitpanel';\n\n/**\n * A class name added to all raw editors.\n */\nconst RAW_EDITOR_CLASS = 'jp-SettingsRawEditor';\n\n/**\n * A class name added to the user settings editor.\n */\nconst USER_CLASS = 'jp-SettingsRawEditor-user';\n\n/**\n * A class name added to the user editor when there are validation errors.\n */\nconst ERROR_CLASS = 'jp-mod-error';\n\n/**\n * The banner text for the default editor.\n */\nconst DEFAULT_TITLE = 'System Defaults';\n\n/**\n * The banner text for the user settings editor.\n */\nconst USER_TITLE = 'User Overrides';\n\n/**\n * A raw JSON settings editor.\n */\nexport class RawEditor extends SplitPanel {\n /**\n * Create a new plugin editor.\n */\n constructor(options: RawEditor.IOptions) {\n super({\n orientation: 'horizontal',\n renderer: SplitPanel.defaultRenderer,\n spacing: 1\n });\n\n const { commands, editorFactory, registry } = options;\n\n this.registry = registry;\n this._commands = commands;\n\n // Create read-only defaults editor.\n const defaults = (this._defaults = new CodeEditorWrapper({\n model: new CodeEditor.Model(),\n factory: editorFactory\n }));\n\n defaults.editor.model.value.text = '';\n defaults.editor.model.mimeType = 'text/javascript';\n defaults.editor.setOption('readOnly', true);\n\n // Create read-write user settings editor.\n const user = (this._user = new CodeEditorWrapper({\n model: new CodeEditor.Model(),\n factory: editorFactory,\n config: { lineNumbers: true }\n }));\n\n user.addClass(USER_CLASS);\n user.editor.model.mimeType = 'text/javascript';\n user.editor.model.value.changed.connect(this._onTextChanged, this);\n\n // Create and set up an inspector.\n this._inspector = createInspector(this, options.rendermime);\n\n this.addClass(RAW_EDITOR_CLASS);\n this._onSaveError = options.onSaveError;\n this.addWidget(Private.defaultsEditor(defaults));\n this.addWidget(Private.userEditor(user, this._toolbar, this._inspector));\n }\n\n /**\n * The setting registry used by the editor.\n */\n readonly registry: ISettingRegistry;\n\n /**\n * Whether the raw editor revert functionality is enabled.\n */\n get canRevert(): boolean {\n return this._canRevert;\n }\n\n /**\n * Whether the raw editor save functionality is enabled.\n */\n get canSave(): boolean {\n return this._canSave;\n }\n\n /**\n * Emits when the commands passed in at instantiation change.\n */\n get commandsChanged(): ISignal<any, string[]> {\n return this._commandsChanged;\n }\n\n /**\n * Whether the debug panel is visible.\n */\n get isDebugVisible(): boolean {\n return this._inspector.isVisible;\n }\n\n /**\n * Tests whether the settings have been modified and need saving.\n */\n get isDirty(): boolean {\n return this._user.editor.model.value.text !== this._settings.raw;\n }\n\n /**\n * The plugin settings being edited.\n */\n get settings(): ISettingRegistry.ISettings | null {\n return this._settings;\n }\n set settings(settings: ISettingRegistry.ISettings | null) {\n if (!settings && !this._settings) {\n return;\n }\n\n const samePlugin =\n settings && this._settings && settings.plugin === this._settings.plugin;\n\n if (samePlugin) {\n return;\n }\n\n const defaults = this._defaults;\n const user = this._user;\n\n // Disconnect old settings change handler.\n if (this._settings) {\n this._settings.changed.disconnect(this._onSettingsChanged, this);\n }\n\n if (settings) {\n this._settings = settings;\n this._settings.changed.connect(this._onSettingsChanged, this);\n this._onSettingsChanged();\n } else {\n this._settings = null;\n defaults.editor.model.value.text = '';\n user.editor.model.value.text = '';\n }\n\n this.update();\n }\n\n /**\n * Get the relative sizes of the two editor panels.\n */\n get sizes(): number[] {\n return this.relativeSizes();\n }\n set sizes(sizes: number[]) {\n this.setRelativeSizes(sizes);\n }\n\n /**\n * The inspectable source editor for user input.\n */\n get source(): CodeEditor.IEditor {\n return this._user.editor;\n }\n\n /**\n * Dispose of the resources held by the raw editor.\n */\n dispose(): void {\n if (this.isDisposed) {\n return;\n }\n\n super.dispose();\n this._defaults.dispose();\n this._user.dispose();\n }\n\n /**\n * Revert the editor back to original settings.\n */\n revert(): void {\n this._user.editor.model.value.text = this.settings.raw;\n this._updateToolbar(false, false);\n }\n\n /**\n * Save the contents of the raw editor.\n */\n save(): Promise<void> {\n if (!this.isDirty) {\n return Promise.resolve(undefined);\n }\n\n const settings = this._settings;\n const source = this._user.editor.model.value.text;\n\n return settings\n .save(source)\n .then(() => {\n this._updateToolbar(false, false);\n })\n .catch(reason => {\n this._updateToolbar(true, false);\n this._onSaveError(reason);\n });\n }\n\n /**\n * Toggle the debug functionality.\n */\n toggleDebug(): void {\n const inspector = this._inspector;\n\n if (inspector.isHidden) {\n inspector.show();\n } else {\n inspector.hide();\n }\n this._updateToolbar();\n }\n\n /**\n * Handle `after-attach` messages.\n */\n protected onAfterAttach(msg: Message): void {\n Private.populateToolbar(this._commands, this._toolbar);\n this.update();\n }\n\n /**\n * Handle `'update-request'` messages.\n */\n protected onUpdateRequest(msg: Message): void {\n const settings = this._settings;\n const defaults = this._defaults;\n const user = this._user;\n\n if (settings) {\n defaults.editor.refresh();\n user.editor.refresh();\n }\n }\n\n /**\n * Handle text changes in the underlying editor.\n */\n private _onTextChanged(): void {\n const raw = this._user.editor.model.value.text;\n const settings = this._settings;\n\n this.removeClass(ERROR_CLASS);\n\n // If there are no settings loaded or there are no changes, bail.\n if (!settings || settings.raw === raw) {\n this._updateToolbar(false, false);\n return;\n }\n\n const errors = settings.validate(raw);\n\n if (errors) {\n this.addClass(ERROR_CLASS);\n this._updateToolbar(true, false);\n return;\n }\n\n this._updateToolbar(true, true);\n }\n\n /**\n * Handle updates to the settings.\n */\n private _onSettingsChanged(): void {\n const settings = this._settings;\n const defaults = this._defaults;\n const user = this._user;\n\n defaults.editor.model.value.text = settings.annotatedDefaults();\n user.editor.model.value.text = settings.raw;\n }\n\n private _updateToolbar(revert = this._canRevert, save = this._canSave): void {\n const commands = this._commands;\n\n this._canRevert = revert;\n this._canSave = save;\n this._commandsChanged.emit([\n commands.debug,\n commands.revert,\n commands.save\n ]);\n }\n\n private _canRevert = false;\n private _canSave = false;\n private _commands: RawEditor.ICommandBundle;\n private _commandsChanged = new Signal<this, string[]>(this);\n private _defaults: CodeEditorWrapper;\n private _inspector: Widget;\n private _onSaveError: (reason: any) => void;\n private _settings: ISettingRegistry.ISettings | null = null;\n private _toolbar: Toolbar<Widget> = new Toolbar();\n private _user: CodeEditorWrapper;\n}\n\n/**\n * A namespace for `RawEditor` statics.\n */\nexport namespace RawEditor {\n /**\n * The toolbar commands and registry for the setting editor toolbar.\n */\n export interface ICommandBundle {\n /**\n * The command registry.\n */\n registry: CommandRegistry;\n\n /**\n * The debug command ID.\n */\n debug: string;\n\n /**\n * The revert command ID.\n */\n revert: string;\n\n /**\n * The save command ID.\n */\n save: string;\n }\n\n /**\n * The instantiation options for a raw editor.\n */\n export interface IOptions {\n /**\n * The toolbar commands and registry for the setting editor toolbar.\n */\n commands: ICommandBundle;\n\n /**\n * The editor factory used by the raw editor.\n */\n editorFactory: CodeEditor.Factory;\n\n /**\n * A function the raw editor calls on save errors.\n */\n onSaveError: (reason: any) => void;\n\n /**\n * The setting registry used by the editor.\n */\n registry: ISettingRegistry;\n\n /**\n * The optional MIME renderer to use for rendering debug messages.\n */\n rendermime?: RenderMimeRegistry;\n }\n}\n\n/**\n * A namespace for private module data.\n */\nnamespace Private {\n /**\n * Returns the wrapped setting defaults editor.\n */\n export function defaultsEditor(editor: Widget): Widget {\n const widget = new Widget();\n const layout = (widget.layout = new BoxLayout({ spacing: 0 }));\n const banner = new Widget();\n const bar = new Toolbar();\n\n banner.node.innerText = DEFAULT_TITLE;\n bar.insertItem(0, 'banner', banner);\n layout.addWidget(bar);\n layout.addWidget(editor);\n\n return widget;\n }\n\n /**\n * Populate the raw editor toolbar.\n */\n export function populateToolbar(\n commands: RawEditor.ICommandBundle,\n toolbar: Toolbar<Widget>\n ): void {\n const { debug, registry, revert, save } = commands;\n\n toolbar.addItem('spacer', Toolbar.createSpacerItem());\n\n // Note the button order. The rationale here is that no matter what state\n // the toolbar is in, the relative location of the revert button in the\n // toolbar remains the same.\n [revert, debug, save].forEach(name => {\n const item = new CommandToolbarButton({ commands: registry, id: name });\n toolbar.addItem(name, item);\n });\n }\n\n /**\n * Returns the wrapped user overrides editor.\n */\n export function userEditor(\n editor: Widget,\n toolbar: Toolbar<Widget>,\n inspector: Widget\n ): Widget {\n const widget = new Widget();\n const layout = (widget.layout = new BoxLayout({ spacing: 0 }));\n const banner = new Widget();\n\n banner.node.innerText = USER_TITLE;\n toolbar.insertItem(0, 'banner', banner);\n layout.addWidget(toolbar);\n layout.addWidget(editor);\n layout.addWidget(inspector);\n\n return widget;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlab/settingeditor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "The JupyterLab default setting editor interface",
|
|
5
5
|
"homepage": "https://github.com/jupyterlab/jupyterlab",
|
|
6
6
|
"bugs": {
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"watch": "tsc -w --listEmittedFiles"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@jupyterlab/apputils": "^0.
|
|
33
|
-
"@jupyterlab/codeeditor": "^0.
|
|
34
|
-
"@jupyterlab/coreutils": "^2.
|
|
35
|
-
"@jupyterlab/inspector": "^0.
|
|
36
|
-
"@jupyterlab/rendermime": "^0.
|
|
32
|
+
"@jupyterlab/apputils": "^0.18.4",
|
|
33
|
+
"@jupyterlab/codeeditor": "^0.18.4",
|
|
34
|
+
"@jupyterlab/coreutils": "^2.1.4",
|
|
35
|
+
"@jupyterlab/inspector": "^0.18.4",
|
|
36
|
+
"@jupyterlab/rendermime": "^0.18.4",
|
|
37
37
|
"@phosphor/commands": "^1.5.0",
|
|
38
38
|
"@phosphor/coreutils": "^1.3.0",
|
|
39
39
|
"@phosphor/messaging": "^1.2.2",
|