@jupyterlab/coreutils
Advanced tools
| import { IDataConnector } from './interfaces'; | ||
| /** | ||
| * An abstract class that adheres to the data connector interface. | ||
| * | ||
| * #### Notes | ||
| * The only abstract method in this class is the `fetch` method, which must be | ||
| * reimplemented by all subclasses. The `remove` and `save` methods have a | ||
| * default implementation that returns a promise that will always reject. This | ||
| * class is a convenience superclass for connectors that only need to `fetch`. | ||
| */ | ||
| export declare abstract class DataConnector<T, U = T, V = string> implements IDataConnector<T, U, V> { | ||
| /** | ||
| * Retrieve an item from the data connector. | ||
| * | ||
| * @param id - The identifier used to retrieve an item. | ||
| * | ||
| * @returns A promise that bears a data payload if available. | ||
| * | ||
| * #### Notes | ||
| * The promise returned by this method may be rejected if an error occurs in | ||
| * retrieving the data. Nonexistence of an `id` will succeed with `undefined`. | ||
| */ | ||
| abstract fetch(id: V): Promise<T | undefined>; | ||
| /** | ||
| * Remove a value using the data connector. | ||
| * | ||
| * @param id - The identifier for the data being removed. | ||
| * | ||
| * @returns A promise that is rejected if remove fails and succeeds otherwise. | ||
| * | ||
| * #### Notes | ||
| * This method will always reject; subclasses should reimplement it if they | ||
| * support a back-end that can remove resources. | ||
| */ | ||
| remove(id: V): Promise<void>; | ||
| /** | ||
| * Save a value using the data connector. | ||
| * | ||
| * @param id - The identifier for the data being saved. | ||
| * | ||
| * @param value - The data being saved. | ||
| * | ||
| * @returns A promise that is rejected if saving fails and succeeds otherwise. | ||
| * | ||
| * #### Notes | ||
| * This method will always reject; subclasses should reimplement it if they | ||
| * support a back-end that can save resources. | ||
| */ | ||
| save(id: V, value: U): Promise<void>; | ||
| } |
| "use strict"; | ||
| // Copyright (c) Jupyter Development Team. | ||
| // Distributed under the terms of the Modified BSD License. | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| /** | ||
| * An abstract class that adheres to the data connector interface. | ||
| * | ||
| * #### Notes | ||
| * The only abstract method in this class is the `fetch` method, which must be | ||
| * reimplemented by all subclasses. The `remove` and `save` methods have a | ||
| * default implementation that returns a promise that will always reject. This | ||
| * class is a convenience superclass for connectors that only need to `fetch`. | ||
| */ | ||
| var DataConnector = /** @class */ (function () { | ||
| function DataConnector() { | ||
| } | ||
| /** | ||
| * Remove a value using the data connector. | ||
| * | ||
| * @param id - The identifier for the data being removed. | ||
| * | ||
| * @returns A promise that is rejected if remove fails and succeeds otherwise. | ||
| * | ||
| * #### Notes | ||
| * This method will always reject; subclasses should reimplement it if they | ||
| * support a back-end that can remove resources. | ||
| */ | ||
| DataConnector.prototype.remove = function (id) { | ||
| return Promise.reject(new Error('Removing has not been implemented.')); | ||
| }; | ||
| /** | ||
| * Save a value using the data connector. | ||
| * | ||
| * @param id - The identifier for the data being saved. | ||
| * | ||
| * @param value - The data being saved. | ||
| * | ||
| * @returns A promise that is rejected if saving fails and succeeds otherwise. | ||
| * | ||
| * #### Notes | ||
| * This method will always reject; subclasses should reimplement it if they | ||
| * support a back-end that can save resources. | ||
| */ | ||
| DataConnector.prototype.save = function (id, value) { | ||
| return Promise.reject(new Error('Saving has not been implemented.')); | ||
| }; | ||
| return DataConnector; | ||
| }()); | ||
| exports.DataConnector = DataConnector; |
@@ -9,3 +9,3 @@ "use strict"; | ||
| */ | ||
| var ActivityMonitor = (function () { | ||
| var ActivityMonitor = /** @class */ (function () { | ||
| /** | ||
@@ -86,2 +86,1 @@ * Construct a new activity monitor. | ||
| exports.ActivityMonitor = ActivityMonitor; | ||
| //# sourceMappingURL=activitymonitor.js.map |
+1
-6
| export * from './activitymonitor'; | ||
| export * from './dataconnector'; | ||
| export * from './interfaces'; | ||
| export * from './markdowncodeblocks'; | ||
| export * from './modeldb'; | ||
| export * from './nbformat'; | ||
| export * from './observablejson'; | ||
| export * from './observablelist'; | ||
| export * from './observablemap'; | ||
| export * from './observablestring'; | ||
| export * from './pageconfig'; | ||
@@ -16,4 +12,3 @@ export * from './path'; | ||
| export * from './time'; | ||
| export * from './undoablelist'; | ||
| export * from './url'; | ||
| export * from './uuid'; |
+1
-7
@@ -9,9 +9,5 @@ "use strict"; | ||
| __export(require("./activitymonitor")); | ||
| __export(require("./dataconnector")); | ||
| __export(require("./markdowncodeblocks")); | ||
| __export(require("./modeldb")); | ||
| __export(require("./nbformat")); | ||
| __export(require("./observablejson")); | ||
| __export(require("./observablelist")); | ||
| __export(require("./observablemap")); | ||
| __export(require("./observablestring")); | ||
| __export(require("./pageconfig")); | ||
@@ -23,5 +19,3 @@ __export(require("./path")); | ||
| __export(require("./time")); | ||
| __export(require("./undoablelist")); | ||
| __export(require("./url")); | ||
| __export(require("./uuid")); | ||
| //# sourceMappingURL=index.js.map |
+10
-11
@@ -21,7 +21,7 @@ /** | ||
| */ | ||
| export interface IDataConnector<T, U = T> { | ||
| export interface IDataConnector<T, U = T, V = string> { | ||
| /** | ||
| * Retrieve a saved bundle from the data connector. | ||
| * Retrieve an item from the data connector. | ||
| * | ||
| * @param id - The identifier used to retrieve a data bundle. | ||
| * @param id - The identifier used to retrieve an item. | ||
| * | ||
@@ -31,9 +31,8 @@ * @returns A promise that bears a data payload if available. | ||
| * #### Notes | ||
| * The promise returned by this method may be rejected if an error | ||
| * occurs in retrieving the data. Non-existence of an `id` will | ||
| * succeed with `undefined`. | ||
| * The promise returned by this method may be rejected if an error occurs in | ||
| * retrieving the data. Nonexistence of an `id` will succeed with `undefined`. | ||
| */ | ||
| fetch(id: string): Promise<T | undefined>; | ||
| fetch(id: V): Promise<T | undefined>; | ||
| /** | ||
| * Remove a value from the data connector. | ||
| * Remove a value using the data connector. | ||
| * | ||
@@ -44,5 +43,5 @@ * @param id - The identifier for the data being removed. | ||
| */ | ||
| remove(id: string): Promise<void>; | ||
| remove(id: V): Promise<void>; | ||
| /** | ||
| * Save a value in the data connector. | ||
| * Save a value using the data connector. | ||
| * | ||
@@ -55,3 +54,3 @@ * @param id - The identifier for the data being saved. | ||
| */ | ||
| save(id: string, value: U): Promise<void>; | ||
| save(id: V, value: U): Promise<void>; | ||
| } |
@@ -5,2 +5,1 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| //# sourceMappingURL=interfaces.js.map |
@@ -25,3 +25,3 @@ "use strict"; | ||
| ]; | ||
| var MarkdownCodeBlock = (function () { | ||
| var MarkdownCodeBlock = /** @class */ (function () { | ||
| function MarkdownCodeBlock(startLine) { | ||
@@ -99,2 +99,1 @@ this.startLine = startLine; | ||
| })(MarkdownCodeBlocks = exports.MarkdownCodeBlocks || (exports.MarkdownCodeBlocks = {})); | ||
| //# sourceMappingURL=markdowncodeblocks.js.map |
+0
-1
@@ -121,2 +121,1 @@ "use strict"; | ||
| })(nbformat = exports.nbformat || (exports.nbformat = {})); | ||
| //# sourceMappingURL=nbformat.js.map |
@@ -123,2 +123,1 @@ "use strict"; | ||
| })(PageConfig = exports.PageConfig || (exports.PageConfig = {})); | ||
| //# sourceMappingURL=pageconfig.js.map |
+0
-1
@@ -148,2 +148,1 @@ "use strict"; | ||
| })(PathExt = exports.PathExt || (exports.PathExt = {})); | ||
| //# sourceMappingURL=path.js.map |
+62
-35
@@ -1,2 +0,2 @@ | ||
| import { JSONObject, JSONValue, Token } from '@phosphor/coreutils'; | ||
| import { JSONObject, JSONValue, ReadonlyJSONObject, Token } from '@phosphor/coreutils'; | ||
| import { IDisposable } from '@phosphor/disposable'; | ||
@@ -18,16 +18,2 @@ import { ISignal } from '@phosphor/signaling'; | ||
| /** | ||
| * Add a schema to the validator. | ||
| * | ||
| * @param plugin - The plugin ID. | ||
| * | ||
| * @param schema - The schema being added. | ||
| * | ||
| * @return A list of errors if the schema fails to validate or `null` if there | ||
| * are no errors. | ||
| * | ||
| * #### Notes | ||
| * It is safe to call this function multiple times with the same plugin name. | ||
| */ | ||
| addSchema(plugin: string, schema: ISettingRegistry.ISchema): ISchemaValidator.IError[] | null; | ||
| /** | ||
| * Validate a plugin's schema and user data; populate the `composite` data. | ||
@@ -38,6 +24,9 @@ * | ||
| * | ||
| * @param populate - Whether plugin data should be populated, defaults to | ||
| * `true`. | ||
| * | ||
| * @return A list of errors if either the schema or data fail to validate or | ||
| * `null` if there are no errors. | ||
| */ | ||
| validateData(plugin: ISettingRegistry.IPlugin): ISchemaValidator.IError[] | null; | ||
| validateData(plugin: ISettingRegistry.IPlugin, populate?: boolean): ISchemaValidator.IError[] | null; | ||
| } | ||
@@ -65,2 +54,6 @@ /** | ||
| /** | ||
| * Optional parameter metadata that might be included in an error. | ||
| */ | ||
| params?: ReadonlyJSONObject; | ||
| /** | ||
| * The path in the schema where the error occurred. | ||
@@ -92,2 +85,6 @@ */ | ||
| /** | ||
| * The raw user settings data as a string containing JSON with comments. | ||
| */ | ||
| raw: string; | ||
| /** | ||
| * The JSON schema for the plugin. | ||
@@ -178,2 +175,6 @@ */ | ||
| /** | ||
| * The plugin settings raw text value. | ||
| */ | ||
| readonly raw: string; | ||
| /** | ||
| * Get the plugin settings schema. | ||
@@ -223,3 +224,3 @@ */ | ||
| */ | ||
| save(user: JSONObject): Promise<void>; | ||
| save(raw: string): Promise<void>; | ||
| /** | ||
@@ -238,2 +239,10 @@ * Set a single setting. | ||
| set(key: string, value: JSONValue): Promise<void>; | ||
| /** | ||
| * Validates raw settings with comments. | ||
| * | ||
| * @param raw - The JSON with comments string being validated. | ||
| * | ||
| * @returns A list of errors or `null` if valid. | ||
| */ | ||
| validate(raw: string): ISchemaValidator.IError[] | null; | ||
| } | ||
@@ -255,2 +264,15 @@ } | ||
| /** | ||
| * Validate a plugin's schema and user data; populate the `composite` data. | ||
| * | ||
| * @param plugin - The plugin being validated. Its `composite` data will be | ||
| * populated by reference. | ||
| * | ||
| * @param populate - Whether plugin data should be populated, defaults to | ||
| * `true`. | ||
| * | ||
| * @return A list of errors if either the schema or data fail to validate or | ||
| * `null` if there are no errors. | ||
| */ | ||
| validateData(plugin: ISettingRegistry.IPlugin, populate?: boolean): ISchemaValidator.IError[] | null; | ||
| /** | ||
| * Add a schema to the validator. | ||
@@ -268,13 +290,3 @@ * | ||
| */ | ||
| addSchema(plugin: string, schema: ISettingRegistry.ISchema): ISchemaValidator.IError[] | null; | ||
| /** | ||
| * Validate a plugin's schema and user data; populate the `composite` data. | ||
| * | ||
| * @param plugin - The plugin being validated. Its `composite` data will be | ||
| * populated by reference. | ||
| * | ||
| * @return A list of errors if either the schema or data fail to validate or | ||
| * `null` if there are no errors. | ||
| */ | ||
| validateData(plugin: ISettingRegistry.IPlugin): ISchemaValidator.IError[] | null; | ||
| private _addSchema(plugin, schema); | ||
| private _composer; | ||
@@ -296,2 +308,6 @@ private _validator; | ||
| /** | ||
| * The schema validator used by the setting registry. | ||
| */ | ||
| readonly validator: ISchemaValidator; | ||
| /** | ||
| * A signal that emits the name of a plugin when its settings change. | ||
@@ -361,10 +377,9 @@ */ | ||
| * | ||
| * @param plugin - The name of the plugin whose settings are being set. | ||
| * | ||
| * @param raw - The raw plugin settings being uploaded. | ||
| * | ||
| * @returns A promise that resolves when the settings have been saved. | ||
| * | ||
| * #### Notes | ||
| * Only the `user` data will be saved. | ||
| */ | ||
| upload(raw: ISettingRegistry.IPlugin): Promise<void>; | ||
| upload(plugin: string, raw: string): Promise<void>; | ||
| /** | ||
@@ -381,3 +396,2 @@ * Save a plugin in the registry. | ||
| private _plugins; | ||
| private _validator; | ||
| } | ||
@@ -409,2 +423,6 @@ /** | ||
| /** | ||
| * Get the plugin settings raw text value. | ||
| */ | ||
| readonly raw: string; | ||
| /** | ||
| * Get the user settings. | ||
@@ -463,3 +481,3 @@ */ | ||
| */ | ||
| save(user: JSONObject): Promise<void>; | ||
| save(raw: string): Promise<void>; | ||
| /** | ||
@@ -479,2 +497,10 @@ * Set a single setting. | ||
| /** | ||
| * Validates raw settings with comments. | ||
| * | ||
| * @param raw - The JSON with comments string being validated. | ||
| * | ||
| * @returns A list of errors or `null` if valid. | ||
| */ | ||
| validate(raw: string): ISchemaValidator.IError[] | null; | ||
| /** | ||
| * Handle plugin changes in the setting registry. | ||
@@ -486,2 +512,3 @@ */ | ||
| private _isDisposed; | ||
| private _raw; | ||
| private _schema; | ||
@@ -501,3 +528,3 @@ private _user; | ||
| */ | ||
| connector: IDataConnector<ISettingRegistry.IPlugin, JSONObject>; | ||
| connector: IDataConnector<ISettingRegistry.IPlugin, string>; | ||
| /** | ||
@@ -504,0 +531,0 @@ * The validator used to enforce the settings JSON schema. |
+144
-81
| "use strict"; | ||
| // Copyright (c) Jupyter Development Team. | ||
| // Distributed under the terms of the Modified BSD License. | ||
| var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
| for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
| s = arguments[i]; | ||
| for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
| t[p] = s[p]; | ||
| } | ||
| return t; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var Ajv = require("ajv"); | ||
| var json = require("comment-json"); | ||
| var algorithm_1 = require("@phosphor/algorithm"); | ||
@@ -29,3 +38,3 @@ var coreutils_1 = require("@phosphor/coreutils"); | ||
| */ | ||
| var DefaultSchemaValidator = (function () { | ||
| var DefaultSchemaValidator = /** @class */ (function () { | ||
| /** | ||
@@ -41,2 +50,59 @@ * Instantiate a schema validator. | ||
| /** | ||
| * Validate a plugin's schema and user data; populate the `composite` data. | ||
| * | ||
| * @param plugin - The plugin being validated. Its `composite` data will be | ||
| * populated by reference. | ||
| * | ||
| * @param populate - Whether plugin data should be populated, defaults to | ||
| * `true`. | ||
| * | ||
| * @return A list of errors if either the schema or data fail to validate or | ||
| * `null` if there are no errors. | ||
| */ | ||
| DefaultSchemaValidator.prototype.validateData = function (plugin, populate) { | ||
| if (populate === void 0) { populate = true; } | ||
| var validate = this._validator.getSchema(plugin.id); | ||
| var compose = this._composer.getSchema(plugin.id); | ||
| // If the schemas do not exist, add them to the validator and continue. | ||
| if (!validate || !compose) { | ||
| var errors = this._addSchema(plugin.id, plugin.schema); | ||
| if (errors) { | ||
| return errors; | ||
| } | ||
| return this.validateData(plugin); | ||
| } | ||
| // Parse the raw commented JSON into a user map. | ||
| var user; | ||
| try { | ||
| var strip = true; | ||
| user = json.parse(plugin.raw, null, strip); | ||
| } | ||
| catch (error) { | ||
| if (error instanceof SyntaxError) { | ||
| return [{ | ||
| dataPath: '', keyword: 'syntax', schemaPath: '', | ||
| message: error.message | ||
| }]; | ||
| } | ||
| var column = error.column, description = error.description; | ||
| var line = error.lineNumber; | ||
| return [{ | ||
| dataPath: '', keyword: 'parse', schemaPath: '', | ||
| message: description + " (line " + line + " column " + column + ")" | ||
| }]; | ||
| } | ||
| if (!validate(user)) { | ||
| return validate.errors; | ||
| } | ||
| // Copy the user data before merging defaults into composite map. | ||
| var composite = copy(user); | ||
| if (!compose(composite)) { | ||
| return compose.errors; | ||
| } | ||
| if (populate) { | ||
| plugin.data = { composite: composite, user: user }; | ||
| } | ||
| return null; | ||
| }; | ||
| /** | ||
| * Add a schema to the validator. | ||
@@ -54,3 +120,3 @@ * | ||
| */ | ||
| DefaultSchemaValidator.prototype.addSchema = function (plugin, schema) { | ||
| DefaultSchemaValidator.prototype._addSchema = function (plugin, schema) { | ||
| var composer = this._composer; | ||
@@ -75,30 +141,2 @@ var validator = this._validator; | ||
| }; | ||
| /** | ||
| * Validate a plugin's schema and user data; populate the `composite` data. | ||
| * | ||
| * @param plugin - The plugin being validated. Its `composite` data will be | ||
| * populated by reference. | ||
| * | ||
| * @return A list of errors if either the schema or data fail to validate or | ||
| * `null` if there are no errors. | ||
| */ | ||
| DefaultSchemaValidator.prototype.validateData = function (plugin) { | ||
| var validate = this._validator.getSchema(plugin.id); | ||
| var compose = this._composer.getSchema(plugin.id); | ||
| if (!validate || !compose) { | ||
| var errors = this.addSchema(plugin.id, plugin.schema); | ||
| if (errors) { | ||
| return errors; | ||
| } | ||
| } | ||
| if (!validate(plugin.data.user)) { | ||
| return validate.errors; | ||
| } | ||
| // Copy the user data before validating (and merging defaults). | ||
| plugin.data.composite = copy(plugin.data.user); | ||
| if (!compose(plugin.data.composite)) { | ||
| return compose.errors; | ||
| } | ||
| return null; | ||
| }; | ||
| return DefaultSchemaValidator; | ||
@@ -110,3 +148,3 @@ }()); | ||
| */ | ||
| var SettingRegistry = (function () { | ||
| var SettingRegistry = /** @class */ (function () { | ||
| /** | ||
@@ -123,3 +161,3 @@ * Create a new setting registry. | ||
| this._connector = options.connector; | ||
| this._validator = options.validator || new DefaultSchemaValidator(); | ||
| this.validator = options.validator || new DefaultSchemaValidator(); | ||
| } | ||
@@ -163,4 +201,4 @@ Object.defineProperty(SettingRegistry.prototype, "pluginChanged", { | ||
| var result = { | ||
| composite: key in composite ? copy(composite[key]) : void 0, | ||
| user: key in user ? copy(user[key]) : void 0 | ||
| composite: key in composite ? copy(composite[key]) : undefined, | ||
| user: key in user ? copy(user[key]) : undefined | ||
| }; | ||
@@ -202,2 +240,3 @@ return Promise.resolve(result); | ||
| var plugins = this._plugins; | ||
| var registry = this; | ||
| // If the plugin needs to be loaded from the connector, fetch. | ||
@@ -221,6 +260,3 @@ return connector.fetch(plugin).then(function (data) { | ||
| _this._pluginChanged.emit(plugin); | ||
| return new Settings({ | ||
| plugin: copy(plugins[plugin]), | ||
| registry: _this | ||
| }); | ||
| return new Settings({ plugin: plugins[plugin], registry: registry }); | ||
| }); | ||
@@ -240,5 +276,9 @@ }; | ||
| if (!(plugin in plugins)) { | ||
| return Promise.resolve(void 0); | ||
| return Promise.resolve(undefined); | ||
| } | ||
| delete plugins[plugin].data.user[key]; | ||
| var raw = json.parse(plugins[plugin].raw); | ||
| // Delete both the value and any associated comment. | ||
| delete raw[key]; | ||
| delete raw["// " + key]; | ||
| plugins[plugin].raw = json.stringify(raw); | ||
| return this._save(plugin); | ||
@@ -264,4 +304,6 @@ }; | ||
| } | ||
| plugins[plugin].data.user[key] = value; | ||
| var raw = json.parse(plugins[plugin].raw); | ||
| plugins[plugin].raw = json.stringify(__assign({}, raw, (_a = {}, _a[key] = value, _a))); | ||
| return this._save(plugin); | ||
| var _a; | ||
| }; | ||
@@ -271,22 +313,16 @@ /** | ||
| * | ||
| * @param plugin - The name of the plugin whose settings are being set. | ||
| * | ||
| * @param raw - The raw plugin settings being uploaded. | ||
| * | ||
| * @returns A promise that resolves when the settings have been saved. | ||
| * | ||
| * #### Notes | ||
| * Only the `user` data will be saved. | ||
| */ | ||
| SettingRegistry.prototype.upload = function (raw) { | ||
| SettingRegistry.prototype.upload = function (plugin, raw) { | ||
| var _this = this; | ||
| var plugins = this._plugins; | ||
| var plugin = raw.id; | ||
| var errors = null; | ||
| // Validate the user data and create the composite data. | ||
| raw.data.user = raw.data.user || {}; | ||
| delete raw.data.composite; | ||
| errors = this._validator.validateData(raw); | ||
| if (errors) { | ||
| return Promise.reject(errors); | ||
| if (!(plugin in plugins)) { | ||
| return this.load(plugin).then(function () { return _this.upload(plugin, raw); }); | ||
| } | ||
| // Set the local copy. | ||
| plugins[plugin] = raw; | ||
| plugins[plugin].raw = raw; | ||
| return this._save(plugin); | ||
@@ -301,6 +337,14 @@ }; | ||
| if (!(plugin in plugins)) { | ||
| return Promise.reject(plugin + " does not exist in setting registry."); | ||
| var message = plugin + " does not exist in setting registry."; | ||
| return Promise.reject(new Error(message)); | ||
| } | ||
| this._validate(plugins[plugin]); | ||
| return this._connector.save(plugin, plugins[plugin].data.user) | ||
| try { | ||
| this._validate(plugins[plugin]); | ||
| } | ||
| catch (errors) { | ||
| var message = plugin + " failed to validate; check console for errors."; | ||
| console.warn(plugin + " validation errors:", errors); | ||
| return Promise.reject(new Error(message)); | ||
| } | ||
| return this._connector.save(plugin, plugins[plugin].raw) | ||
| .then(function () { _this._pluginChanged.emit(plugin); }); | ||
@@ -312,12 +356,4 @@ }; | ||
| SettingRegistry.prototype._validate = function (plugin) { | ||
| var errors = null; | ||
| // Add the schema to the registry. | ||
| errors = this._validator.addSchema(plugin.id, plugin.schema); | ||
| if (errors) { | ||
| throw errors; | ||
| } | ||
| // Validate the user data and create the composite data. | ||
| plugin.data.user = plugin.data.user || {}; | ||
| delete plugin.data.composite; | ||
| errors = this._validator.validateData(plugin); | ||
| var errors = this.validator.validateData(plugin); | ||
| if (errors) { | ||
@@ -335,3 +371,3 @@ throw errors; | ||
| */ | ||
| var Settings = (function () { | ||
| var Settings = /** @class */ (function () { | ||
| /** | ||
@@ -344,2 +380,3 @@ * Instantiate a new plugin settings manager. | ||
| this._isDisposed = false; | ||
| this._raw = '{ }'; | ||
| this._schema = Object.create(null); | ||
@@ -351,2 +388,3 @@ this._user = Object.create(null); | ||
| this._composite = plugin.data.composite || {}; | ||
| this._raw = plugin.raw || '{ }'; | ||
| this._schema = plugin.schema || { type: 'object' }; | ||
@@ -396,2 +434,12 @@ this._user = plugin.data.user || {}; | ||
| }); | ||
| Object.defineProperty(Settings.prototype, "raw", { | ||
| /** | ||
| * Get the plugin settings raw text value. | ||
| */ | ||
| get: function () { | ||
| return this._raw; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| Object.defineProperty(Settings.prototype, "user", { | ||
@@ -447,4 +495,4 @@ /** | ||
| return { | ||
| composite: key in composite ? copy(composite[key]) : void 0, | ||
| user: key in user ? copy(user[key]) : void 0 | ||
| composite: key in composite ? copy(composite[key]) : undefined, | ||
| user: key in user ? copy(user[key]) : undefined | ||
| }; | ||
@@ -468,8 +516,4 @@ }; | ||
| */ | ||
| Settings.prototype.save = function (user) { | ||
| return this.registry.upload({ | ||
| id: this.plugin, | ||
| data: { composite: this._composite, user: user }, | ||
| schema: this._schema | ||
| }); | ||
| Settings.prototype.save = function (raw) { | ||
| return this.registry.upload(this.plugin, raw); | ||
| }; | ||
@@ -492,2 +536,16 @@ /** | ||
| /** | ||
| * Validates raw settings with comments. | ||
| * | ||
| * @param raw - The JSON with comments string being validated. | ||
| * | ||
| * @returns A list of errors or `null` if valid. | ||
| */ | ||
| Settings.prototype.validate = function (raw) { | ||
| var data = { composite: {}, user: {} }; | ||
| var id = this.plugin; | ||
| var schema = this._schema; | ||
| var validator = this.registry.validator; | ||
| return validator.validateData({ data: data, id: id, raw: raw, schema: schema }, false); | ||
| }; | ||
| /** | ||
| * Handle plugin changes in the setting registry. | ||
@@ -502,7 +560,8 @@ */ | ||
| var _a = found.data, composite = _a.composite, user = _a.user; | ||
| var schema = found.schema; | ||
| var raw = found.raw, schema = found.schema; | ||
| this._composite = composite || {}; | ||
| this._raw = raw; | ||
| this._schema = schema || { type: 'object' }; | ||
| this._user = user || {}; | ||
| this._changed.emit(void 0); | ||
| this._changed.emit(undefined); | ||
| } | ||
@@ -535,2 +594,6 @@ }; | ||
| /** | ||
| * The default indentation level, uses spaces instead of tabs. | ||
| */ | ||
| var indent = ' '; | ||
| /** | ||
| * Replacement text for schema properties missing a `description` field. | ||
@@ -553,2 +616,3 @@ */ | ||
| var keys = Object.keys(properties).sort(function (a, b) { return a.localeCompare(b); }); | ||
| var length = Math.max((description || nondescript).length, plugin.length); | ||
| return [ | ||
@@ -559,3 +623,3 @@ '{', | ||
| prefix(description || nondescript), | ||
| prefix(line((description || nondescript).length)), | ||
| prefix(line(length)), | ||
| '', | ||
@@ -574,3 +638,3 @@ keys.map(function (key) { return docstring(schema, key); }).join('\n\n'), | ||
| var defaults = reified === undefined ? prefix("\"" + key + "\": " + undefaulted) | ||
| : prefix("\"" + key + "\": " + JSON.stringify(reified, null, 2), ' '); | ||
| : prefix("\"" + key + "\": " + JSON.stringify(reified, null, 2), indent); | ||
| return [ | ||
@@ -593,3 +657,3 @@ prefix("" + (title || untitled)), | ||
| function prefix(source, pre) { | ||
| if (pre === void 0) { pre = ' \/\/ '; } | ||
| if (pre === void 0) { pre = indent + "// "; } | ||
| return pre + source.split('\n').join("\n" + pre); | ||
@@ -618,2 +682,1 @@ } | ||
| })(Private = exports.Private || (exports.Private = {})); | ||
| //# sourceMappingURL=settingregistry.js.map |
+6
-6
@@ -1,3 +0,3 @@ | ||
| import { ReadonlyJSONObject, Token } from '@phosphor/coreutils'; | ||
| import { IDataConnector } from '.'; | ||
| import { ReadonlyJSONValue, Token } from '@phosphor/coreutils'; | ||
| import { IDataConnector } from './interfaces'; | ||
| /** | ||
@@ -18,3 +18,3 @@ * The default state database token. | ||
| */ | ||
| value: ReadonlyJSONObject; | ||
| value: ReadonlyJSONValue; | ||
| } | ||
@@ -24,3 +24,3 @@ /** | ||
| */ | ||
| export interface IStateDB extends IDataConnector<ReadonlyJSONObject> { | ||
| export interface IStateDB extends IDataConnector<ReadonlyJSONValue> { | ||
| /** | ||
@@ -101,3 +101,3 @@ * The maximum allowed length of the data after it has been serialized. | ||
| */ | ||
| fetch(id: string): Promise<ReadonlyJSONObject | undefined>; | ||
| fetch(id: string): Promise<ReadonlyJSONValue | undefined>; | ||
| /** | ||
@@ -144,3 +144,3 @@ * Retrieve all the saved bundles for a namespace. | ||
| */ | ||
| save(id: string, value: ReadonlyJSONObject): Promise<void>; | ||
| save(id: string, value: ReadonlyJSONValue): Promise<void>; | ||
| } | ||
@@ -147,0 +147,0 @@ /** |
+10
-8
@@ -14,3 +14,3 @@ "use strict"; | ||
| */ | ||
| var StateDB = (function () { | ||
| var StateDB = /** @class */ (function () { | ||
| /** | ||
@@ -40,3 +40,3 @@ * Create a new state database. | ||
| } | ||
| return Promise.resolve(void 0); | ||
| return Promise.resolve(undefined); | ||
| }; | ||
@@ -67,3 +67,4 @@ /** | ||
| try { | ||
| return Promise.resolve(JSON.parse(value)); | ||
| var envelope = JSON.parse(value); | ||
| return Promise.resolve(envelope.v); | ||
| } | ||
@@ -100,5 +101,6 @@ catch (error) { | ||
| try { | ||
| var envelope = JSON.parse(value); | ||
| items.push({ | ||
| id: key.replace(regex, ''), | ||
| value: value ? JSON.parse(value) : undefined | ||
| value: envelope ? envelope.v : undefined | ||
| }); | ||
@@ -123,3 +125,3 @@ } | ||
| window.localStorage.removeItem(this.namespace + ":" + id); | ||
| return Promise.resolve(void 0); | ||
| return Promise.resolve(undefined); | ||
| }; | ||
@@ -145,3 +147,4 @@ /** | ||
| var key = this.namespace + ":" + id; | ||
| var serialized = JSON.stringify(value); | ||
| var envelope = { v: value }; | ||
| var serialized = JSON.stringify(envelope); | ||
| var length_1 = serialized.length; | ||
@@ -153,3 +156,3 @@ var max = this.maxLength; | ||
| window.localStorage.setItem(key, serialized); | ||
| return Promise.resolve(void 0); | ||
| return Promise.resolve(undefined); | ||
| } | ||
@@ -163,2 +166,1 @@ catch (error) { | ||
| exports.StateDB = StateDB; | ||
| //# sourceMappingURL=statedb.js.map |
+0
-1
@@ -75,2 +75,1 @@ "use strict"; | ||
| })(Text = exports.Text || (exports.Text = {})); | ||
| //# sourceMappingURL=text.js.map |
+0
-1
@@ -39,2 +39,1 @@ "use strict"; | ||
| })(Time = exports.Time || (exports.Time = {})); | ||
| //# sourceMappingURL=time.js.map |
+0
-1
@@ -99,2 +99,1 @@ "use strict"; | ||
| })(URLExt = exports.URLExt || (exports.URLExt = {})); | ||
| //# sourceMappingURL=url.js.map |
+0
-1
@@ -21,2 +21,1 @@ "use strict"; | ||
| exports.uuid = uuid; | ||
| //# sourceMappingURL=uuid.js.map |
+5
-3
| { | ||
| "name": "@jupyterlab/coreutils", | ||
| "version": "0.12.0", | ||
| "version": "0.13.0", | ||
| "description": "JupyterLab - Core Utilities", | ||
@@ -28,2 +28,3 @@ "homepage": "https://github.com/jupyterlab/jupyterlab", | ||
| "clean": "rimraf lib", | ||
| "prepublishOnly": "npm run build", | ||
| "watch": "tsc -w" | ||
@@ -35,5 +36,5 @@ }, | ||
| "@phosphor/disposable": "^1.1.2", | ||
| "@phosphor/messaging": "^1.2.2", | ||
| "@phosphor/signaling": "^1.2.2", | ||
| "ajv": "~5.1.6", | ||
| "comment-json": "^1.1.3", | ||
| "minimist": "~1.2.0", | ||
@@ -45,6 +46,7 @@ "moment": "~2.17.1", | ||
| "devDependencies": { | ||
| "@types/comment-json": "^1.1.0", | ||
| "@types/minimist": "~1.2.0", | ||
| "rimraf": "~2.6.2", | ||
| "typescript": "~2.4.2" | ||
| "typescript": "~2.6.2" | ||
| } | ||
| } |
+2
-2
| # @jupyterlab/coreutils | ||
| A JupyterLab package which provides utility functions and data structures that are widely used across many | ||
| of the `@jupyterlab` packages. This includes (among other things) functions for manipulating paths, urls, strings, lists, and maps. | ||
| A JupyterLab package which provides utility functions that are widely used across many | ||
| of the `@jupyterlab` packages. This includes (among other things) functions for manipulating paths, urls, and the notebook format. |
| {"version":3,"file":"activitymonitor.js","sourceRoot":"","sources":["../../../../coreutils/src/activitymonitor.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAM3D,iDAE6B;AAG7B;;GAEG;AACH;IAEE;;OAEG;IACH,yBAAY,OAA+C;QA0DnD,WAAM,GAAG,CAAC,CAAC,CAAC;QACZ,aAAQ,GAAG,CAAC,CAAC,CAAC;QAGd,gBAAW,GAAG,KAAK,CAAC;QACpB,qBAAgB,GAAG,IAAI,kBAAM,CAAiD,IAAI,CAAC,CAAC;QA9D1F,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC;IAC1C,CAAC;IAKD,sBAAI,4CAAe;QAHnB;;WAEG;aACH;YACE,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC;QAC/B,CAAC;;;OAAA;IAKD,sBAAI,oCAAO;QAHX;;WAEG;aACH;YACE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;QACvB,CAAC;aACD,UAAY,KAAa;YACvB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACxB,CAAC;;;OAHA;IAWD,sBAAI,uCAAU;QANd;;;;;WAKG;aACH;YACE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;;;OAAA;IAED;;OAEG;IACH,iCAAO,GAAP;QACE,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;YACrB,MAAM,CAAC;QACT,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,kBAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACK,wCAAc,GAAtB,UAAuB,MAAc,EAAE,IAAU;QAAjD,iBAUC;QATC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC;YAC9B,KAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBACzB,MAAM,EAAE,KAAI,CAAC,OAAO;gBACpB,IAAI,EAAE,KAAI,CAAC,KAAK;aACjB,CAAC,CAAC;QACL,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;IAQH,sBAAC;AAAD,CAAC,AArED,IAqEC;AApEK,0CAAe","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport {\n IDisposable\n} from '@phosphor/disposable';\n\nimport {\n ISignal, Signal\n} from '@phosphor/signaling';\n\n\n/**\n * A class that monitors activity on a signal.\n */\nexport\nclass ActivityMonitor<Sender, Args> implements IDisposable {\n /**\n * Construct a new activity monitor.\n */\n constructor(options: ActivityMonitor.IOptions<Sender, Args>) {\n options.signal.connect(this._onSignalFired, this);\n this._timeout = options.timeout || 1000;\n }\n\n /**\n * A signal emitted when activity has ceased.\n */\n get activityStopped(): ISignal<this, ActivityMonitor.IArguments<Sender, Args>> {\n return this._activityStopped;\n }\n\n /**\n * The timeout associated with the monitor, in milliseconds.\n */\n get timeout(): number {\n return this._timeout;\n }\n set timeout(value: number) {\n this._timeout = value;\n }\n\n /**\n * Test whether the monitor has been disposed.\n *\n * #### Notes\n * This is a read-only property.\n */\n get isDisposed(): boolean {\n return this._isDisposed;\n }\n\n /**\n * Dispose of the resources used by the activity monitor.\n */\n dispose(): void {\n if (this._isDisposed) {\n return;\n }\n this._isDisposed = true;\n Signal.clearData(this);\n }\n\n /**\n * A signal handler for the monitored signal.\n */\n private _onSignalFired(sender: Sender, args: Args): void {\n clearTimeout(this._timer);\n this._sender = sender;\n this._args = args;\n this._timer = window.setTimeout(() => {\n this._activityStopped.emit({\n sender: this._sender,\n args: this._args\n });\n }, this._timeout);\n }\n\n private _timer = -1;\n private _timeout = -1;\n private _sender: Sender;\n private _args: Args;\n private _isDisposed = false;\n private _activityStopped = new Signal<this, ActivityMonitor.IArguments<Sender, Args>>(this);\n}\n\n\n/**\n * The namespace for `ActivityMonitor` statics.\n */\nexport\nnamespace ActivityMonitor {\n /**\n * The options used to construct a new `ActivityMonitor`.\n */\n export\n interface IOptions<Sender, Args> {\n /**\n * The signal to monitor.\n */\n signal: ISignal<Sender, Args>;\n\n /**\n * The activity timeout in milliseconds.\n *\n * The default is 1 second.\n */\n timeout?: number;\n }\n\n /**\n * The argument object for an activity timeout.\n *\n */\n export\n interface IArguments<Sender, Args> {\n /**\n * The most recent sender object.\n */\n sender: Sender;\n\n /**\n * The most recent argument object.\n */\n args: Args;\n }\n}\n"]} |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../coreutils/src/index.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;;;;AAE3D,uCAAkC;AAElC,0CAAqC;AACrC,+BAA0B;AAC1B,gCAA2B;AAC3B,sCAAiC;AACjC,sCAAiC;AACjC,qCAAgC;AAChC,wCAAmC;AACnC,kCAA6B;AAC7B,4BAAuB;AACvB,uCAAkC;AAClC,+BAA0B;AAC1B,4BAAuB;AACvB,4BAAuB;AACvB,oCAA+B;AAC/B,2BAAsB;AACtB,4BAAuB","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nexport * from './activitymonitor';\nexport * from './interfaces';\nexport * from './markdowncodeblocks';\nexport * from './modeldb';\nexport * from './nbformat';\nexport * from './observablejson';\nexport * from './observablelist';\nexport * from './observablemap';\nexport * from './observablestring';\nexport * from './pageconfig';\nexport * from './path';\nexport * from './settingregistry';\nexport * from './statedb';\nexport * from './text';\nexport * from './time';\nexport * from './undoablelist';\nexport * from './url';\nexport * from './uuid';\n"]} |
| {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../coreutils/src/interfaces.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\n\n/**\n * A generic interface for change emitter payloads.\n */\nexport\ninterface IChangedArgs<T> {\n /**\n * The name of the changed attribute.\n */\n name: string;\n\n /**\n * The old value of the changed attribute.\n */\n oldValue: T;\n\n /**\n * The new value of the changed attribute.\n */\n newValue: T;\n}\n\n\n/**\n * The description of a general purpose data connector.\n */\nexport\ninterface IDataConnector<T, U = T> {\n /**\n * Retrieve a saved bundle from the data connector.\n *\n * @param id - The identifier used to retrieve a data bundle.\n *\n * @returns A promise that bears a data payload if available.\n *\n * #### Notes\n * The promise returned by this method may be rejected if an error\n * occurs in retrieving the data. Non-existence of an `id` will\n * succeed with `undefined`.\n */\n fetch(id: string): Promise<T | undefined>;\n\n /**\n * Remove a value from the data connector.\n *\n * @param id - The identifier for the data being removed.\n *\n * @returns A promise that is rejected if remove fails and succeeds otherwise.\n */\n remove(id: string): Promise<void>;\n\n /**\n * Save a value in the data connector.\n *\n * @param id - The identifier for the data being saved.\n *\n * @param value - The data being saved.\n *\n * @returns A promise that is rejected if saving fails and succeeds otherwise.\n */\n save(id: string, value: U): Promise<void>;\n}\n"]} |
| {"version":3,"file":"markdowncodeblocks.js","sourceRoot":"","sources":["../../../../coreutils/src/markdowncodeblocks.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D;;;GAGG;AACH,IACU,kBAAkB,CA+F3B;AAhGD,WACU,kBAAkB;IAEpB,oCAAiB,GAAG,KAAK,CAAC;IAChC,IAAM,kBAAkB,GAAa;QACnC,WAAW;QACX,QAAQ;QACR,OAAO;QACP,KAAK;QACL,MAAM;QACN,OAAO;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terms of the Modified BSD License.\n\n/**\n * The namespace for code block functions which help\n * in extract code from markdown text\n */\nexport\nnamespace MarkdownCodeBlocks {\n export\n const CODE_BLOCK_MARKER = \"```\";\n const markdownExtensions: string[] = [\n '.markdown',\n '.mdown',\n '.mkdn',\n '.md',\n '.mkd',\n '.mdwn',\n '.mdtxt',\n '.mdtext',\n '.text',\n '.txt',\n '.Rmd'\n ];\n\n export\n class MarkdownCodeBlock {\n startLine: number;\n endLine: number;\n code: string;\n constructor(startLine: number) {\n this.startLine = startLine;\n this.code = \"\";\n this.endLine = -1;\n }\n }\n\n /**\n * Check whether the given file extension is a markdown extension\n * @param extension - A file extension\n *\n * @returns true/false depending on whether this is a supported markdown extension\n */\n export\n function isMarkdown(extension: string): boolean {\n return markdownExtensions.indexOf(extension) > -1\n }\n\n /**\n * Construct all code snippets from current text\n * (this could be potentially optimized if we can cache and detect differences)\n * @param text - A string to parse codeblocks from\n *\n * @returns An array of MarkdownCodeBlocks.\n */\n export\n function findMarkdownCodeBlocks(text: string): MarkdownCodeBlock[] {\n if (!text || text == '') {\n return [];\n }\n\n const lines = text.split(\"\\n\");\n const codeBlocks: MarkdownCodeBlock[] = [];\n var currentBlock = null;\n for (var lineIndex = 0; lineIndex < lines.length; lineIndex++) {\n const line = lines[lineIndex];\n const lineContainsMarker = line.indexOf(CODE_BLOCK_MARKER) === 0;\n const constructingBlock = currentBlock != null;\n // Skip this line if it is not part of any code block and doesn't contain a marker.\n if (!lineContainsMarker && !constructingBlock) {\n continue;\n }\n\n // Check if we are already constructing a code block.\n if (!constructingBlock) {\n // Start constructing a new code block.\n currentBlock = new MarkdownCodeBlock(lineIndex);\n\n // Check whether this is a single line code block of the form ```a = 10```.\n const firstIndex = line.indexOf(CODE_BLOCK_MARKER);\n const lastIndex = line.lastIndexOf(CODE_BLOCK_MARKER);\n const isSingleLine = firstIndex !== lastIndex;\n if (isSingleLine) {\n currentBlock.code = line.substring(firstIndex + CODE_BLOCK_MARKER.length, lastIndex);\n currentBlock.endLine = lineIndex;\n codeBlocks.push(currentBlock);\n currentBlock = null;\n }\n } else if (currentBlock) {\n if (lineContainsMarker) {\n // End of block, finish it up.\n currentBlock.endLine = lineIndex - 1;\n codeBlocks.push(currentBlock);\n currentBlock = null;\n } else {\n // Append the current line.\n currentBlock.code += line + '\\n';\n }\n }\n }\n return codeBlocks;\n }\n\n}\n"]} |
-427
| import { IDisposable } from '@phosphor/disposable'; | ||
| import { ISignal } from '@phosphor/signaling'; | ||
| import { JSONValue, JSONObject } from '@phosphor/coreutils'; | ||
| import { IObservableJSON } from './observablejson'; | ||
| import { IObservableString } from './observablestring'; | ||
| import { IObservableUndoableList } from './undoablelist'; | ||
| import { IObservableMap } from './observablemap'; | ||
| /** | ||
| * String type annotations for Observable objects that can be | ||
| * created and placed in the IModelDB interface. | ||
| */ | ||
| export declare type ObservableType = 'Map' | 'List' | 'String' | 'Value'; | ||
| /** | ||
| * Base interface for Observable objects. | ||
| */ | ||
| export interface IObservable extends IDisposable { | ||
| /** | ||
| * The type of this object. | ||
| */ | ||
| readonly type: ObservableType; | ||
| } | ||
| /** | ||
| * Interface for an Observable object that represents | ||
| * an opaque JSON value. | ||
| */ | ||
| export interface IObservableValue extends IObservable { | ||
| /** | ||
| * The type of this object. | ||
| */ | ||
| readonly type: 'Value'; | ||
| /** | ||
| * The changed signal. | ||
| */ | ||
| readonly changed: ISignal<IObservableValue, ObservableValue.IChangedArgs>; | ||
| /** | ||
| * Get the current value, or `undefined` if it has not been set. | ||
| */ | ||
| get(): JSONValue | undefined; | ||
| /** | ||
| * Set the value. | ||
| */ | ||
| set(value: JSONValue): void; | ||
| } | ||
| /** | ||
| * Interface for an object representing a single collaborator | ||
| * on a realtime model. | ||
| */ | ||
| export interface ICollaborator extends JSONObject { | ||
| /** | ||
| * A user id for the collaborator. | ||
| * This might not be unique, if the user has more than | ||
| * one editing session at a time. | ||
| */ | ||
| readonly userId: string; | ||
| /** | ||
| * A session id, which should be unique to a | ||
| * particular view on a collaborative model. | ||
| */ | ||
| readonly sessionId: string; | ||
| /** | ||
| * A human-readable display name for a collaborator. | ||
| */ | ||
| readonly displayName: string; | ||
| /** | ||
| * A color to be used to identify the collaborator in | ||
| * UI elements. | ||
| */ | ||
| readonly color: string; | ||
| /** | ||
| * A human-readable short name for a collaborator, for | ||
| * use in places where the full `displayName` would take | ||
| * too much space. | ||
| */ | ||
| readonly shortName: string; | ||
| } | ||
| /** | ||
| * Interface for an IObservableMap that tracks collaborators. | ||
| */ | ||
| export interface ICollaboratorMap extends IObservableMap<ICollaborator> { | ||
| /** | ||
| * The local collaborator on a model. | ||
| */ | ||
| readonly localCollaborator: ICollaborator; | ||
| } | ||
| /** | ||
| * An interface for a path based database for | ||
| * creating and storing values, which is agnostic | ||
| * to the particular type of store in the backend. | ||
| */ | ||
| export interface IModelDB extends IDisposable { | ||
| /** | ||
| * The base path for the `IModelDB`. This is prepended | ||
| * to all the paths that are passed in to the member | ||
| * functions of the object. | ||
| */ | ||
| readonly basePath: string; | ||
| /** | ||
| * Whether the database has been disposed. | ||
| */ | ||
| readonly isDisposed: boolean; | ||
| /** | ||
| * Whether the database has been populated | ||
| * with model values prior to connection. | ||
| */ | ||
| readonly isPrepopulated: boolean; | ||
| /** | ||
| * Whether the database is collaborative. | ||
| */ | ||
| readonly isCollaborative: boolean; | ||
| /** | ||
| * A promise that resolves when the database | ||
| * has connected to its backend, if any. | ||
| */ | ||
| readonly connected: Promise<void>; | ||
| /** | ||
| * A map of the currently active collaborators | ||
| * for the database, including the local user. | ||
| */ | ||
| readonly collaborators?: ICollaboratorMap; | ||
| /** | ||
| * Get a value for a path. | ||
| * | ||
| * @param path: the path for the object. | ||
| * | ||
| * @returns an `IObservable`. | ||
| */ | ||
| get(path: string): IObservable | undefined; | ||
| /** | ||
| * Whether the `IModelDB` has an object at this path. | ||
| * | ||
| * @param path: the path for the object. | ||
| * | ||
| * @returns a boolean for whether an object is at `path`. | ||
| */ | ||
| has(path: string): boolean; | ||
| /** | ||
| * Create a string and insert it in the database. | ||
| * | ||
| * @param path: the path for the string. | ||
| * | ||
| * @returns the string that was created. | ||
| */ | ||
| createString(path: string): IObservableString; | ||
| /** | ||
| * Create an undoable list and insert it in the database. | ||
| * | ||
| * @param path: the path for the list. | ||
| * | ||
| * @returns the list that was created. | ||
| * | ||
| * #### Notes | ||
| * The list can only store objects that are simple | ||
| * JSON Objects and primitives. | ||
| */ | ||
| createList<T extends JSONValue>(path: string): IObservableUndoableList<T>; | ||
| /** | ||
| * Create a map and insert it in the database. | ||
| * | ||
| * @param path: the path for the map. | ||
| * | ||
| * @returns the map that was created. | ||
| * | ||
| * #### Notes | ||
| * The map can only store objects that are simple | ||
| * JSON Objects and primitives. | ||
| */ | ||
| createMap(path: string): IObservableJSON; | ||
| /** | ||
| * Create an opaque value and insert it in the database. | ||
| * | ||
| * @param path: the path for the value. | ||
| * | ||
| * @returns the value that was created. | ||
| */ | ||
| createValue(path: string): IObservableValue; | ||
| /** | ||
| * Get a value at a path, or `undefined if it has not been set | ||
| * That value must already have been created using `createValue`. | ||
| * | ||
| * @param path: the path for the value. | ||
| */ | ||
| getValue(path: string): JSONValue | undefined; | ||
| /** | ||
| * Set a value at a path. That value must already have | ||
| * been created using `createValue`. | ||
| * | ||
| * @param path: the path for the value. | ||
| * | ||
| * @param value: the new value. | ||
| */ | ||
| setValue(path: string, value: JSONValue): void; | ||
| /** | ||
| * Create a view onto a subtree of the model database. | ||
| * | ||
| * @param basePath: the path for the root of the subtree. | ||
| * | ||
| * @returns an `IModelDB` with a view onto the original | ||
| * `IModelDB`, with `basePath` prepended to all paths. | ||
| */ | ||
| view(basePath: string): IModelDB; | ||
| /** | ||
| * Dispose of the resources held by the database. | ||
| */ | ||
| dispose(): void; | ||
| } | ||
| /** | ||
| * A concrete implementation of an `IObservableValue`. | ||
| */ | ||
| export declare class ObservableValue implements IObservableValue { | ||
| /** | ||
| * Constructor for the value. | ||
| * | ||
| * @param initialValue: the starting value for the `ObservableValue`. | ||
| */ | ||
| constructor(initialValue?: JSONValue); | ||
| /** | ||
| * The observable type. | ||
| */ | ||
| readonly type: 'Value'; | ||
| /** | ||
| * Whether the value has been disposed. | ||
| */ | ||
| readonly isDisposed: boolean; | ||
| /** | ||
| * The changed signal. | ||
| */ | ||
| readonly changed: ISignal<this, ObservableValue.IChangedArgs>; | ||
| /** | ||
| * Get the current value, or `undefined` if it has not been set. | ||
| */ | ||
| get(): JSONValue; | ||
| /** | ||
| * Set the current value. | ||
| */ | ||
| set(value: JSONValue): void; | ||
| /** | ||
| * Dispose of the resources held by the value. | ||
| */ | ||
| dispose(): void; | ||
| private _value; | ||
| private _changed; | ||
| private _isDisposed; | ||
| } | ||
| /** | ||
| * The namespace for the `ObservableValue` class statics. | ||
| */ | ||
| export declare namespace ObservableValue { | ||
| /** | ||
| * The changed args object emitted by the `IObservableValue`. | ||
| */ | ||
| class IChangedArgs { | ||
| /** | ||
| * The old value. | ||
| */ | ||
| oldValue: JSONValue | undefined; | ||
| /** | ||
| * The new value. | ||
| */ | ||
| newValue: JSONValue | undefined; | ||
| } | ||
| } | ||
| /** | ||
| * A concrete implementation of an `IModelDB`. | ||
| */ | ||
| export declare class ModelDB implements IModelDB { | ||
| /** | ||
| * Constructor for the `ModelDB`. | ||
| */ | ||
| constructor(options?: ModelDB.ICreateOptions); | ||
| /** | ||
| * The base path for the `ModelDB`. This is prepended | ||
| * to all the paths that are passed in to the member | ||
| * functions of the object. | ||
| */ | ||
| readonly basePath: string; | ||
| /** | ||
| * Whether the database is disposed. | ||
| */ | ||
| readonly isDisposed: boolean; | ||
| /** | ||
| * Whether the model has been populated with | ||
| * any model values. | ||
| */ | ||
| readonly isPrepopulated: boolean; | ||
| /** | ||
| * Whether the model is collaborative. | ||
| */ | ||
| readonly isCollaborative: boolean; | ||
| /** | ||
| * A promise resolved when the model is connected | ||
| * to its backend. For the in-memory ModelDB it | ||
| * is immediately resolved. | ||
| */ | ||
| readonly connected: Promise<void>; | ||
| /** | ||
| * Get a value for a path. | ||
| * | ||
| * @param path: the path for the object. | ||
| * | ||
| * @returns an `IObservable`. | ||
| */ | ||
| get(path: string): IObservable | undefined; | ||
| /** | ||
| * Whether the `IModelDB` has an object at this path. | ||
| * | ||
| * @param path: the path for the object. | ||
| * | ||
| * @returns a boolean for whether an object is at `path`. | ||
| */ | ||
| has(path: string): boolean; | ||
| /** | ||
| * Create a string and insert it in the database. | ||
| * | ||
| * @param path: the path for the string. | ||
| * | ||
| * @returns the string that was created. | ||
| */ | ||
| createString(path: string): IObservableString; | ||
| /** | ||
| * Create an undoable list and insert it in the database. | ||
| * | ||
| * @param path: the path for the list. | ||
| * | ||
| * @returns the list that was created. | ||
| * | ||
| * #### Notes | ||
| * The list can only store objects that are simple | ||
| * JSON Objects and primitives. | ||
| */ | ||
| createList<T extends JSONValue>(path: string): IObservableUndoableList<T>; | ||
| /** | ||
| * Create a map and insert it in the database. | ||
| * | ||
| * @param path: the path for the map. | ||
| * | ||
| * @returns the map that was created. | ||
| * | ||
| * #### Notes | ||
| * The map can only store objects that are simple | ||
| * JSON Objects and primitives. | ||
| */ | ||
| createMap(path: string): IObservableJSON; | ||
| /** | ||
| * Create an opaque value and insert it in the database. | ||
| * | ||
| * @param path: the path for the value. | ||
| * | ||
| * @returns the value that was created. | ||
| */ | ||
| createValue(path: string): IObservableValue; | ||
| /** | ||
| * Get a value at a path, or `undefined if it has not been set | ||
| * That value must already have been created using `createValue`. | ||
| * | ||
| * @param path: the path for the value. | ||
| */ | ||
| getValue(path: string): JSONValue | undefined; | ||
| /** | ||
| * Set a value at a path. That value must already have | ||
| * been created using `createValue`. | ||
| * | ||
| * @param path: the path for the value. | ||
| * | ||
| * @param value: the new value. | ||
| */ | ||
| setValue(path: string, value: JSONValue): void; | ||
| /** | ||
| * Create a view onto a subtree of the model database. | ||
| * | ||
| * @param basePath: the path for the root of the subtree. | ||
| * | ||
| * @returns an `IModelDB` with a view onto the original | ||
| * `IModelDB`, with `basePath` prepended to all paths. | ||
| */ | ||
| view(basePath: string): ModelDB; | ||
| /** | ||
| * Set a value at a path. Not intended to | ||
| * be called by user code, instead use the | ||
| * `create*` factory methods. | ||
| * | ||
| * @param path: the path to set the value at. | ||
| * | ||
| * @param value: the value to set at the path. | ||
| */ | ||
| set(path: string, value: IObservable): void; | ||
| /** | ||
| * Dispose of the resources held by the database. | ||
| */ | ||
| dispose(): void; | ||
| /** | ||
| * Compute the fully resolved path for a path argument. | ||
| */ | ||
| private _resolvePath(path); | ||
| private _basePath; | ||
| private _db; | ||
| private _toDispose; | ||
| private _isDisposed; | ||
| private _disposables; | ||
| } | ||
| /** | ||
| * A namespace for the `ModelDB` class statics. | ||
| */ | ||
| export declare namespace ModelDB { | ||
| /** | ||
| * Options for creating a `ModelDB` object. | ||
| */ | ||
| interface ICreateOptions { | ||
| /** | ||
| * The base path to prepend to all the path arguments. | ||
| */ | ||
| basePath?: string; | ||
| /** | ||
| * A ModelDB to use as the store for this | ||
| * ModelDB. If none is given, it uses its own store. | ||
| */ | ||
| baseDB?: ModelDB; | ||
| } | ||
| /** | ||
| * A factory interface for creating `IModelDB` objects. | ||
| */ | ||
| interface IFactory { | ||
| /** | ||
| * Create a new `IModelDB` instance. | ||
| */ | ||
| createNew(path: string): IModelDB; | ||
| } | ||
| } |
-319
| "use strict"; | ||
| // Copyright (c) Jupyter Development Team. | ||
| // Distributed under the terms of the Modified BSD License. | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var disposable_1 = require("@phosphor/disposable"); | ||
| var signaling_1 = require("@phosphor/signaling"); | ||
| var observablemap_1 = require("./observablemap"); | ||
| var observablejson_1 = require("./observablejson"); | ||
| var observablestring_1 = require("./observablestring"); | ||
| var undoablelist_1 = require("./undoablelist"); | ||
| /** | ||
| * A concrete implementation of an `IObservableValue`. | ||
| */ | ||
| var ObservableValue = (function () { | ||
| /** | ||
| * Constructor for the value. | ||
| * | ||
| * @param initialValue: the starting value for the `ObservableValue`. | ||
| */ | ||
| function ObservableValue(initialValue) { | ||
| if (initialValue === void 0) { initialValue = null; } | ||
| this._value = null; | ||
| this._changed = new signaling_1.Signal(this); | ||
| this._isDisposed = false; | ||
| this._value = initialValue; | ||
| } | ||
| Object.defineProperty(ObservableValue.prototype, "type", { | ||
| /** | ||
| * The observable type. | ||
| */ | ||
| get: function () { | ||
| return 'Value'; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| Object.defineProperty(ObservableValue.prototype, "isDisposed", { | ||
| /** | ||
| * Whether the value has been disposed. | ||
| */ | ||
| get: function () { | ||
| return this._isDisposed; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| Object.defineProperty(ObservableValue.prototype, "changed", { | ||
| /** | ||
| * The changed signal. | ||
| */ | ||
| get: function () { | ||
| return this._changed; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| /** | ||
| * Get the current value, or `undefined` if it has not been set. | ||
| */ | ||
| ObservableValue.prototype.get = function () { | ||
| return this._value; | ||
| }; | ||
| /** | ||
| * Set the current value. | ||
| */ | ||
| ObservableValue.prototype.set = function (value) { | ||
| var oldValue = this._value; | ||
| this._value = value; | ||
| this._changed.emit({ | ||
| oldValue: oldValue, | ||
| newValue: value | ||
| }); | ||
| }; | ||
| /** | ||
| * Dispose of the resources held by the value. | ||
| */ | ||
| ObservableValue.prototype.dispose = function () { | ||
| if (this._isDisposed) { | ||
| return; | ||
| } | ||
| this._isDisposed = true; | ||
| signaling_1.Signal.clearData(this); | ||
| this._value = null; | ||
| }; | ||
| return ObservableValue; | ||
| }()); | ||
| exports.ObservableValue = ObservableValue; | ||
| /** | ||
| * The namespace for the `ObservableValue` class statics. | ||
| */ | ||
| (function (ObservableValue) { | ||
| /** | ||
| * The changed args object emitted by the `IObservableValue`. | ||
| */ | ||
| var IChangedArgs = (function () { | ||
| function IChangedArgs() { | ||
| } | ||
| return IChangedArgs; | ||
| }()); | ||
| ObservableValue.IChangedArgs = IChangedArgs; | ||
| })(ObservableValue = exports.ObservableValue || (exports.ObservableValue = {})); | ||
| exports.ObservableValue = ObservableValue; | ||
| /** | ||
| * A concrete implementation of an `IModelDB`. | ||
| */ | ||
| var ModelDB = (function () { | ||
| /** | ||
| * Constructor for the `ModelDB`. | ||
| */ | ||
| function ModelDB(options) { | ||
| if (options === void 0) { options = {}; } | ||
| /** | ||
| * Whether the model has been populated with | ||
| * any model values. | ||
| */ | ||
| this.isPrepopulated = false; | ||
| /** | ||
| * Whether the model is collaborative. | ||
| */ | ||
| this.isCollaborative = false; | ||
| /** | ||
| * A promise resolved when the model is connected | ||
| * to its backend. For the in-memory ModelDB it | ||
| * is immediately resolved. | ||
| */ | ||
| this.connected = Promise.resolve(void 0); | ||
| this._toDispose = false; | ||
| this._isDisposed = false; | ||
| this._disposables = new disposable_1.DisposableSet(); | ||
| this._basePath = options.basePath || ''; | ||
| if (options.baseDB) { | ||
| this._db = options.baseDB; | ||
| } | ||
| else { | ||
| this._db = new observablemap_1.ObservableMap(); | ||
| this._toDispose = true; | ||
| } | ||
| } | ||
| Object.defineProperty(ModelDB.prototype, "basePath", { | ||
| /** | ||
| * The base path for the `ModelDB`. This is prepended | ||
| * to all the paths that are passed in to the member | ||
| * functions of the object. | ||
| */ | ||
| get: function () { | ||
| return this._basePath; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| Object.defineProperty(ModelDB.prototype, "isDisposed", { | ||
| /** | ||
| * Whether the database is disposed. | ||
| */ | ||
| get: function () { | ||
| return this._isDisposed; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| /** | ||
| * Get a value for a path. | ||
| * | ||
| * @param path: the path for the object. | ||
| * | ||
| * @returns an `IObservable`. | ||
| */ | ||
| ModelDB.prototype.get = function (path) { | ||
| return this._db.get(this._resolvePath(path)); | ||
| }; | ||
| /** | ||
| * Whether the `IModelDB` has an object at this path. | ||
| * | ||
| * @param path: the path for the object. | ||
| * | ||
| * @returns a boolean for whether an object is at `path`. | ||
| */ | ||
| ModelDB.prototype.has = function (path) { | ||
| return this._db.has(this._resolvePath(path)); | ||
| }; | ||
| /** | ||
| * Create a string and insert it in the database. | ||
| * | ||
| * @param path: the path for the string. | ||
| * | ||
| * @returns the string that was created. | ||
| */ | ||
| ModelDB.prototype.createString = function (path) { | ||
| var str = new observablestring_1.ObservableString(); | ||
| this._disposables.add(str); | ||
| this.set(path, str); | ||
| return str; | ||
| }; | ||
| /** | ||
| * Create an undoable list and insert it in the database. | ||
| * | ||
| * @param path: the path for the list. | ||
| * | ||
| * @returns the list that was created. | ||
| * | ||
| * #### Notes | ||
| * The list can only store objects that are simple | ||
| * JSON Objects and primitives. | ||
| */ | ||
| ModelDB.prototype.createList = function (path) { | ||
| var vec = new undoablelist_1.ObservableUndoableList(new undoablelist_1.ObservableUndoableList.IdentitySerializer()); | ||
| this._disposables.add(vec); | ||
| this.set(path, vec); | ||
| return vec; | ||
| }; | ||
| /** | ||
| * Create a map and insert it in the database. | ||
| * | ||
| * @param path: the path for the map. | ||
| * | ||
| * @returns the map that was created. | ||
| * | ||
| * #### Notes | ||
| * The map can only store objects that are simple | ||
| * JSON Objects and primitives. | ||
| */ | ||
| ModelDB.prototype.createMap = function (path) { | ||
| var map = new observablejson_1.ObservableJSON(); | ||
| this._disposables.add(map); | ||
| this.set(path, map); | ||
| return map; | ||
| }; | ||
| /** | ||
| * Create an opaque value and insert it in the database. | ||
| * | ||
| * @param path: the path for the value. | ||
| * | ||
| * @returns the value that was created. | ||
| */ | ||
| ModelDB.prototype.createValue = function (path) { | ||
| var val = new ObservableValue(); | ||
| this._disposables.add(val); | ||
| this.set(path, val); | ||
| return val; | ||
| }; | ||
| /** | ||
| * Get a value at a path, or `undefined if it has not been set | ||
| * That value must already have been created using `createValue`. | ||
| * | ||
| * @param path: the path for the value. | ||
| */ | ||
| ModelDB.prototype.getValue = function (path) { | ||
| var val = this.get(path); | ||
| if (!val || val.type !== 'Value') { | ||
| throw Error('Can only call getValue for an ObservableValue'); | ||
| } | ||
| return val.get(); | ||
| }; | ||
| /** | ||
| * Set a value at a path. That value must already have | ||
| * been created using `createValue`. | ||
| * | ||
| * @param path: the path for the value. | ||
| * | ||
| * @param value: the new value. | ||
| */ | ||
| ModelDB.prototype.setValue = function (path, value) { | ||
| var val = this.get(path); | ||
| if (!val || val.type !== 'Value') { | ||
| throw Error('Can only call setValue on an ObservableValue'); | ||
| } | ||
| val.set(value); | ||
| }; | ||
| /** | ||
| * Create a view onto a subtree of the model database. | ||
| * | ||
| * @param basePath: the path for the root of the subtree. | ||
| * | ||
| * @returns an `IModelDB` with a view onto the original | ||
| * `IModelDB`, with `basePath` prepended to all paths. | ||
| */ | ||
| ModelDB.prototype.view = function (basePath) { | ||
| var view = new ModelDB({ basePath: basePath, baseDB: this }); | ||
| this._disposables.add(view); | ||
| return view; | ||
| }; | ||
| /** | ||
| * Set a value at a path. Not intended to | ||
| * be called by user code, instead use the | ||
| * `create*` factory methods. | ||
| * | ||
| * @param path: the path to set the value at. | ||
| * | ||
| * @param value: the value to set at the path. | ||
| */ | ||
| ModelDB.prototype.set = function (path, value) { | ||
| this._db.set(this._resolvePath(path), value); | ||
| }; | ||
| /** | ||
| * Dispose of the resources held by the database. | ||
| */ | ||
| ModelDB.prototype.dispose = function () { | ||
| if (this.isDisposed) { | ||
| return; | ||
| } | ||
| this._isDisposed = true; | ||
| if (this._toDispose) { | ||
| this._db.dispose(); | ||
| } | ||
| this._disposables.dispose(); | ||
| }; | ||
| /** | ||
| * Compute the fully resolved path for a path argument. | ||
| */ | ||
| ModelDB.prototype._resolvePath = function (path) { | ||
| if (this._basePath) { | ||
| path = this._basePath + '.' + path; | ||
| } | ||
| return path; | ||
| }; | ||
| return ModelDB; | ||
| }()); | ||
| exports.ModelDB = ModelDB; | ||
| //# sourceMappingURL=modeldb.js.map |
| {"version":3,"file":"modeldb.js","sourceRoot":"","sources":["../../../../coreutils/src/modeldb.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;A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ED;;OAEG;IACH,yBAAO,GAAP;QACE,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;YACpB,MAAM,CAAC;QACT,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;YACpB,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACK,8BAAY,GAApB,UAAqB,IAAY;QAC/B,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;YACnB,IAAI,GAAG,IAAI,CAAC,SAAS,GAAG,GAAG,GAAG,IAAI,CAAC;QACrC,CAAC;QACD,MAAM,CAAC,IAAI,CAAC;IACd,CAAC;IAOH,cAAC;AAAD,CAAC,AA/ND,IA+NC;AA9NK,0BAAO","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport {\n IDisposable, DisposableSet\n} from '@phosphor/disposable';\n\nimport {\n ISignal, Signal\n} from '@phosphor/signaling';\n\nimport {\n JSONValue, JSONObject\n} from '@phosphor/coreutils';\n\nimport {\n ObservableMap\n} from './observablemap';\n\nimport {\n IObservableJSON, ObservableJSON\n} from './observablejson';\n\nimport {\n IObservableString, ObservableString\n} from './observablestring';\n\nimport {\n IObservableUndoableList, ObservableUndoableList\n} from './undoablelist';\n\nimport {\n IObservableMap\n} from './observablemap';\n\n\n/**\n * String type annotations for Observable objects that can be\n * created and placed in the IModelDB interface.\n */\nexport\ntype ObservableType = 'Map' | 'List' | 'String' | 'Value';\n\n\n/**\n * Base interface for Observable objects.\n */\nexport\ninterface IObservable extends IDisposable {\n /**\n * The type of this object.\n */\n readonly type: ObservableType;\n}\n\n\n/**\n * Interface for an Observable object that represents\n * an opaque JSON value.\n */\nexport\ninterface IObservableValue extends IObservable {\n /**\n * The type of this object.\n */\n readonly type: 'Value';\n\n /**\n * The changed signal.\n */\n readonly changed: ISignal<IObservableValue, ObservableValue.IChangedArgs>;\n\n /**\n * Get the current value, or `undefined` if it has not been set.\n */\n get(): JSONValue | undefined;\n\n /**\n * Set the value.\n */\n set(value: JSONValue): void;\n}\n\n\n/**\n * Interface for an object representing a single collaborator\n * on a realtime model.\n */\nexport\ninterface ICollaborator extends JSONObject {\n /**\n * A user id for the collaborator.\n * This might not be unique, if the user has more than\n * one editing session at a time.\n */\n readonly userId: string;\n\n /**\n * A session id, which should be unique to a\n * particular view on a collaborative model.\n */\n readonly sessionId: string;\n\n /**\n * A human-readable display name for a collaborator.\n */\n readonly displayName: string;\n\n /**\n * A color to be used to identify the collaborator in\n * UI elements.\n */\n readonly color: string;\n\n /**\n * A human-readable short name for a collaborator, for\n * use in places where the full `displayName` would take\n * too much space.\n */\n readonly shortName: string;\n}\n\n\n/**\n * Interface for an IObservableMap that tracks collaborators.\n */\nexport\ninterface ICollaboratorMap extends IObservableMap<ICollaborator> {\n /**\n * The local collaborator on a model.\n */\n readonly localCollaborator: ICollaborator;\n}\n\n\n/**\n * An interface for a path based database for\n * creating and storing values, which is agnostic\n * to the particular type of store in the backend.\n */\nexport\ninterface IModelDB extends IDisposable {\n /**\n * The base path for the `IModelDB`. This is prepended\n * to all the paths that are passed in to the member\n * functions of the object.\n */\n readonly basePath: string;\n\n /**\n * Whether the database has been disposed.\n */\n readonly isDisposed: boolean;\n\n /**\n * Whether the database has been populated\n * with model values prior to connection.\n */\n readonly isPrepopulated: boolean;\n\n /**\n * Whether the database is collaborative.\n */\n readonly isCollaborative: boolean;\n\n /**\n * A promise that resolves when the database\n * has connected to its backend, if any.\n */\n readonly connected: Promise<void>;\n\n /**\n * A map of the currently active collaborators\n * for the database, including the local user.\n */\n readonly collaborators?: ICollaboratorMap;\n\n /**\n * Get a value for a path.\n *\n * @param path: the path for the object.\n *\n * @returns an `IObservable`.\n */\n get(path: string): IObservable | undefined;\n\n /**\n * Whether the `IModelDB` has an object at this path.\n *\n * @param path: the path for the object.\n *\n * @returns a boolean for whether an object is at `path`.\n */\n has(path: string): boolean;\n\n /**\n * Create a string and insert it in the database.\n *\n * @param path: the path for the string.\n *\n * @returns the string that was created.\n */\n createString(path: string): IObservableString;\n\n /**\n * Create an undoable list and insert it in the database.\n *\n * @param path: the path for the list.\n *\n * @returns the list that was created.\n *\n * #### Notes\n * The list can only store objects that are simple\n * JSON Objects and primitives.\n */\n createList<T extends JSONValue>(path: string): IObservableUndoableList<T>;\n\n /**\n * Create a map and insert it in the database.\n *\n * @param path: the path for the map.\n *\n * @returns the map that was created.\n *\n * #### Notes\n * The map can only store objects that are simple\n * JSON Objects and primitives.\n */\n createMap(path: string): IObservableJSON;\n\n /**\n * Create an opaque value and insert it in the database.\n *\n * @param path: the path for the value.\n *\n * @returns the value that was created.\n */\n createValue(path: string): IObservableValue;\n\n /**\n * Get a value at a path, or `undefined if it has not been set\n * That value must already have been created using `createValue`.\n *\n * @param path: the path for the value.\n */\n getValue(path: string): JSONValue | undefined;\n\n /**\n * Set a value at a path. That value must already have\n * been created using `createValue`.\n *\n * @param path: the path for the value.\n *\n * @param value: the new value.\n */\n setValue(path: string, value: JSONValue): void;\n\n /**\n * Create a view onto a subtree of the model database.\n *\n * @param basePath: the path for the root of the subtree.\n *\n * @returns an `IModelDB` with a view onto the original\n * `IModelDB`, with `basePath` prepended to all paths.\n */\n view(basePath: string): IModelDB;\n\n /**\n * Dispose of the resources held by the database.\n */\n dispose(): void;\n}\n\n\n/**\n * A concrete implementation of an `IObservableValue`.\n */\nexport\nclass ObservableValue implements IObservableValue {\n /**\n * Constructor for the value.\n *\n * @param initialValue: the starting value for the `ObservableValue`.\n */\n constructor(initialValue: JSONValue = null) {\n this._value = initialValue;\n }\n\n /**\n * The observable type.\n */\n get type(): 'Value' {\n return 'Value';\n }\n\n /**\n * Whether the value has been disposed.\n */\n get isDisposed(): boolean {\n return this._isDisposed;\n }\n\n /**\n * The changed signal.\n */\n get changed(): ISignal<this, ObservableValue.IChangedArgs> {\n return this._changed;\n }\n\n /**\n * Get the current value, or `undefined` if it has not been set.\n */\n get(): JSONValue {\n return this._value;\n }\n\n /**\n * Set the current value.\n */\n set(value: JSONValue): void {\n let oldValue = this._value;\n this._value = value;\n this._changed.emit({\n oldValue: oldValue,\n newValue: value\n });\n }\n\n /**\n * Dispose of the resources held by the value.\n */\n dispose(): void {\n if (this._isDisposed) {\n return;\n }\n this._isDisposed = true;\n Signal.clearData(this);\n this._value = null;\n }\n\n private _value: JSONValue = null;\n private _changed = new Signal<this, ObservableValue.IChangedArgs>(this);\n private _isDisposed = false;\n}\n\n\n/**\n * The namespace for the `ObservableValue` class statics.\n */\nexport\nnamespace ObservableValue {\n /**\n * The changed args object emitted by the `IObservableValue`.\n */\n export\n class IChangedArgs {\n /**\n * The old value.\n */\n oldValue: JSONValue | undefined;\n\n /**\n * The new value.\n */\n newValue: JSONValue | undefined;\n }\n}\n\n\n/**\n * A concrete implementation of an `IModelDB`.\n */\nexport\nclass ModelDB implements IModelDB {\n /**\n * Constructor for the `ModelDB`.\n */\n constructor(options: ModelDB.ICreateOptions = {}) {\n this._basePath = options.basePath || '';\n if (options.baseDB) {\n this._db = options.baseDB;\n } else {\n this._db = new ObservableMap<IObservable>();\n this._toDispose = true;\n }\n }\n\n /**\n * The base path for the `ModelDB`. This is prepended\n * to all the paths that are passed in to the member\n * functions of the object.\n */\n get basePath(): string {\n return this._basePath;\n }\n\n /**\n * Whether the database is disposed.\n */\n get isDisposed(): boolean {\n return this._isDisposed;\n }\n\n /**\n * Whether the model has been populated with\n * any model values.\n */\n readonly isPrepopulated: boolean = false;\n\n /**\n * Whether the model is collaborative.\n */\n readonly isCollaborative: boolean = false;\n\n /**\n * A promise resolved when the model is connected\n * to its backend. For the in-memory ModelDB it\n * is immediately resolved.\n */\n readonly connected: Promise<void> = Promise.resolve(void 0);\n\n /**\n * Get a value for a path.\n *\n * @param path: the path for the object.\n *\n * @returns an `IObservable`.\n */\n get(path: string): IObservable | undefined {\n return this._db.get(this._resolvePath(path));\n }\n\n /**\n * Whether the `IModelDB` has an object at this path.\n *\n * @param path: the path for the object.\n *\n * @returns a boolean for whether an object is at `path`.\n */\n has(path: string): boolean {\n return this._db.has(this._resolvePath(path));\n }\n\n /**\n * Create a string and insert it in the database.\n *\n * @param path: the path for the string.\n *\n * @returns the string that was created.\n */\n createString(path: string): IObservableString {\n let str = new ObservableString();\n this._disposables.add(str);\n this.set(path, str);\n return str;\n }\n\n /**\n * Create an undoable list and insert it in the database.\n *\n * @param path: the path for the list.\n *\n * @returns the list that was created.\n *\n * #### Notes\n * The list can only store objects that are simple\n * JSON Objects and primitives.\n */\n createList<T extends JSONValue>(path: string): IObservableUndoableList<T> {\n let vec = new ObservableUndoableList<T>(\n new ObservableUndoableList.IdentitySerializer<T>());\n this._disposables.add(vec);\n this.set(path, vec);\n return vec;\n }\n\n /**\n * Create a map and insert it in the database.\n *\n * @param path: the path for the map.\n *\n * @returns the map that was created.\n *\n * #### Notes\n * The map can only store objects that are simple\n * JSON Objects and primitives.\n */\n createMap(path: string): IObservableJSON {\n let map = new ObservableJSON();\n this._disposables.add(map);\n this.set(path, map);\n return map;\n }\n\n /**\n * Create an opaque value and insert it in the database.\n *\n * @param path: the path for the value.\n *\n * @returns the value that was created.\n */\n createValue(path: string): IObservableValue {\n let val = new ObservableValue();\n this._disposables.add(val);\n this.set(path, val);\n return val;\n }\n\n /**\n * Get a value at a path, or `undefined if it has not been set\n * That value must already have been created using `createValue`.\n *\n * @param path: the path for the value.\n */\n getValue(path: string): JSONValue | undefined {\n let val = this.get(path);\n if (!val || val.type !== 'Value') {\n throw Error('Can only call getValue for an ObservableValue');\n }\n return (val as ObservableValue).get();\n }\n\n /**\n * Set a value at a path. That value must already have\n * been created using `createValue`.\n *\n * @param path: the path for the value.\n *\n * @param value: the new value.\n */\n setValue(path: string, value: JSONValue): void {\n let val = this.get(path);\n if (!val || val.type !== 'Value') {\n throw Error('Can only call setValue on an ObservableValue');\n }\n (val as ObservableValue).set(value);\n }\n\n\n /**\n * Create a view onto a subtree of the model database.\n *\n * @param basePath: the path for the root of the subtree.\n *\n * @returns an `IModelDB` with a view onto the original\n * `IModelDB`, with `basePath` prepended to all paths.\n */\n view(basePath: string): ModelDB {\n let view = new ModelDB({basePath, baseDB: this});\n this._disposables.add(view);\n return view;\n }\n\n /**\n * Set a value at a path. Not intended to\n * be called by user code, instead use the\n * `create*` factory methods.\n *\n * @param path: the path to set the value at.\n *\n * @param value: the value to set at the path.\n */\n set(path: string, value: IObservable): void {\n this._db.set(this._resolvePath(path), value);\n }\n\n /**\n * Dispose of the resources held by the database.\n */\n dispose(): void {\n if (this.isDisposed) {\n return;\n }\n this._isDisposed = true;\n if (this._toDispose) {\n this._db.dispose();\n }\n this._disposables.dispose();\n }\n\n /**\n * Compute the fully resolved path for a path argument.\n */\n private _resolvePath(path: string): string {\n if (this._basePath) {\n path = this._basePath + '.' + path;\n }\n return path;\n }\n\n private _basePath: string;\n private _db: ModelDB | ObservableMap<IObservable>;\n private _toDispose = false;\n private _isDisposed = false;\n private _disposables = new DisposableSet();\n}\n\n/**\n * A namespace for the `ModelDB` class statics.\n */\nexport\nnamespace ModelDB {\n /**\n * Options for creating a `ModelDB` object.\n */\n export\n interface ICreateOptions {\n /**\n * The base path to prepend to all the path arguments.\n */\n basePath?: string;\n\n /**\n * A ModelDB to use as the store for this\n * ModelDB. If none is given, it uses its own store.\n */\n baseDB?: ModelDB;\n }\n\n /**\n * A factory interface for creating `IModelDB` objects.\n */\n export\n interface IFactory {\n /**\n * Create a new `IModelDB` instance.\n */\n createNew(path: string): IModelDB;\n }\n}\n"]} |
| {"version":3,"file":"nbformat.js","sourceRoot":"","sources":["../../../../coreutils/src/nbformat.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D,6BAA6B;AAC7B,oEAAoE;AACpE,sFAAsF;AAEtF,iDAE6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AM,CAAC,mBAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IApCQ,0BAAiB,oBAoCzB,CAAA;IA+JD;;OAEG;IACH,eACe,IAAW;QACxB,MAAM,CAAC,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC;IAClC,CAAC;IAFQ,cAAK,QAEb,CAAA;IAED;;OAEG;IACH,oBACoB,IAAW;QAC7B,MAAM,CAAC,IAAI,CAAC,SAAS,KAAK,UAAU,CAAC;IACvC,CAAC;IAFQ,mBAAU,aAElB,CAAA;IAED;;OAEG;IACH,gBACgB,IAAW;QACzB,MAAM,CAAC,IAAI,CAAC,SAAS,KAAK,MAAM,CAAC;IACnC,CAAC;IAFQ,eAAM,SAEd,CAAA;IAwJD;;OAEG;IACH,yBACyB,MAAe;QACtC,MAAM,CAAC,MAAM,CAAC,WAAW,KAAK,gBAAgB,CAAC;IACjD,CAAC;IAFQ,wBAAe,kBAEvB,CAAA;IAED;;OAEG;IACH,uBACuB,MAAe;QACpC,MAAM,CAAC,MAAM,CAAC,WAAW,KAAK,cAAc,CAAC;IAC/C,CAAC;IAFQ,sBAAa,gBAErB,CAAA;IAED;;OAEG;IACH,yBACyB,MAAe;QACtC,MAAM,CAAC,MAAM,CAAC,WAAW,KAAK,qBAAqB,CAAC;IACtD,CAAC;IAFQ,wBAAe,kBAEvB,CAAA;IAED;;OAEG;IACH,kBACkB,MAAe;QAC/B,MAAM,CAAC,MAAM,CAAC,WAAW,KAAK,QAAQ,CAAC;IACzC,CAAC;IAFQ,iBAAQ,WAEhB,CAAA;IAED;;OAEG;IACH,iBACiB,MAAe;QAC9B,MAAM,CAAC,MAAM,CAAC,WAAW,KAAK,OAAO,CAAC;IACxC,CAAC;IAFQ,gBAAO,UAEf,CAAA;AAOH,CAAC,EAjgBS,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAigBjB","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\n// Notebook format interfaces\n// https://nbformat.readthedocs.io/en/latest/format_description.html\n// https://github.com/jupyter/nbformat/blob/master/nbformat/v4/nbformat.v4.schema.json\n\nimport {\n JSONObject, JSONExt\n} from '@phosphor/coreutils';\n\n\n/**\n * A namespace for nbformat interfaces.\n */\nexport\nnamespace nbformat {\n /**\n * The major version of the notebook format.\n */\n export\n const MAJOR_VERSION: number = 4;\n\n /**\n * The minor version of the notebook format.\n */\n export\n const MINOR_VERSION: number = 2;\n\n /**\n * The kernelspec metadata.\n */\n export\n interface IKernelspecMetadata extends JSONObject {\n name: string;\n display_name: string;\n }\n\n /**\n * The language info metatda\n */\n export\n interface ILanguageInfoMetadata extends JSONObject {\n name: string;\n codemirror_mode?: string | JSONObject;\n file_extension?: string;\n mimetype?: string;\n pygments_lexer?: string;\n }\n\n /**\n * The default metadata for the notebook.\n */\n export\n interface INotebookMetadata extends JSONObject {\n kernelspec: IKernelspecMetadata;\n language_info: ILanguageInfoMetadata;\n orig_nbformat: number;\n }\n\n /**\n * The notebook content.\n */\n export\n interface INotebookContent extends JSONObject {\n metadata: INotebookMetadata;\n nbformat_minor: number;\n nbformat: number;\n cells: ICell[];\n }\n\n /**\n * A multiline string.\n */\n export\n type MultilineString = string | string[];\n\n /**\n * A mime-type keyed dictionary of data.\n */\n export\n interface IMimeBundle extends JSONObject {\n [key: string]: MultilineString | JSONObject;\n }\n\n /**\n * Media attachments (e.g. inline images).\n */\n export\n interface IAttachments {\n [key: string]: IMimeBundle;\n }\n\n /**\n * The code cell's prompt number. Will be null if the cell has not been run.\n */\n export\n type ExecutionCount = number | null;\n\n /**\n * Cell output metadata.\n */\n export\n type OutputMetadata = JSONObject;\n\n /**\n * Validate a mime type/value pair.\n *\n * @param type - The mimetype name.\n *\n * @param value - The value associated with the type.\n *\n * @returns Whether the type/value pair are valid.\n */\n export\n function validateMimeValue(type: string, value: MultilineString | JSONObject): boolean {\n // Check if \"application/json\" or \"application/foo+json\"\n const jsonTest = /^application\\/(.*?)+\\+json$/;\n const isJSONType = type === 'application/json' || jsonTest.test(type);\n\n let isString = (x: any) => {\n return Object.prototype.toString.call(x) === '[object String]';\n };\n\n // If it is an array, make sure if is not a JSON type and it is an\n // array of strings.\n if (Array.isArray(value)) {\n if (isJSONType) {\n return false;\n }\n let valid = true;\n (value as string[]).forEach(v => {\n if (!isString(v)) {\n valid = false;\n }\n });\n return valid;\n }\n\n // If it is a string, make sure we are not a JSON type.\n if (isString(value)) {\n return !isJSONType;\n }\n\n // It is not a string, make sure it is a JSON type.\n if (!isJSONType) {\n return false;\n }\n\n // It is a JSON type, make sure it is a valid JSON object.\n return JSONExt.isObject(value);\n }\n\n /**\n * A type which describes the type of cell.\n */\n export\n type CellType = 'code' | 'markdown' | 'raw';\n\n /**\n * Cell-level metadata.\n */\n export\n interface IBaseCellMetadata extends JSONObject {\n /**\n * Whether the cell is trusted.\n *\n * #### Notes\n * This is not strictly part of the nbformat spec, but it is added by\n * the contents manager.\n *\n * See https://jupyter-notebook.readthedocs.io/en/latest/security.html.\n */\n trusted: boolean;\n\n /**\n * The cell's name. If present, must be a non-empty string.\n */\n name: string;\n\n /**\n * The cell's tags. Tags must be unique, and must not contain commas.\n */\n tags: string[];\n }\n\n /**\n * The base cell interface.\n */\n export\n interface IBaseCell extends JSONObject {\n /**\n * String identifying the type of cell.\n */\n cell_type: string;\n\n /**\n * Contents of the cell, represented as an array of lines.\n */\n source: MultilineString;\n\n /**\n * Cell-level metadata.\n */\n metadata: Partial<ICellMetadata>;\n }\n\n /**\n * Metadata for the raw cell.\n */\n export\n interface IRawCellMetadata extends IBaseCellMetadata {\n /**\n * Raw cell metadata format for nbconvert.\n */\n format: string;\n }\n\n /**\n * A raw cell.\n */\n export\n interface IRawCell extends IBaseCell {\n /**\n * String identifying the type of cell.\n */\n cell_type: 'raw';\n\n /**\n * Cell-level metadata.\n */\n metadata: Partial<IRawCellMetadata>;\n\n /**\n * Cell attachments.\n */\n attachments?: IAttachments;\n }\n\n /**\n * A markdown cell.\n */\n export\n interface IMarkdownCell extends IBaseCell {\n /**\n * String identifying the type of cell.\n */\n cell_type: 'markdown';\n\n /**\n * Cell attachments.\n */\n attachments?: IAttachments;\n }\n\n /**\n * Metadata for a code cell.\n */\n export\n interface ICodeCellMetadata extends IBaseCellMetadata {\n /**\n * Whether the cell is collapsed/expanded.\n */\n collapsed: boolean;\n\n /**\n * Whether the cell's output is scrolled, unscrolled, or autoscrolled.\n */\n scrolled: boolean | 'auto';\n }\n\n /**\n * A code cell.\n */\n export\n interface ICodeCell extends IBaseCell {\n /**\n * String identifying the type of cell.\n */\n cell_type: 'code';\n\n /**\n * Cell-level metadata.\n */\n metadata: Partial<ICodeCellMetadata>;\n\n /**\n * Execution, display, or stream outputs.\n */\n outputs: IOutput[];\n\n /**\n * The code cell's prompt number. Will be null if the cell has not been run.\n */\n execution_count: ExecutionCount;\n }\n\n /**\n * An unrecognized cell.\n */\n export\n interface IUnrecognizedCell extends IBaseCell { }\n\n\n /**\n * A cell union type.\n */\n export\n type ICell = IRawCell | IMarkdownCell | ICodeCell | IUnrecognizedCell;\n\n /**\n * Test whether a cell is a raw cell.\n */\n export\n function isRaw(cell: ICell): cell is IRawCell {\n return cell.cell_type === 'raw';\n }\n\n /**\n * Test whether a cell is a markdown cell.\n */\n export\n function isMarkdown(cell: ICell): cell is IMarkdownCell {\n return cell.cell_type === 'markdown';\n }\n\n /**\n * Test whether a cell is a code cell.\n */\n export\n function isCode(cell: ICell): cell is ICodeCell {\n return cell.cell_type === 'code';\n }\n\n /**\n * A union metadata type.\n */\n export\n type ICellMetadata = IBaseCellMetadata | IRawCellMetadata | ICodeCellMetadata;\n\n /**\n * The valid output types.\n */\n export\n type OutputType = 'execute_result' | 'display_data' | 'stream' | 'error' | 'update_display_data';\n\n /**\n * The base output type.\n */\n export\n interface IBaseOutput extends JSONObject {\n /**\n * Type of cell output.\n */\n output_type: string;\n }\n\n /**\n * Result of executing a code cell.\n */\n export\n interface IExecuteResult extends IBaseOutput {\n /**\n * Type of cell output.\n */\n output_type: 'execute_result';\n\n /**\n * A result's prompt number.\n */\n execution_count: ExecutionCount;\n\n /**\n * A mime-type keyed dictionary of data.\n */\n data: IMimeBundle;\n\n /**\n * Cell output metadata.\n */\n metadata: OutputMetadata;\n }\n\n /**\n * Data displayed as a result of code cell execution.\n */\n export\n interface IDisplayData extends IBaseOutput {\n /**\n * Type of cell output.\n */\n output_type: 'display_data';\n\n /**\n * A mime-type keyed dictionary of data.\n */\n data: IMimeBundle;\n\n /**\n * Cell output metadata.\n */\n metadata: OutputMetadata;\n }\n\n /**\n * Data displayed as an update to existing display data.\n */\n export\n interface IDisplayUpdate extends IBaseOutput {\n /**\n * Type of cell output.\n */\n output_type: 'update_display_data';\n\n /**\n * A mime-type keyed dictionary of data.\n */\n data: IMimeBundle;\n\n /**\n * Cell output metadata.\n */\n metadata: OutputMetadata;\n }\n\n /**\n * Stream output from a code cell.\n */\n export\n interface IStream extends IBaseOutput {\n /**\n * Type of cell output.\n */\n output_type: 'stream';\n\n /**\n * The name of the stream.\n */\n name: StreamType;\n\n /**\n * The stream's text output.\n */\n text: MultilineString;\n }\n\n /**\n * An alias for a stream type.\n */\n export\n type StreamType = 'stdout' | 'stderr';\n\n /**\n * Output of an error that occurred during code cell execution.\n */\n export\n interface IError extends IBaseOutput {\n /**\n * Type of cell output.\n */\n output_type: 'error';\n\n /**\n * The name of the error.\n */\n ename: string;\n\n /**\n * The value, or message, of the error.\n */\n evalue: string;\n\n /**\n * The error's traceback.\n */\n traceback: string[];\n }\n\n /**\n * Unrecognized output.\n */\n export\n interface IUnrecognizedOutput extends IBaseOutput { }\n\n /**\n * Test whether an output is an execute result.\n */\n export\n function isExecuteResult(output: IOutput): output is IExecuteResult {\n return output.output_type === 'execute_result';\n }\n\n /**\n * Test whether an output is from display data.\n */\n export\n function isDisplayData(output: IOutput): output is IDisplayData {\n return output.output_type === 'display_data';\n }\n\n /**\n * Test whether an output is from updated display data.\n */\n export\n function isDisplayUpdate(output: IOutput): output is IDisplayUpdate {\n return output.output_type === 'update_display_data';\n }\n\n /**\n * Test whether an output is from a stream.\n */\n export\n function isStream(output: IOutput): output is IStream {\n return output.output_type === 'stream';\n }\n\n /**\n * Test whether an output is from a stream.\n */\n export\n function isError(output: IOutput): output is IError {\n return output.output_type === 'error';\n }\n\n /**\n * An output union type.\n */\n export\n type IOutput = IUnrecognizedOutput | IExecuteResult | IDisplayData | IStream | IError;\n}\n"]} |
| import { JSONObject, JSONValue } from '@phosphor/coreutils'; | ||
| import { Message } from '@phosphor/messaging'; | ||
| import { IObservableMap, ObservableMap } from './observablemap'; | ||
| /** | ||
| * An observable JSON value. | ||
| */ | ||
| export interface IObservableJSON extends IObservableMap<JSONValue> { | ||
| /** | ||
| * Serialize the model to JSON. | ||
| */ | ||
| toJSON(): JSONObject; | ||
| } | ||
| /** | ||
| * The namespace for IObservableJSON related interfaces. | ||
| */ | ||
| export declare namespace IObservableJSON { | ||
| /** | ||
| * A type alias for observable JSON changed args. | ||
| */ | ||
| type IChangedArgs = IObservableMap.IChangedArgs<JSONValue>; | ||
| } | ||
| /** | ||
| * A concrete Observable map for JSON data. | ||
| */ | ||
| export declare class ObservableJSON extends ObservableMap<JSONValue> { | ||
| /** | ||
| * Construct a new observable JSON object. | ||
| */ | ||
| constructor(options?: ObservableJSON.IOptions); | ||
| /** | ||
| * Serialize the model to JSON. | ||
| */ | ||
| toJSON(): JSONObject; | ||
| } | ||
| /** | ||
| * The namespace for ObservableJSON static data. | ||
| */ | ||
| export declare namespace ObservableJSON { | ||
| /** | ||
| * The options use to initialize an observable JSON object. | ||
| */ | ||
| interface IOptions { | ||
| /** | ||
| * The optional intitial value for the object. | ||
| */ | ||
| values?: JSONObject; | ||
| } | ||
| /** | ||
| * An observable JSON change message. | ||
| */ | ||
| class ChangeMessage extends Message { | ||
| /** | ||
| * Create a new metadata changed message. | ||
| */ | ||
| constructor(args: IObservableJSON.IChangedArgs); | ||
| /** | ||
| * The arguments of the change. | ||
| */ | ||
| readonly args: IObservableJSON.IChangedArgs; | ||
| } | ||
| } |
| "use strict"; | ||
| // Copyright (c) Jupyter Development Team. | ||
| // Distributed under the terms of the Modified BSD License. | ||
| var __extends = (this && this.__extends) || (function () { | ||
| var extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
| return function (d, b) { | ||
| extendStatics(d, b); | ||
| function __() { this.constructor = d; } | ||
| d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| }; | ||
| })(); | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var coreutils_1 = require("@phosphor/coreutils"); | ||
| var messaging_1 = require("@phosphor/messaging"); | ||
| var observablemap_1 = require("./observablemap"); | ||
| /** | ||
| * A concrete Observable map for JSON data. | ||
| */ | ||
| var ObservableJSON = (function (_super) { | ||
| __extends(ObservableJSON, _super); | ||
| /** | ||
| * Construct a new observable JSON object. | ||
| */ | ||
| function ObservableJSON(options) { | ||
| if (options === void 0) { options = {}; } | ||
| return _super.call(this, { | ||
| itemCmp: coreutils_1.JSONExt.deepEqual, | ||
| values: options.values | ||
| }) || this; | ||
| } | ||
| /** | ||
| * Serialize the model to JSON. | ||
| */ | ||
| ObservableJSON.prototype.toJSON = function () { | ||
| var out = Object.create(null); | ||
| var keys = this.keys(); | ||
| for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { | ||
| var key = keys_1[_i]; | ||
| var value = this.get(key); | ||
| if (value !== undefined) { | ||
| out[key] = coreutils_1.JSONExt.deepCopy(value); | ||
| } | ||
| } | ||
| return out; | ||
| }; | ||
| return ObservableJSON; | ||
| }(observablemap_1.ObservableMap)); | ||
| exports.ObservableJSON = ObservableJSON; | ||
| /** | ||
| * The namespace for ObservableJSON static data. | ||
| */ | ||
| (function (ObservableJSON) { | ||
| /** | ||
| * An observable JSON change message. | ||
| */ | ||
| var ChangeMessage = (function (_super) { | ||
| __extends(ChangeMessage, _super); | ||
| /** | ||
| * Create a new metadata changed message. | ||
| */ | ||
| function ChangeMessage(args) { | ||
| var _this = _super.call(this, 'jsonvalue-changed') || this; | ||
| _this.args = args; | ||
| return _this; | ||
| } | ||
| return ChangeMessage; | ||
| }(messaging_1.Message)); | ||
| ObservableJSON.ChangeMessage = ChangeMessage; | ||
| })(ObservableJSON = exports.ObservableJSON || (exports.ObservableJSON = {})); | ||
| exports.ObservableJSON = ObservableJSON; | ||
| //# sourceMappingURL=observablejson.js.map |
| {"version":3,"file":"observablejson.js","sourceRoot":"","sources":["../../../../coreutils/src/observablejson.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;;;;;;;;;;;AAE3D,iDAE6B;AAE7B,iDAE6B;AAE7B,iDAEyB;AA4BzB;;GAEG;AACH;IAC6B,kCAAwB;IACnD;;OAEG;IACH,wBAAY,OAAqC;QAArC,wBAAA,EAAA,YAAqC;eAC/C,kBAAM;YACJ,OAAO,EAAE,mBAAO,CAAC,SAAS;YAC1B,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,+BAAM,GAAN;QACE,IAAM,GAAG,GAAe,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAEzB,GAAG,CAAC,CAAY,UAAI,EAAJ,aAAI,EAAJ,kBAAI,EAAJ,IAAI;YAAf,IAAI,GAAG,aAAA;YACV,IAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAE5B,EAAE,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC;gBACxB,GAAG,CAAC,GAAG,CAAC,GAAG,mBAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACrC,CAAC;SACF;QACD,MAAM,CAAC,GAAG,CAAC;IACb,CAAC;IACH,qBAAC;AAAD,CAAC,AA5BD,CAC6B,6BAAa,GA2BzC;AA3BK,wCAAc;AA8BpB;;GAEG;AACH,WACU,cAAc;IAYtB;;OAEG;IACH;QAC4B,iCAAO;QACjC;;WAEG;QACH,uBAAY,IAAkC;YAA9C,YACE,kBAAM,mBAAmB,CAAC,SAE3B;YADC,KAAI,CAAC,IAAI,GAAG,IAAI,CAAC;;QACnB,CAAC;QAMH,oBAAC;IAAD,CAAC,AAdD,CAC4B,mBAAO,GAalC;IAbK,4BAAa,gBAalB,CAAA;AACH,CAAC,EA9BS,cAAc,GAAd,sBAAc,KAAd,sBAAc,QA8BvB;AAhEK,wCAAc","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport {\n JSONExt, JSONObject, JSONValue\n} from '@phosphor/coreutils';\n\nimport {\n Message\n} from '@phosphor/messaging';\n\nimport {\n IObservableMap, ObservableMap\n} from './observablemap';\n\n\n/**\n * An observable JSON value.\n */\nexport\ninterface IObservableJSON extends IObservableMap<JSONValue> {\n /**\n * Serialize the model to JSON.\n */\n toJSON(): JSONObject;\n}\n\n\n/**\n * The namespace for IObservableJSON related interfaces.\n */\nexport\nnamespace IObservableJSON {\n /**\n * A type alias for observable JSON changed args.\n */\n export\n type IChangedArgs = IObservableMap.IChangedArgs<JSONValue>;\n}\n\n\n/**\n * A concrete Observable map for JSON data.\n */\nexport\nclass ObservableJSON extends ObservableMap<JSONValue> {\n /**\n * Construct a new observable JSON object.\n */\n constructor(options: ObservableJSON.IOptions = {}) {\n super({\n itemCmp: JSONExt.deepEqual,\n values: options.values\n });\n }\n\n /**\n * Serialize the model to JSON.\n */\n toJSON(): JSONObject {\n const out: JSONObject = Object.create(null);\n const keys = this.keys();\n\n for (let key of keys) {\n const value = this.get(key);\n\n if (value !== undefined) {\n out[key] = JSONExt.deepCopy(value);\n }\n }\n return out;\n }\n}\n\n\n/**\n * The namespace for ObservableJSON static data.\n */\nexport\nnamespace ObservableJSON {\n /**\n * The options use to initialize an observable JSON object.\n */\n export\n interface IOptions {\n /**\n * The optional intitial value for the object.\n */\n values?: JSONObject;\n }\n\n /**\n * An observable JSON change message.\n */\n export\n class ChangeMessage extends Message {\n /**\n * Create a new metadata changed message.\n */\n constructor(args: IObservableJSON.IChangedArgs) {\n super('jsonvalue-changed');\n this.args = args;\n }\n\n /**\n * The arguments of the change.\n */\n readonly args: IObservableJSON.IChangedArgs;\n }\n}\n"]} |
| import { IIterator, IterableOrArrayLike } from '@phosphor/algorithm'; | ||
| import { IDisposable } from '@phosphor/disposable'; | ||
| import { ISignal } from '@phosphor/signaling'; | ||
| /** | ||
| * A list which can be observed for changes. | ||
| */ | ||
| export interface IObservableList<T> extends IDisposable { | ||
| /** | ||
| * A signal emitted when the list has changed. | ||
| */ | ||
| readonly changed: ISignal<this, IObservableList.IChangedArgs<T>>; | ||
| /** | ||
| * The type of this object. | ||
| */ | ||
| readonly type: 'List'; | ||
| /** | ||
| * The length of the list. | ||
| * | ||
| * #### Notes | ||
| * This is a read-only property. | ||
| */ | ||
| length: number; | ||
| /** | ||
| * Create an iterator over the values in the list. | ||
| * | ||
| * @returns A new iterator starting at the front of the list. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| */ | ||
| iter(): IIterator<T>; | ||
| /** | ||
| * Remove all values from the list. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * All current iterators are invalidated. | ||
| */ | ||
| clear(): void; | ||
| /** | ||
| * Get the value at the specified index. | ||
| * | ||
| * @param index - The positive integer index of interest. | ||
| * | ||
| * @returns The value at the specified index. | ||
| * | ||
| * #### Undefined Behavior | ||
| * An `index` which is non-integral or out of range. | ||
| */ | ||
| get(index: number): T | undefined; | ||
| /** | ||
| * Insert a value into the list at a specific index. | ||
| * | ||
| * @param index - The index at which to insert the value. | ||
| * | ||
| * @param value - The value to set at the specified index. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| * | ||
| * #### Notes | ||
| * The `index` will be clamped to the bounds of the list. | ||
| * | ||
| * #### Undefined Behavior | ||
| * An `index` which is non-integral. | ||
| */ | ||
| insert(index: number, value: T): void; | ||
| /** | ||
| * Insert a set of items into the list at the specified index. | ||
| * | ||
| * @param index - The index at which to insert the values. | ||
| * | ||
| * @param values - The values to insert at the specified index. | ||
| * | ||
| * #### Complexity. | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| * | ||
| * #### Notes | ||
| * The `index` will be clamped to the bounds of the list. | ||
| * | ||
| * #### Undefined Behavior. | ||
| * An `index` which is non-integral. | ||
| */ | ||
| insertAll(index: number, values: IterableOrArrayLike<T>): void; | ||
| /** | ||
| * Move a value from one index to another. | ||
| * | ||
| * @parm fromIndex - The index of the element to move. | ||
| * | ||
| * @param toIndex - The index to move the element to. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * Iterators pointing at the lesser of the `fromIndex` and the `toIndex` | ||
| * and beyond are invalidated. | ||
| * | ||
| * #### Undefined Behavior | ||
| * A `fromIndex` or a `toIndex` which is non-integral. | ||
| */ | ||
| move(fromIndex: number, toIndex: number): void; | ||
| /** | ||
| * Add a value to the back of the list. | ||
| * | ||
| * @param value - The value to add to the back of the list. | ||
| * | ||
| * @returns The new length of the list. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| */ | ||
| push(value: T): number; | ||
| /** | ||
| * Push a set of values to the back of the list. | ||
| * | ||
| * @param values - An iterable or array-like set of values to add. | ||
| * | ||
| * @returns The new length of the list. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| */ | ||
| pushAll(values: IterableOrArrayLike<T>): number; | ||
| /** | ||
| * Remove and return the value at a specific index. | ||
| * | ||
| * @param index - The index of the value of interest. | ||
| * | ||
| * @returns The value at the specified index, or `undefined` if the | ||
| * index is out of range. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * Iterators pointing at the removed value and beyond are invalidated. | ||
| * | ||
| * #### Undefined Behavior | ||
| * An `index` which is non-integral. | ||
| */ | ||
| remove(index: number): T | undefined; | ||
| /** | ||
| * Remove a range of items from the list. | ||
| * | ||
| * @param startIndex - The start index of the range to remove (inclusive). | ||
| * | ||
| * @param endIndex - The end index of the range to remove (exclusive). | ||
| * | ||
| * @returns The new length of the list. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * Iterators pointing to the first removed value and beyond are invalid. | ||
| * | ||
| * #### Undefined Behavior | ||
| * A `startIndex` or `endIndex` which is non-integral. | ||
| */ | ||
| removeRange(startIndex: number, endIndex: number): number; | ||
| /** | ||
| * Remove the first occurrence of a value from the list. | ||
| * | ||
| * @param value - The value of interest. | ||
| * | ||
| * @returns The index of the removed value, or `-1` if the value | ||
| * is not contained in the list. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * Iterators pointing at the removed value and beyond are invalidated. | ||
| */ | ||
| removeValue(value: T): number; | ||
| /** | ||
| * Set the value at the specified index. | ||
| * | ||
| * @param index - The positive integer index of interest. | ||
| * | ||
| * @param value - The value to set at the specified index. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| * | ||
| * #### Undefined Behavior | ||
| * An `index` which is non-integral or out of range. | ||
| */ | ||
| set(index: number, value: T): void; | ||
| } | ||
| /** | ||
| * The namespace for IObservableList related interfaces. | ||
| */ | ||
| export declare namespace IObservableList { | ||
| /** | ||
| * The change types which occur on an observable list. | ||
| */ | ||
| type ChangeType = 'add' | 'move' | 'remove' | 'set'; | ||
| /** | ||
| * The changed args object which is emitted by an observable list. | ||
| */ | ||
| interface IChangedArgs<T> { | ||
| /** | ||
| * The type of change undergone by the vector. | ||
| */ | ||
| type: ChangeType; | ||
| /** | ||
| * The new index associated with the change. | ||
| */ | ||
| newIndex: number; | ||
| /** | ||
| * The new values associated with the change. | ||
| * | ||
| * #### Notes | ||
| * The values will be contiguous starting at the `newIndex`. | ||
| */ | ||
| newValues: T[]; | ||
| /** | ||
| * The old index associated with the change. | ||
| */ | ||
| oldIndex: number; | ||
| /** | ||
| * The old values associated with the change. | ||
| * | ||
| * #### Notes | ||
| * The values will be contiguous starting at the `oldIndex`. | ||
| */ | ||
| oldValues: T[]; | ||
| } | ||
| } | ||
| /** | ||
| * A concrete implementation of [[IObservableList]]. | ||
| */ | ||
| export declare class ObservableList<T> implements IObservableList<T> { | ||
| /** | ||
| * Construct a new observable map. | ||
| */ | ||
| constructor(options?: ObservableList.IOptions<T>); | ||
| /** | ||
| * The type of this object. | ||
| */ | ||
| readonly type: 'List'; | ||
| /** | ||
| * A signal emitted when the list has changed. | ||
| */ | ||
| readonly changed: ISignal<this, IObservableList.IChangedArgs<T>>; | ||
| /** | ||
| * The length of the list. | ||
| */ | ||
| readonly length: number; | ||
| /** | ||
| * Test whether the list has been disposed. | ||
| */ | ||
| readonly isDisposed: boolean; | ||
| /** | ||
| * Dispose of the resources held by the list. | ||
| */ | ||
| dispose(): void; | ||
| /** | ||
| * Create an iterator over the values in the list. | ||
| * | ||
| * @returns A new iterator starting at the front of the list. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| */ | ||
| iter(): IIterator<T>; | ||
| /** | ||
| * Get the value at the specified index. | ||
| * | ||
| * @param index - The positive integer index of interest. | ||
| * | ||
| * @returns The value at the specified index. | ||
| * | ||
| * #### Undefined Behavior | ||
| * An `index` which is non-integral or out of range. | ||
| */ | ||
| get(index: number): T | undefined; | ||
| /** | ||
| * Set the value at the specified index. | ||
| * | ||
| * @param index - The positive integer index of interest. | ||
| * | ||
| * @param value - The value to set at the specified index. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| * | ||
| * #### Undefined Behavior | ||
| * An `index` which is non-integral or out of range. | ||
| */ | ||
| set(index: number, value: T): void; | ||
| /** | ||
| * Add a value to the end of the list. | ||
| * | ||
| * @param value - The value to add to the end of the list. | ||
| * | ||
| * @returns The new length of the list. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| */ | ||
| push(value: T): number; | ||
| /** | ||
| * Insert a value into the list at a specific index. | ||
| * | ||
| * @param index - The index at which to insert the value. | ||
| * | ||
| * @param value - The value to set at the specified index. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| * | ||
| * #### Notes | ||
| * The `index` will be clamped to the bounds of the list. | ||
| * | ||
| * #### Undefined Behavior | ||
| * An `index` which is non-integral. | ||
| */ | ||
| insert(index: number, value: T): void; | ||
| /** | ||
| * Remove the first occurrence of a value from the list. | ||
| * | ||
| * @param value - The value of interest. | ||
| * | ||
| * @returns The index of the removed value, or `-1` if the value | ||
| * is not contained in the list. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * Iterators pointing at the removed value and beyond are invalidated. | ||
| */ | ||
| removeValue(value: T): number; | ||
| /** | ||
| * Remove and return the value at a specific index. | ||
| * | ||
| * @param index - The index of the value of interest. | ||
| * | ||
| * @returns The value at the specified index, or `undefined` if the | ||
| * index is out of range. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * Iterators pointing at the removed value and beyond are invalidated. | ||
| * | ||
| * #### Undefined Behavior | ||
| * An `index` which is non-integral. | ||
| */ | ||
| remove(index: number): T | undefined; | ||
| /** | ||
| * Remove all values from the list. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * All current iterators are invalidated. | ||
| */ | ||
| clear(): void; | ||
| /** | ||
| * Move a value from one index to another. | ||
| * | ||
| * @parm fromIndex - The index of the element to move. | ||
| * | ||
| * @param toIndex - The index to move the element to. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * Iterators pointing at the lesser of the `fromIndex` and the `toIndex` | ||
| * and beyond are invalidated. | ||
| * | ||
| * #### Undefined Behavior | ||
| * A `fromIndex` or a `toIndex` which is non-integral. | ||
| */ | ||
| move(fromIndex: number, toIndex: number): void; | ||
| /** | ||
| * Push a set of values to the back of the list. | ||
| * | ||
| * @param values - An iterable or array-like set of values to add. | ||
| * | ||
| * @returns The new length of the list. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| */ | ||
| pushAll(values: IterableOrArrayLike<T>): number; | ||
| /** | ||
| * Insert a set of items into the list at the specified index. | ||
| * | ||
| * @param index - The index at which to insert the values. | ||
| * | ||
| * @param values - The values to insert at the specified index. | ||
| * | ||
| * #### Complexity. | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| * | ||
| * #### Notes | ||
| * The `index` will be clamped to the bounds of the list. | ||
| * | ||
| * #### Undefined Behavior. | ||
| * An `index` which is non-integral. | ||
| */ | ||
| insertAll(index: number, values: IterableOrArrayLike<T>): void; | ||
| /** | ||
| * Remove a range of items from the list. | ||
| * | ||
| * @param startIndex - The start index of the range to remove (inclusive). | ||
| * | ||
| * @param endIndex - The end index of the range to remove (exclusive). | ||
| * | ||
| * @returns The new length of the list. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * Iterators pointing to the first removed value and beyond are invalid. | ||
| * | ||
| * #### Undefined Behavior | ||
| * A `startIndex` or `endIndex` which is non-integral. | ||
| */ | ||
| removeRange(startIndex: number, endIndex: number): number; | ||
| private _array; | ||
| private _isDisposed; | ||
| private _itemCmp; | ||
| private _changed; | ||
| } | ||
| /** | ||
| * The namespace for `ObservableList` class statics. | ||
| */ | ||
| export declare namespace ObservableList { | ||
| /** | ||
| * The options used to initialize an observable map. | ||
| */ | ||
| interface IOptions<T> { | ||
| /** | ||
| * An optional intial set of values. | ||
| */ | ||
| values?: IterableOrArrayLike<T>; | ||
| /** | ||
| * The item comparison function for change detection on `set`. | ||
| * | ||
| * If not given, strict `===` equality will be used. | ||
| */ | ||
| itemCmp?: (first: T, second: T) => boolean; | ||
| } | ||
| } |
| "use strict"; | ||
| // Copyright (c) Jupyter Development Team. | ||
| // Distributed under the terms of the Modified BSD License. | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var algorithm_1 = require("@phosphor/algorithm"); | ||
| var signaling_1 = require("@phosphor/signaling"); | ||
| /** | ||
| * A concrete implementation of [[IObservableList]]. | ||
| */ | ||
| var ObservableList = (function () { | ||
| /** | ||
| * Construct a new observable map. | ||
| */ | ||
| function ObservableList(options) { | ||
| if (options === void 0) { options = {}; } | ||
| var _this = this; | ||
| this._array = []; | ||
| this._isDisposed = false; | ||
| this._changed = new signaling_1.Signal(this); | ||
| if (options.values !== void 0) { | ||
| algorithm_1.each(options.values, function (value) { _this._array.push(value); }); | ||
| } | ||
| this._itemCmp = options.itemCmp || Private.itemCmp; | ||
| } | ||
| Object.defineProperty(ObservableList.prototype, "type", { | ||
| /** | ||
| * The type of this object. | ||
| */ | ||
| get: function () { | ||
| return 'List'; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| Object.defineProperty(ObservableList.prototype, "changed", { | ||
| /** | ||
| * A signal emitted when the list has changed. | ||
| */ | ||
| get: function () { | ||
| return this._changed; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| Object.defineProperty(ObservableList.prototype, "length", { | ||
| /** | ||
| * The length of the list. | ||
| */ | ||
| get: function () { | ||
| return this._array.length; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| Object.defineProperty(ObservableList.prototype, "isDisposed", { | ||
| /** | ||
| * Test whether the list has been disposed. | ||
| */ | ||
| get: function () { | ||
| return this._isDisposed; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| /** | ||
| * Dispose of the resources held by the list. | ||
| */ | ||
| ObservableList.prototype.dispose = function () { | ||
| if (this._isDisposed) { | ||
| return; | ||
| } | ||
| this._isDisposed = true; | ||
| signaling_1.Signal.clearData(this); | ||
| this.clear(); | ||
| }; | ||
| /** | ||
| * Create an iterator over the values in the list. | ||
| * | ||
| * @returns A new iterator starting at the front of the list. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| */ | ||
| ObservableList.prototype.iter = function () { | ||
| return new algorithm_1.ArrayIterator(this._array); | ||
| }; | ||
| /** | ||
| * Get the value at the specified index. | ||
| * | ||
| * @param index - The positive integer index of interest. | ||
| * | ||
| * @returns The value at the specified index. | ||
| * | ||
| * #### Undefined Behavior | ||
| * An `index` which is non-integral or out of range. | ||
| */ | ||
| ObservableList.prototype.get = function (index) { | ||
| return this._array[index]; | ||
| }; | ||
| /** | ||
| * Set the value at the specified index. | ||
| * | ||
| * @param index - The positive integer index of interest. | ||
| * | ||
| * @param value - The value to set at the specified index. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| * | ||
| * #### Undefined Behavior | ||
| * An `index` which is non-integral or out of range. | ||
| */ | ||
| ObservableList.prototype.set = function (index, value) { | ||
| var oldValue = this._array[index]; | ||
| if (value === undefined) { | ||
| throw new Error('Cannot set an undefined item'); | ||
| } | ||
| // Bail if the value does not change. | ||
| var itemCmp = this._itemCmp; | ||
| if (itemCmp(oldValue, value)) { | ||
| return; | ||
| } | ||
| this._array[index] = value; | ||
| this._changed.emit({ | ||
| type: 'set', | ||
| oldIndex: index, | ||
| newIndex: index, | ||
| oldValues: [oldValue], | ||
| newValues: [value] | ||
| }); | ||
| }; | ||
| /** | ||
| * Add a value to the end of the list. | ||
| * | ||
| * @param value - The value to add to the end of the list. | ||
| * | ||
| * @returns The new length of the list. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| */ | ||
| ObservableList.prototype.push = function (value) { | ||
| var num = this._array.push(value); | ||
| this._changed.emit({ | ||
| type: 'add', | ||
| oldIndex: -1, | ||
| newIndex: this.length - 1, | ||
| oldValues: [], | ||
| newValues: [value] | ||
| }); | ||
| return num; | ||
| }; | ||
| /** | ||
| * Insert a value into the list at a specific index. | ||
| * | ||
| * @param index - The index at which to insert the value. | ||
| * | ||
| * @param value - The value to set at the specified index. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| * | ||
| * #### Notes | ||
| * The `index` will be clamped to the bounds of the list. | ||
| * | ||
| * #### Undefined Behavior | ||
| * An `index` which is non-integral. | ||
| */ | ||
| ObservableList.prototype.insert = function (index, value) { | ||
| algorithm_1.ArrayExt.insert(this._array, index, value); | ||
| this._changed.emit({ | ||
| type: 'add', | ||
| oldIndex: -1, | ||
| newIndex: index, | ||
| oldValues: [], | ||
| newValues: [value] | ||
| }); | ||
| }; | ||
| /** | ||
| * Remove the first occurrence of a value from the list. | ||
| * | ||
| * @param value - The value of interest. | ||
| * | ||
| * @returns The index of the removed value, or `-1` if the value | ||
| * is not contained in the list. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * Iterators pointing at the removed value and beyond are invalidated. | ||
| */ | ||
| ObservableList.prototype.removeValue = function (value) { | ||
| var itemCmp = this._itemCmp; | ||
| var index = algorithm_1.ArrayExt.findFirstIndex(this._array, function (item) { | ||
| return itemCmp(item, value); | ||
| }); | ||
| this.remove(index); | ||
| return index; | ||
| }; | ||
| /** | ||
| * Remove and return the value at a specific index. | ||
| * | ||
| * @param index - The index of the value of interest. | ||
| * | ||
| * @returns The value at the specified index, or `undefined` if the | ||
| * index is out of range. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * Iterators pointing at the removed value and beyond are invalidated. | ||
| * | ||
| * #### Undefined Behavior | ||
| * An `index` which is non-integral. | ||
| */ | ||
| ObservableList.prototype.remove = function (index) { | ||
| var value = algorithm_1.ArrayExt.removeAt(this._array, index); | ||
| if (value === undefined) { | ||
| return; | ||
| } | ||
| this._changed.emit({ | ||
| type: 'remove', | ||
| oldIndex: index, | ||
| newIndex: -1, | ||
| newValues: [], | ||
| oldValues: [value] | ||
| }); | ||
| return value; | ||
| }; | ||
| /** | ||
| * Remove all values from the list. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * All current iterators are invalidated. | ||
| */ | ||
| ObservableList.prototype.clear = function () { | ||
| var copy = this._array.slice(); | ||
| this._array.length = 0; | ||
| this._changed.emit({ | ||
| type: 'remove', | ||
| oldIndex: 0, | ||
| newIndex: 0, | ||
| newValues: [], | ||
| oldValues: copy | ||
| }); | ||
| }; | ||
| /** | ||
| * Move a value from one index to another. | ||
| * | ||
| * @parm fromIndex - The index of the element to move. | ||
| * | ||
| * @param toIndex - The index to move the element to. | ||
| * | ||
| * #### Complexity | ||
| * Constant. | ||
| * | ||
| * #### Iterator Validity | ||
| * Iterators pointing at the lesser of the `fromIndex` and the `toIndex` | ||
| * and beyond are invalidated. | ||
| * | ||
| * #### Undefined Behavior | ||
| * A `fromIndex` or a `toIndex` which is non-integral. | ||
| */ | ||
| ObservableList.prototype.move = function (fromIndex, toIndex) { | ||
| if (this.length <= 1 || fromIndex === toIndex) { | ||
| return; | ||
| } | ||
| var values = [this._array[fromIndex]]; | ||
| algorithm_1.ArrayExt.move(this._array, fromIndex, toIndex); | ||
| this._changed.emit({ | ||
| type: 'move', | ||
| oldIndex: fromIndex, | ||
| newIndex: toIndex, | ||
| oldValues: values, | ||
| newValues: values | ||
| }); | ||
| }; | ||
| /** | ||
| * Push a set of values to the back of the list. | ||
| * | ||
| * @param values - An iterable or array-like set of values to add. | ||
| * | ||
| * @returns The new length of the list. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| */ | ||
| ObservableList.prototype.pushAll = function (values) { | ||
| var _this = this; | ||
| var newIndex = this.length; | ||
| var count = 0; | ||
| algorithm_1.each(values, function (value) { | ||
| _this._array.push(value); | ||
| count++; | ||
| }); | ||
| this._changed.emit({ | ||
| type: 'add', | ||
| oldIndex: -1, | ||
| newIndex: newIndex, | ||
| oldValues: [], | ||
| newValues: algorithm_1.toArray(values) | ||
| }); | ||
| return this.length; | ||
| }; | ||
| /** | ||
| * Insert a set of items into the list at the specified index. | ||
| * | ||
| * @param index - The index at which to insert the values. | ||
| * | ||
| * @param values - The values to insert at the specified index. | ||
| * | ||
| * #### Complexity. | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * No changes. | ||
| * | ||
| * #### Notes | ||
| * The `index` will be clamped to the bounds of the list. | ||
| * | ||
| * #### Undefined Behavior. | ||
| * An `index` which is non-integral. | ||
| */ | ||
| ObservableList.prototype.insertAll = function (index, values) { | ||
| var _this = this; | ||
| var newIndex = index; | ||
| var count = 0; | ||
| algorithm_1.each(values, function (value) { | ||
| algorithm_1.ArrayExt.insert(_this._array, index++, value); | ||
| count++; | ||
| }); | ||
| this._changed.emit({ | ||
| type: 'add', | ||
| oldIndex: -1, | ||
| newIndex: newIndex, | ||
| oldValues: [], | ||
| newValues: algorithm_1.toArray(values) | ||
| }); | ||
| }; | ||
| /** | ||
| * Remove a range of items from the list. | ||
| * | ||
| * @param startIndex - The start index of the range to remove (inclusive). | ||
| * | ||
| * @param endIndex - The end index of the range to remove (exclusive). | ||
| * | ||
| * @returns The new length of the list. | ||
| * | ||
| * #### Complexity | ||
| * Linear. | ||
| * | ||
| * #### Iterator Validity | ||
| * Iterators pointing to the first removed value and beyond are invalid. | ||
| * | ||
| * #### Undefined Behavior | ||
| * A `startIndex` or `endIndex` which is non-integral. | ||
| */ | ||
| ObservableList.prototype.removeRange = function (startIndex, endIndex) { | ||
| var oldValues = this._array.slice(startIndex, endIndex); | ||
| for (var i = startIndex; i < endIndex; i++) { | ||
| algorithm_1.ArrayExt.removeAt(this._array, startIndex); | ||
| } | ||
| this._changed.emit({ | ||
| type: 'remove', | ||
| oldIndex: startIndex, | ||
| newIndex: -1, | ||
| oldValues: oldValues, | ||
| newValues: [] | ||
| }); | ||
| return this.length; | ||
| }; | ||
| return ObservableList; | ||
| }()); | ||
| exports.ObservableList = ObservableList; | ||
| /** | ||
| * The namespace for module private data. | ||
| */ | ||
| var Private; | ||
| (function (Private) { | ||
| /** | ||
| * The default strict equality item cmp. | ||
| */ | ||
| function itemCmp(first, second) { | ||
| return first === second; | ||
| } | ||
| Private.itemCmp = itemCmp; | ||
| })(Private || (Private = {})); | ||
| //# sourceMappingURL=observablelist.js.map |
| {"version":3,"file":"observablelist.js","sourceRoot":"","sources":["../../../../coreutils/src/observablelist.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D,iDAE6B;AAM7B,iDAE6B;AAyS7B;;GAEG;AACH;IAEE;;OAEG;IACH,wBAAY,OAAwC;QAAxC,wBAAA,EAAA,YAAwC;QAApD,iBAKC;QAiXO,WAAM,GAAa,EAAE,CAAC;QACtB,gBAAW,GAAG,KAAK,CAAC;QAEpB,aAAQ,GAAG,IAAI,kBAAM,CAAwC,IAAI,CAAC,CAAC;QAxXzE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC;YAC9B,gBAAI,CAAC,OAAO,CAAC,MAAM,EAAE,UAAA,KAAK,IAAM,KAAI,CAAC,MAAM,CAAC,IAAI,CAAC,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AM,CAAC,KAAK,KAAK,MAAM,CAAC;IAC1B,CAAC;IAFQ,eAAO,UAEf,CAAA;AACH,CAAC,EARS,OAAO,KAAP,OAAO,QAQhB","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport {\n ArrayExt, ArrayIterator, IIterator, IterableOrArrayLike, each, toArray\n} from '@phosphor/algorithm';\n\nimport {\n IDisposable\n} from '@phosphor/disposable';\n\nimport {\n ISignal, Signal\n} from '@phosphor/signaling';\n\n\n/**\n * A list which can be observed for changes.\n */\nexport\ninterface IObservableList<T> extends IDisposable {\n /**\n * A signal emitted when the list has changed.\n */\n readonly changed: ISignal<this, IObservableList.IChangedArgs<T>>;\n\n /**\n * The type of this object.\n */\n readonly type: 'List';\n\n /**\n * The length of the list.\n *\n * #### Notes\n * This is a read-only property.\n */\n length: number;\n\n /**\n * Create an iterator over the values in the list.\n *\n * @returns A new iterator starting at the front of the list.\n *\n * #### Complexity\n * Constant.\n *\n * #### Iterator Validity\n * No changes.\n */\n iter(): IIterator<T>;\n\n /**\n * Remove all values from the list.\n *\n * #### Complexity\n * Linear.\n *\n * #### Iterator Validity\n * All current iterators are invalidated.\n */\n clear(): void;\n\n /**\n * Get the value at the specified index.\n *\n * @param index - The positive integer index of interest.\n *\n * @returns The value at the specified index.\n *\n * #### Undefined Behavior\n * An `index` which is non-integral or out of range.\n */\n get(index: number): T | undefined;\n\n /**\n * Insert a value into the list at a specific index.\n *\n * @param index - The index at which to insert the value.\n *\n * @param value - The value to set at the specified index.\n *\n * #### Complexity\n * Linear.\n *\n * #### Iterator Validity\n * No changes.\n *\n * #### Notes\n * The `index` will be clamped to the bounds of the list.\n *\n * #### Undefined Behavior\n * An `index` which is non-integral.\n */\n insert(index: number, value: T): void;\n\n /**\n * Insert a set of items into the list at the specified index.\n *\n * @param index - The index at which to insert the values.\n *\n * @param values - The values to insert at the specified index.\n *\n * #### Complexity.\n * Linear.\n *\n * #### Iterator Validity\n * No changes.\n *\n * #### Notes\n * The `index` will be clamped to the bounds of the list.\n *\n * #### Undefined Behavior.\n * An `index` which is non-integral.\n */\n insertAll(index: number, values: IterableOrArrayLike<T>): void;\n\n /**\n * Move a value from one index to another.\n *\n * @parm fromIndex - The index of the element to move.\n *\n * @param toIndex - The index to move the element to.\n *\n * #### Complexity\n * Constant.\n *\n * #### Iterator Validity\n * Iterators pointing at the lesser of the `fromIndex` and the `toIndex`\n * and beyond are invalidated.\n *\n * #### Undefined Behavior\n * A `fromIndex` or a `toIndex` which is non-integral.\n */\n move(fromIndex: number, toIndex: number): void;\n\n /**\n * Add a value to the back of the list.\n *\n * @param value - The value to add to the back of the list.\n *\n * @returns The new length of the list.\n *\n * #### Complexity\n * Constant.\n *\n * #### Iterator Validity\n * No changes.\n */\n push(value: T): number;\n\n /**\n * Push a set of values to the back of the list.\n *\n * @param values - An iterable or array-like set of values to add.\n *\n * @returns The new length of the list.\n *\n * #### Complexity\n * Linear.\n *\n * #### Iterator Validity\n * No changes.\n */\n pushAll(values: IterableOrArrayLike<T>): number;\n\n /**\n * Remove and return the value at a specific index.\n *\n * @param index - The index of the value of interest.\n *\n * @returns The value at the specified index, or `undefined` if the\n * index is out of range.\n *\n * #### Complexity\n * Constant.\n *\n * #### Iterator Validity\n * Iterators pointing at the removed value and beyond are invalidated.\n *\n * #### Undefined Behavior\n * An `index` which is non-integral.\n */\n remove(index: number): T | undefined;\n\n /**\n * Remove a range of items from the list.\n *\n * @param startIndex - The start index of the range to remove (inclusive).\n *\n * @param endIndex - The end index of the range to remove (exclusive).\n *\n * @returns The new length of the list.\n *\n * #### Complexity\n * Linear.\n *\n * #### Iterator Validity\n * Iterators pointing to the first removed value and beyond are invalid.\n *\n * #### Undefined Behavior\n * A `startIndex` or `endIndex` which is non-integral.\n */\n removeRange(startIndex: number, endIndex: number): number;\n\n /**\n * Remove the first occurrence of a value from the list.\n *\n * @param value - The value of interest.\n *\n * @returns The index of the removed value, or `-1` if the value\n * is not contained in the list.\n *\n * #### Complexity\n * Linear.\n *\n * #### Iterator Validity\n * Iterators pointing at the removed value and beyond are invalidated.\n */\n removeValue(value: T): number;\n\n /**\n * Set the value at the specified index.\n *\n * @param index - The positive integer index of interest.\n *\n * @param value - The value to set at the specified index.\n *\n * #### Complexity\n * Constant.\n *\n * #### Iterator Validity\n * No changes.\n *\n * #### Undefined Behavior\n * An `index` which is non-integral or out of range.\n */\n set(index: number, value: T): void;\n}\n\n\n/**\n * The namespace for IObservableList related interfaces.\n */\nexport\nnamespace IObservableList {\n /**\n * The change types which occur on an observable list.\n */\n export\n type ChangeType =\n /**\n * Item(s) were added to the list.\n */\n 'add' |\n\n /**\n * An item was moved within the list.\n */\n 'move' |\n\n /**\n * Item(s) were removed from the list.\n */\n 'remove' |\n\n /**\n * An item was set in the list.\n */\n 'set';\n\n /**\n * The changed args object which is emitted by an observable list.\n */\n export\n interface IChangedArgs<T> {\n /**\n * The type of change undergone by the vector.\n */\n type: ChangeType;\n\n /**\n * The new index associated with the change.\n */\n newIndex: number;\n\n /**\n * The new values associated with the change.\n *\n * #### Notes\n * The values will be contiguous starting at the `newIndex`.\n */\n newValues: T[];\n\n /**\n * The old index associated with the change.\n */\n oldIndex: number;\n\n /**\n * The old values associated with the change.\n *\n * #### Notes\n * The values will be contiguous starting at the `oldIndex`.\n */\n oldValues: T[];\n }\n}\n\n\n/**\n * A concrete implementation of [[IObservableList]].\n */\nexport\nclass ObservableList<T> implements IObservableList<T> {\n /**\n * Construct a new observable map.\n */\n constructor(options: ObservableList.IOptions<T> = {}) {\n if (options.values !== void 0) {\n each(options.values, value => { this._array.push(value); });\n }\n this._itemCmp = options.itemCmp || Private.itemCmp;\n }\n\n /**\n * The type of this object.\n */\n get type(): 'List' {\n return 'List';\n }\n\n /**\n * A signal emitted when the list has changed.\n */\n get changed(): ISignal<this, IObservableList.IChangedArgs<T>> {\n return this._changed;\n }\n\n /**\n * The length of the list.\n */\n get length(): number {\n return this._array.length;\n }\n\n /**\n * Test whether the list has been disposed.\n */\n get isDisposed(): boolean {\n return this._isDisposed;\n }\n\n /**\n * Dispose of the resources held by the list.\n */\n dispose(): void {\n if (this._isDisposed) {\n return;\n }\n this._isDisposed = true;\n Signal.clearData(this);\n this.clear();\n }\n\n\n /**\n * Create an iterator over the values in the list.\n *\n * @returns A new iterator starting at the front of the list.\n *\n * #### Complexity\n * Constant.\n *\n * #### Iterator Validity\n * No changes.\n */\n iter(): IIterator<T> {\n return new ArrayIterator(this._array);\n }\n\n /**\n * Get the value at the specified index.\n *\n * @param index - The positive integer index of interest.\n *\n * @returns The value at the specified index.\n *\n * #### Undefined Behavior\n * An `index` which is non-integral or out of range.\n */\n get(index: number): T | undefined {\n return this._array[index];\n }\n\n /**\n * Set the value at the specified index.\n *\n * @param index - The positive integer index of interest.\n *\n * @param value - The value to set at the specified index.\n *\n * #### Complexity\n * Constant.\n *\n * #### Iterator Validity\n * No changes.\n *\n * #### Undefined Behavior\n * An `index` which is non-integral or out of range.\n */\n set(index: number, value: T): void {\n let oldValue = this._array[index];\n if (value === undefined) {\n throw new Error('Cannot set an undefined item');\n }\n // Bail if the value does not change.\n let itemCmp = this._itemCmp;\n if (itemCmp(oldValue, value)) {\n return;\n }\n this._array[index] = value;\n this._changed.emit({\n type: 'set',\n oldIndex: index,\n newIndex: index,\n oldValues: [oldValue],\n newValues: [value]\n });\n }\n\n /**\n * Add a value to the end of the list.\n *\n * @param value - The value to add to the end of the list.\n *\n * @returns The new length of the list.\n *\n * #### Complexity\n * Constant.\n *\n * #### Iterator Validity\n * No changes.\n */\n push(value: T): number {\n let num = this._array.push(value);\n this._changed.emit({\n type: 'add',\n oldIndex: -1,\n newIndex: this.length - 1,\n oldValues: [],\n newValues: [value]\n });\n return num;\n }\n\n /**\n * Insert a value into the list at a specific index.\n *\n * @param index - The index at which to insert the value.\n *\n * @param value - The value to set at the specified index.\n *\n * #### Complexity\n * Linear.\n *\n * #### Iterator Validity\n * No changes.\n *\n * #### Notes\n * The `index` will be clamped to the bounds of the list.\n *\n * #### Undefined Behavior\n * An `index` which is non-integral.\n */\n insert(index: number, value: T): void {\n ArrayExt.insert(this._array, index, value);\n this._changed.emit({\n type: 'add',\n oldIndex: -1,\n newIndex: index,\n oldValues: [],\n newValues: [value]\n });\n }\n\n /**\n * Remove the first occurrence of a value from the list.\n *\n * @param value - The value of interest.\n *\n * @returns The index of the removed value, or `-1` if the value\n * is not contained in the list.\n *\n * #### Complexity\n * Linear.\n *\n * #### Iterator Validity\n * Iterators pointing at the removed value and beyond are invalidated.\n */\n removeValue(value: T): number {\n let itemCmp = this._itemCmp;\n let index = ArrayExt.findFirstIndex(this._array, item => {\n return itemCmp(item, value);\n });\n this.remove(index);\n return index;\n }\n\n /**\n * Remove and return the value at a specific index.\n *\n * @param index - The index of the value of interest.\n *\n * @returns The value at the specified index, or `undefined` if the\n * index is out of range.\n *\n * #### Complexity\n * Constant.\n *\n * #### Iterator Validity\n * Iterators pointing at the removed value and beyond are invalidated.\n *\n * #### Undefined Behavior\n * An `index` which is non-integral.\n */\n remove(index: number): T | undefined {\n let value = ArrayExt.removeAt(this._array, index);\n if (value === undefined) {\n return;\n }\n this._changed.emit({\n type: 'remove',\n oldIndex: index,\n newIndex: -1,\n newValues: [],\n oldValues: [value]\n });\n return value;\n }\n\n /**\n * Remove all values from the list.\n *\n * #### Complexity\n * Linear.\n *\n * #### Iterator Validity\n * All current iterators are invalidated.\n */\n clear(): void {\n let copy = this._array.slice();\n this._array.length = 0;\n this._changed.emit({\n type: 'remove',\n oldIndex: 0,\n newIndex: 0,\n newValues: [],\n oldValues: copy\n });\n }\n\n /**\n * Move a value from one index to another.\n *\n * @parm fromIndex - The index of the element to move.\n *\n * @param toIndex - The index to move the element to.\n *\n * #### Complexity\n * Constant.\n *\n * #### Iterator Validity\n * Iterators pointing at the lesser of the `fromIndex` and the `toIndex`\n * and beyond are invalidated.\n *\n * #### Undefined Behavior\n * A `fromIndex` or a `toIndex` which is non-integral.\n */\n move(fromIndex: number, toIndex: number): void {\n if (this.length <= 1 || fromIndex === toIndex) {\n return;\n }\n let values = [this._array[fromIndex]];\n ArrayExt.move(this._array, fromIndex, toIndex);\n this._changed.emit({\n type: 'move',\n oldIndex: fromIndex,\n newIndex: toIndex,\n oldValues: values,\n newValues: values\n });\n }\n\n /**\n * Push a set of values to the back of the list.\n *\n * @param values - An iterable or array-like set of values to add.\n *\n * @returns The new length of the list.\n *\n * #### Complexity\n * Linear.\n *\n * #### Iterator Validity\n * No changes.\n */\n pushAll(values: IterableOrArrayLike<T>): number {\n let newIndex = this.length;\n let count = 0;\n each(values, value => {\n this._array.push(value);\n count++;\n });\n this._changed.emit({\n type: 'add',\n oldIndex: -1,\n newIndex,\n oldValues: [],\n newValues: toArray(values)\n });\n return this.length;\n }\n\n /**\n * Insert a set of items into the list at the specified index.\n *\n * @param index - The index at which to insert the values.\n *\n * @param values - The values to insert at the specified index.\n *\n * #### Complexity.\n * Linear.\n *\n * #### Iterator Validity\n * No changes.\n *\n * #### Notes\n * The `index` will be clamped to the bounds of the list.\n *\n * #### Undefined Behavior.\n * An `index` which is non-integral.\n */\n insertAll(index: number, values: IterableOrArrayLike<T>): void {\n let newIndex = index;\n let count = 0;\n each(values, value => {\n ArrayExt.insert(this._array, index++, value);\n count++;\n });\n this._changed.emit({\n type: 'add',\n oldIndex: -1,\n newIndex,\n oldValues: [],\n newValues: toArray(values)\n });\n }\n\n /**\n * Remove a range of items from the list.\n *\n * @param startIndex - The start index of the range to remove (inclusive).\n *\n * @param endIndex - The end index of the range to remove (exclusive).\n *\n * @returns The new length of the list.\n *\n * #### Complexity\n * Linear.\n *\n * #### Iterator Validity\n * Iterators pointing to the first removed value and beyond are invalid.\n *\n * #### Undefined Behavior\n * A `startIndex` or `endIndex` which is non-integral.\n */\n removeRange(startIndex: number, endIndex: number): number {\n let oldValues = this._array.slice(startIndex, endIndex);\n for (let i = startIndex; i < endIndex; i++) {\n ArrayExt.removeAt(this._array, startIndex);\n }\n this._changed.emit({\n type: 'remove',\n oldIndex: startIndex,\n newIndex: -1,\n oldValues,\n newValues: []\n });\n return this.length;\n }\n\n private _array: Array<T> = [];\n private _isDisposed = false;\n private _itemCmp: (first: T, second: T) => boolean;\n private _changed = new Signal<this, IObservableList.IChangedArgs<T>>(this);\n}\n\n\n/**\n * The namespace for `ObservableList` class statics.\n */\nexport\nnamespace ObservableList {\n /**\n * The options used to initialize an observable map.\n */\n export\n interface IOptions<T> {\n /**\n * An optional intial set of values.\n */\n values?: IterableOrArrayLike<T>;\n\n /**\n * The item comparison function for change detection on `set`.\n *\n * If not given, strict `===` equality will be used.\n */\n itemCmp?: (first: T, second: T) => boolean;\n }\n}\n\n\n/**\n * The namespace for module private data.\n */\nnamespace Private {\n /**\n * The default strict equality item cmp.\n */\n export\n function itemCmp(first: any, second: any): boolean {\n return first === second;\n }\n}\n"]} |
| import { IDisposable } from '@phosphor/disposable'; | ||
| import { ISignal } from '@phosphor/signaling'; | ||
| import { IObservable } from './modeldb'; | ||
| /** | ||
| * A map which can be observed for changes. | ||
| */ | ||
| export interface IObservableMap<T> extends IDisposable, IObservable { | ||
| /** | ||
| * The type of the Observable. | ||
| */ | ||
| type: 'Map'; | ||
| /** | ||
| * A signal emitted when the map has changed. | ||
| */ | ||
| readonly changed: ISignal<this, IObservableMap.IChangedArgs<T>>; | ||
| /** | ||
| * The number of key-value pairs in the map. | ||
| */ | ||
| readonly size: number; | ||
| /** | ||
| * Set a key-value pair in the map | ||
| * | ||
| * @param key - The key to set. | ||
| * | ||
| * @param value - The value for the key. | ||
| * | ||
| * @returns the old value for the key, or undefined | ||
| * if that did not exist. | ||
| */ | ||
| set(key: string, value: T): T | undefined; | ||
| /** | ||
| * Get a value for a given key. | ||
| * | ||
| * @param key - the key. | ||
| * | ||
| * @returns the value for that key. | ||
| */ | ||
| get(key: string): T | undefined; | ||
| /** | ||
| * Check whether the map has a key. | ||
| * | ||
| * @param key - the key to check. | ||
| * | ||
| * @returns `true` if the map has the key, `false` otherwise. | ||
| */ | ||
| has(key: string): boolean; | ||
| /** | ||
| * Get a list of the keys in the map. | ||
| * | ||
| * @returns - a list of keys. | ||
| */ | ||
| keys(): string[]; | ||
| /** | ||
| * Get a list of the values in the map. | ||
| * | ||
| * @returns - a list of values. | ||
| */ | ||
| values(): T[]; | ||
| /** | ||
| * Remove a key from the map | ||
| * | ||
| * @param key - the key to remove. | ||
| * | ||
| * @returns the value of the given key, | ||
| * or undefined if that does not exist. | ||
| */ | ||
| delete(key: string): T | undefined; | ||
| /** | ||
| * Set the ObservableMap to an empty map. | ||
| */ | ||
| clear(): void; | ||
| /** | ||
| * Dispose of the resources held by the map. | ||
| */ | ||
| dispose(): void; | ||
| } | ||
| /** | ||
| * The interfaces associated with an IObservableMap. | ||
| */ | ||
| export declare namespace IObservableMap { | ||
| /** | ||
| * The change types which occur on an observable map. | ||
| */ | ||
| type ChangeType = 'add' | 'remove' | 'change'; | ||
| /** | ||
| * The changed args object which is emitted by an observable map. | ||
| */ | ||
| interface IChangedArgs<T> { | ||
| /** | ||
| * The type of change undergone by the map. | ||
| */ | ||
| type: ChangeType; | ||
| /** | ||
| * The key of the change. | ||
| */ | ||
| key: string; | ||
| /** | ||
| * The old value of the change. | ||
| */ | ||
| oldValue: T | undefined; | ||
| /** | ||
| * The new value of the change. | ||
| */ | ||
| newValue: T | undefined; | ||
| } | ||
| } | ||
| /** | ||
| * A concrete implementation of IObservbleMap<T>. | ||
| */ | ||
| export declare class ObservableMap<T> implements IObservableMap<T> { | ||
| /** | ||
| * Construct a new observable map. | ||
| */ | ||
| constructor(options?: ObservableMap.IOptions<T>); | ||
| /** | ||
| * The type of the Observable. | ||
| */ | ||
| readonly type: 'Map'; | ||
| /** | ||
| * A signal emitted when the map has changed. | ||
| */ | ||
| readonly changed: ISignal<this, IObservableMap.IChangedArgs<T>>; | ||
| /** | ||
| * Whether this map has been disposed. | ||
| */ | ||
| readonly isDisposed: boolean; | ||
| /** | ||
| * The number of key-value pairs in the map. | ||
| */ | ||
| readonly size: number; | ||
| /** | ||
| * Set a key-value pair in the map | ||
| * | ||
| * @param key - The key to set. | ||
| * | ||
| * @param value - The value for the key. | ||
| * | ||
| * @returns the old value for the key, or undefined | ||
| * if that did not exist. | ||
| * | ||
| * @throws if the new value is undefined. | ||
| * | ||
| * #### Notes | ||
| * This is a no-op if the value does not change. | ||
| */ | ||
| set(key: string, value: T): T | undefined; | ||
| /** | ||
| * Get a value for a given key. | ||
| * | ||
| * @param key - the key. | ||
| * | ||
| * @returns the value for that key. | ||
| */ | ||
| get(key: string): T | undefined; | ||
| /** | ||
| * Check whether the map has a key. | ||
| * | ||
| * @param key - the key to check. | ||
| * | ||
| * @returns `true` if the map has the key, `false` otherwise. | ||
| */ | ||
| has(key: string): boolean; | ||
| /** | ||
| * Get a list of the keys in the map. | ||
| * | ||
| * @returns - a list of keys. | ||
| */ | ||
| keys(): string[]; | ||
| /** | ||
| * Get a list of the values in the map. | ||
| * | ||
| * @returns - a list of values. | ||
| */ | ||
| values(): T[]; | ||
| /** | ||
| * Remove a key from the map | ||
| * | ||
| * @param key - the key to remove. | ||
| * | ||
| * @returns the value of the given key, | ||
| * or undefined if that does not exist. | ||
| */ | ||
| delete(key: string): T | undefined; | ||
| /** | ||
| * Set the ObservableMap to an empty map. | ||
| */ | ||
| clear(): void; | ||
| /** | ||
| * Dispose of the resources held by the map. | ||
| */ | ||
| dispose(): void; | ||
| private _map; | ||
| private _itemCmp; | ||
| private _changed; | ||
| private _isDisposed; | ||
| } | ||
| /** | ||
| * The namespace for `ObservableMap` class statics. | ||
| */ | ||
| export declare namespace ObservableMap { | ||
| /** | ||
| * The options used to initialize an observable map. | ||
| */ | ||
| interface IOptions<T> { | ||
| /** | ||
| * An optional intial set of values. | ||
| */ | ||
| values?: { | ||
| [key: string]: T; | ||
| }; | ||
| /** | ||
| * The item comparison function for change detection on `set`. | ||
| * | ||
| * If not given, strict `===` equality will be used. | ||
| */ | ||
| itemCmp?: (first: T, second: T) => boolean; | ||
| } | ||
| } |
| "use strict"; | ||
| // Copyright (c) Jupyter Development Team. | ||
| // Distributed under the terms of the Modified BSD License. | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var signaling_1 = require("@phosphor/signaling"); | ||
| /** | ||
| * A concrete implementation of IObservbleMap<T>. | ||
| */ | ||
| var ObservableMap = (function () { | ||
| /** | ||
| * Construct a new observable map. | ||
| */ | ||
| function ObservableMap(options) { | ||
| if (options === void 0) { options = {}; } | ||
| this._map = new Map(); | ||
| this._changed = new signaling_1.Signal(this); | ||
| this._isDisposed = false; | ||
| this._itemCmp = options.itemCmp || Private.itemCmp; | ||
| if (options.values) { | ||
| for (var key in options.values) { | ||
| this._map.set(key, options.values[key]); | ||
| } | ||
| } | ||
| } | ||
| Object.defineProperty(ObservableMap.prototype, "type", { | ||
| /** | ||
| * The type of the Observable. | ||
| */ | ||
| get: function () { | ||
| return 'Map'; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| Object.defineProperty(ObservableMap.prototype, "changed", { | ||
| /** | ||
| * A signal emitted when the map has changed. | ||
| */ | ||
| get: function () { | ||
| return this._changed; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| Object.defineProperty(ObservableMap.prototype, "isDisposed", { | ||
| /** | ||
| * Whether this map has been disposed. | ||
| */ | ||
| get: function () { | ||
| return this._isDisposed; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| Object.defineProperty(ObservableMap.prototype, "size", { | ||
| /** | ||
| * The number of key-value pairs in the map. | ||
| */ | ||
| get: function () { | ||
| return this._map.size; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| /** | ||
| * Set a key-value pair in the map | ||
| * | ||
| * @param key - The key to set. | ||
| * | ||
| * @param value - The value for the key. | ||
| * | ||
| * @returns the old value for the key, or undefined | ||
| * if that did not exist. | ||
| * | ||
| * @throws if the new value is undefined. | ||
| * | ||
| * #### Notes | ||
| * This is a no-op if the value does not change. | ||
| */ | ||
| ObservableMap.prototype.set = function (key, value) { | ||
| var oldVal = this._map.get(key); | ||
| if (value === undefined) { | ||
| throw Error('Cannot set an undefined value, use remove'); | ||
| } | ||
| // Bail if the value does not change. | ||
| var itemCmp = this._itemCmp; | ||
| if (oldVal !== undefined && itemCmp(oldVal, value)) { | ||
| return oldVal; | ||
| } | ||
| this._map.set(key, value); | ||
| this._changed.emit({ | ||
| type: oldVal ? 'change' : 'add', | ||
| key: key, | ||
| oldValue: oldVal, | ||
| newValue: value | ||
| }); | ||
| return oldVal; | ||
| }; | ||
| /** | ||
| * Get a value for a given key. | ||
| * | ||
| * @param key - the key. | ||
| * | ||
| * @returns the value for that key. | ||
| */ | ||
| ObservableMap.prototype.get = function (key) { | ||
| return this._map.get(key); | ||
| }; | ||
| /** | ||
| * Check whether the map has a key. | ||
| * | ||
| * @param key - the key to check. | ||
| * | ||
| * @returns `true` if the map has the key, `false` otherwise. | ||
| */ | ||
| ObservableMap.prototype.has = function (key) { | ||
| return this._map.has(key); | ||
| }; | ||
| /** | ||
| * Get a list of the keys in the map. | ||
| * | ||
| * @returns - a list of keys. | ||
| */ | ||
| ObservableMap.prototype.keys = function () { | ||
| var keyList = []; | ||
| this._map.forEach(function (v, k) { | ||
| keyList.push(k); | ||
| }); | ||
| return keyList; | ||
| }; | ||
| /** | ||
| * Get a list of the values in the map. | ||
| * | ||
| * @returns - a list of values. | ||
| */ | ||
| ObservableMap.prototype.values = function () { | ||
| var valList = []; | ||
| this._map.forEach(function (v, k) { | ||
| valList.push(v); | ||
| }); | ||
| return valList; | ||
| }; | ||
| /** | ||
| * Remove a key from the map | ||
| * | ||
| * @param key - the key to remove. | ||
| * | ||
| * @returns the value of the given key, | ||
| * or undefined if that does not exist. | ||
| */ | ||
| ObservableMap.prototype.delete = function (key) { | ||
| var oldVal = this._map.get(key); | ||
| this._map.delete(key); | ||
| this._changed.emit({ | ||
| type: 'remove', | ||
| key: key, | ||
| oldValue: oldVal, | ||
| newValue: undefined | ||
| }); | ||
| return oldVal; | ||
| }; | ||
| /** | ||
| * Set the ObservableMap to an empty map. | ||
| */ | ||
| ObservableMap.prototype.clear = function () { | ||
| // Delete one by one to emit the correct signals. | ||
| var keyList = this.keys(); | ||
| for (var i = 0; i < keyList.length; i++) { | ||
| this.delete(keyList[i]); | ||
| } | ||
| }; | ||
| /** | ||
| * Dispose of the resources held by the map. | ||
| */ | ||
| ObservableMap.prototype.dispose = function () { | ||
| if (this.isDisposed) { | ||
| return; | ||
| } | ||
| this._isDisposed = true; | ||
| signaling_1.Signal.clearData(this); | ||
| this._map.clear(); | ||
| }; | ||
| return ObservableMap; | ||
| }()); | ||
| exports.ObservableMap = ObservableMap; | ||
| /** | ||
| * The namespace for module private data. | ||
| */ | ||
| var Private; | ||
| (function (Private) { | ||
| /** | ||
| * The default strict equality item comparator. | ||
| */ | ||
| function itemCmp(first, second) { | ||
| return first === second; | ||
| } | ||
| Private.itemCmp = itemCmp; | ||
| })(Private || (Private = {})); | ||
| //# sourceMappingURL=observablemap.js.map |
| {"version":3,"file":"observablemap.js","sourceRoot":"","sources":["../../../../coreutils/src/observablemap.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAM3D,iDAE6B;AAkJ7B;;GAEG;AACH;IAEE;;OAEG;IACH,uBAAY,OAAuC;QAAvC,wBAAA,EAAA,YAAuC;QAqK3C,SAAI,GAAmB,IAAI,GAAG,EAAa,CAAC;QAE5C,aAAQ,GAAG,IAAI,kBAAM,CAAuC,IAAI,CAAC,CAAC;QAClE,gBAAW,GAAG,KAAK,CAAC;QAvK1B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;QACnD,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;YACnB,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC/B,IAAI,CAAC,IAAI,CAAC,G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AiD;QACjD,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC1B,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,+BAAO,GAAP;QACE,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;YACpB,MAAM,CAAC;QACT,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,kBAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAMH,oBAAC;AAAD,CAAC,AA9KD,IA8KC;AA7KK,sCAAa;AAyMnB;;GAEG;AACH,IAAU,OAAO,CAQhB;AARD,WAAU,OAAO;IACf;;OAEG;IACH,iBACiB,KAAU,EAAE,MAAW;QACtC,MAAM,CAAC,KAAK,KAAK,MAAM,CAAC;IAC1B,CAAC;IAFQ,eAAO,UAEf,CAAA;AACH,CAAC,EARS,OAAO,KAAP,OAAO,QAQhB","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport {\n IDisposable\n} from '@phosphor/disposable';\n\nimport {\n ISignal, Signal\n} from '@phosphor/signaling';\n\nimport {\n IObservable\n} from './modeldb';\n\n\n/**\n * A map which can be observed for changes.\n */\nexport\ninterface IObservableMap<T> extends IDisposable, IObservable {\n /**\n * The type of the Observable.\n */\n type: 'Map';\n\n /**\n * A signal emitted when the map has changed.\n */\n readonly changed: ISignal<this, IObservableMap.IChangedArgs<T>>;\n\n /**\n * The number of key-value pairs in the map.\n */\n readonly size: number;\n\n /**\n * Set a key-value pair in the map\n *\n * @param key - The key to set.\n *\n * @param value - The value for the key.\n *\n * @returns the old value for the key, or undefined\n * if that did not exist.\n */\n set(key: string, value: T): T | undefined;\n\n /**\n * Get a value for a given key.\n *\n * @param key - the key.\n *\n * @returns the value for that key.\n */\n get(key: string): T | undefined;\n\n /**\n * Check whether the map has a key.\n *\n * @param key - the key to check.\n *\n * @returns `true` if the map has the key, `false` otherwise.\n */\n has(key: string): boolean;\n\n /**\n * Get a list of the keys in the map.\n *\n * @returns - a list of keys.\n */\n keys(): string[];\n\n /**\n * Get a list of the values in the map.\n *\n * @returns - a list of values.\n */\n values(): T[];\n\n /**\n * Remove a key from the map\n *\n * @param key - the key to remove.\n *\n * @returns the value of the given key,\n * or undefined if that does not exist.\n */\n delete(key: string): T | undefined;\n\n /**\n * Set the ObservableMap to an empty map.\n */\n clear(): void;\n\n /**\n * Dispose of the resources held by the map.\n */\n dispose(): void;\n}\n\n\n/**\n * The interfaces associated with an IObservableMap.\n */\nexport\nnamespace IObservableMap {\n /**\n * The change types which occur on an observable map.\n */\n export\n type ChangeType =\n /**\n * An entry was added.\n */\n 'add' |\n\n /**\n * An entry was removed.\n */\n 'remove' |\n\n /**\n * An entry was changed.\n */\n 'change';\n\n /**\n * The changed args object which is emitted by an observable map.\n */\n export\n interface IChangedArgs<T> {\n /**\n * The type of change undergone by the map.\n */\n type: ChangeType;\n\n /**\n * The key of the change.\n */\n key: string;\n\n /**\n * The old value of the change.\n */\n oldValue: T | undefined;\n\n /**\n * The new value of the change.\n */\n newValue: T | undefined;\n }\n}\n\n\n/**\n * A concrete implementation of IObservbleMap<T>.\n */\nexport\nclass ObservableMap<T> implements IObservableMap<T> {\n /**\n * Construct a new observable map.\n */\n constructor(options: ObservableMap.IOptions<T> = {}) {\n this._itemCmp = options.itemCmp || Private.itemCmp;\n if (options.values) {\n for (let key in options.values) {\n this._map.set(key, options.values[key]);\n }\n }\n }\n\n /**\n * The type of the Observable.\n */\n get type(): 'Map' {\n return 'Map';\n }\n\n\n /**\n * A signal emitted when the map has changed.\n */\n get changed(): ISignal<this, IObservableMap.IChangedArgs<T>> {\n return this._changed;\n }\n\n /**\n * Whether this map has been disposed.\n */\n get isDisposed(): boolean {\n return this._isDisposed;\n }\n\n /**\n * The number of key-value pairs in the map.\n */\n get size(): number {\n return this._map.size;\n }\n\n /**\n * Set a key-value pair in the map\n *\n * @param key - The key to set.\n *\n * @param value - The value for the key.\n *\n * @returns the old value for the key, or undefined\n * if that did not exist.\n *\n * @throws if the new value is undefined.\n *\n * #### Notes\n * This is a no-op if the value does not change.\n */\n set(key: string, value: T): T | undefined {\n let oldVal = this._map.get(key);\n if (value === undefined) {\n throw Error('Cannot set an undefined value, use remove');\n }\n // Bail if the value does not change.\n let itemCmp = this._itemCmp;\n if (oldVal !== undefined && itemCmp(oldVal, value)) {\n return oldVal;\n }\n this._map.set(key, value);\n this._changed.emit({\n type: oldVal ? 'change' : 'add',\n key: key,\n oldValue: oldVal,\n newValue: value\n });\n return oldVal;\n }\n\n /**\n * Get a value for a given key.\n *\n * @param key - the key.\n *\n * @returns the value for that key.\n */\n get(key: string): T | undefined {\n return this._map.get(key);\n }\n\n /**\n * Check whether the map has a key.\n *\n * @param key - the key to check.\n *\n * @returns `true` if the map has the key, `false` otherwise.\n */\n has(key: string): boolean {\n return this._map.has(key);\n }\n\n /**\n * Get a list of the keys in the map.\n *\n * @returns - a list of keys.\n */\n keys(): string[] {\n let keyList: string[] = [];\n this._map.forEach((v: T, k: string) => {\n keyList.push(k);\n });\n return keyList;\n }\n\n\n /**\n * Get a list of the values in the map.\n *\n * @returns - a list of values.\n */\n values(): T[] {\n let valList: T[] = [];\n this._map.forEach((v: T, k: string) => {\n valList.push(v);\n });\n return valList;\n }\n\n /**\n * Remove a key from the map\n *\n * @param key - the key to remove.\n *\n * @returns the value of the given key,\n * or undefined if that does not exist.\n */\n delete(key: string): T | undefined {\n let oldVal = this._map.get(key);\n this._map.delete(key);\n this._changed.emit({\n type: 'remove',\n key: key,\n oldValue: oldVal,\n newValue: undefined\n });\n return oldVal;\n }\n\n /**\n * Set the ObservableMap to an empty map.\n */\n clear(): void {\n // Delete one by one to emit the correct signals.\n let keyList = this.keys();\n for (let i = 0; i < keyList.length; i++) {\n this.delete(keyList[i]);\n }\n }\n\n /**\n * Dispose of the resources held by the map.\n */\n dispose(): void {\n if (this.isDisposed) {\n return;\n }\n this._isDisposed = true;\n Signal.clearData(this);\n this._map.clear();\n }\n\n private _map: Map<string, T> = new Map<string, T>();\n private _itemCmp: (first: T, second: T) => boolean;\n private _changed = new Signal<this, IObservableMap.IChangedArgs<T>>(this);\n private _isDisposed = false;\n}\n\n\n/**\n * The namespace for `ObservableMap` class statics.\n */\nexport\nnamespace ObservableMap {\n /**\n * The options used to initialize an observable map.\n */\n export\n interface IOptions<T> {\n /**\n * An optional intial set of values.\n */\n values?: { [key: string]: T };\n\n /**\n * The item comparison function for change detection on `set`.\n *\n * If not given, strict `===` equality will be used.\n */\n itemCmp?: (first: T, second: T) => boolean;\n }\n}\n\n\n/**\n * The namespace for module private data.\n */\nnamespace Private {\n /**\n * The default strict equality item comparator.\n */\n export\n function itemCmp(first: any, second: any): boolean {\n return first === second;\n }\n}\n"]} |
| import { IDisposable } from '@phosphor/disposable'; | ||
| import { ISignal } from '@phosphor/signaling'; | ||
| import { IObservable } from './modeldb'; | ||
| /** | ||
| * A string which can be observed for changes. | ||
| */ | ||
| export interface IObservableString extends IDisposable, IObservable { | ||
| /** | ||
| * The type of the Observable. | ||
| */ | ||
| type: 'String'; | ||
| /** | ||
| * A signal emitted when the string has changed. | ||
| */ | ||
| readonly changed: ISignal<this, IObservableString.IChangedArgs>; | ||
| /** | ||
| * The value of the string. | ||
| */ | ||
| text: string; | ||
| /** | ||
| * Insert a substring. | ||
| * | ||
| * @param index - The starting index. | ||
| * | ||
| * @param text - The substring to insert. | ||
| */ | ||
| insert(index: number, text: string): void; | ||
| /** | ||
| * Remove a substring. | ||
| * | ||
| * @param start - The starting index. | ||
| * | ||
| * @param end - The ending index. | ||
| */ | ||
| remove(start: number, end: number): void; | ||
| /** | ||
| * Set the ObservableString to an empty string. | ||
| */ | ||
| clear(): void; | ||
| /** | ||
| * Dispose of the resources held by the string. | ||
| */ | ||
| dispose(): void; | ||
| } | ||
| /** | ||
| * The namespace for `IObservableString` associate interfaces. | ||
| */ | ||
| export declare namespace IObservableString { | ||
| /** | ||
| * The change types which occur on an observable string. | ||
| */ | ||
| type ChangeType = 'insert' | 'remove' | 'set'; | ||
| /** | ||
| * The changed args object which is emitted by an observable string. | ||
| */ | ||
| interface IChangedArgs { | ||
| /** | ||
| * The type of change undergone by the list. | ||
| */ | ||
| type: ChangeType; | ||
| /** | ||
| * The starting index of the change. | ||
| */ | ||
| start: number; | ||
| /** | ||
| * The end index of the change. | ||
| */ | ||
| end: number; | ||
| /** | ||
| * The value of the change. | ||
| * | ||
| * ### Notes | ||
| * If `ChangeType` is `set`, then | ||
| * this is the new value of the string. | ||
| * | ||
| * If `ChangeType` is `insert` this is | ||
| * the value of the inserted string. | ||
| * | ||
| * If `ChangeType` is remove this is the | ||
| * value of the removed substring. | ||
| */ | ||
| value: string; | ||
| } | ||
| } | ||
| /** | ||
| * A concrete implementation of [[IObservableString]] | ||
| */ | ||
| export declare class ObservableString implements IObservableString { | ||
| /** | ||
| * Construct a new observable string. | ||
| */ | ||
| constructor(initialText?: string); | ||
| /** | ||
| * The type of the Observable. | ||
| */ | ||
| readonly type: 'String'; | ||
| /** | ||
| * A signal emitted when the string has changed. | ||
| */ | ||
| readonly changed: ISignal<this, IObservableString.IChangedArgs>; | ||
| /** | ||
| * Get the value of the string. | ||
| */ | ||
| /** | ||
| * Set the value of the string. | ||
| */ | ||
| text: string; | ||
| /** | ||
| * Insert a substring. | ||
| * | ||
| * @param index - The starting index. | ||
| * | ||
| * @param text - The substring to insert. | ||
| */ | ||
| insert(index: number, text: string): void; | ||
| /** | ||
| * Remove a substring. | ||
| * | ||
| * @param start - The starting index. | ||
| * | ||
| * @param end - The ending index. | ||
| */ | ||
| remove(start: number, end: number): void; | ||
| /** | ||
| * Set the ObservableString to an empty string. | ||
| */ | ||
| clear(): void; | ||
| /** | ||
| * Test whether the string has been disposed. | ||
| */ | ||
| readonly isDisposed: boolean; | ||
| /** | ||
| * Dispose of the resources held by the string. | ||
| */ | ||
| dispose(): void; | ||
| private _text; | ||
| private _isDisposed; | ||
| private _changed; | ||
| } |
| "use strict"; | ||
| // Copyright (c) Jupyter Development Team. | ||
| // Distributed under the terms of the Modified BSD License. | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var signaling_1 = require("@phosphor/signaling"); | ||
| /** | ||
| * A concrete implementation of [[IObservableString]] | ||
| */ | ||
| var ObservableString = (function () { | ||
| /** | ||
| * Construct a new observable string. | ||
| */ | ||
| function ObservableString(initialText) { | ||
| if (initialText === void 0) { initialText = ''; } | ||
| this._text = ''; | ||
| this._isDisposed = false; | ||
| this._changed = new signaling_1.Signal(this); | ||
| this._text = initialText; | ||
| } | ||
| Object.defineProperty(ObservableString.prototype, "type", { | ||
| /** | ||
| * The type of the Observable. | ||
| */ | ||
| get: function () { | ||
| return 'String'; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| Object.defineProperty(ObservableString.prototype, "changed", { | ||
| /** | ||
| * A signal emitted when the string has changed. | ||
| */ | ||
| get: function () { | ||
| return this._changed; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| Object.defineProperty(ObservableString.prototype, "text", { | ||
| /** | ||
| * Get the value of the string. | ||
| */ | ||
| get: function () { | ||
| return this._text; | ||
| }, | ||
| /** | ||
| * Set the value of the string. | ||
| */ | ||
| set: function (value) { | ||
| if (value.length === this._text.length && value === this._text) { | ||
| return; | ||
| } | ||
| this._text = value; | ||
| this._changed.emit({ | ||
| type: 'set', | ||
| start: 0, | ||
| end: value.length, | ||
| value: value | ||
| }); | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| /** | ||
| * Insert a substring. | ||
| * | ||
| * @param index - The starting index. | ||
| * | ||
| * @param text - The substring to insert. | ||
| */ | ||
| ObservableString.prototype.insert = function (index, text) { | ||
| this._text = this._text.slice(0, index) + | ||
| text + | ||
| this._text.slice(index); | ||
| this._changed.emit({ | ||
| type: 'insert', | ||
| start: index, | ||
| end: index + text.length, | ||
| value: text | ||
| }); | ||
| }; | ||
| /** | ||
| * Remove a substring. | ||
| * | ||
| * @param start - The starting index. | ||
| * | ||
| * @param end - The ending index. | ||
| */ | ||
| ObservableString.prototype.remove = function (start, end) { | ||
| var oldValue = this._text.slice(start, end); | ||
| this._text = this._text.slice(0, start) + | ||
| this._text.slice(end); | ||
| this._changed.emit({ | ||
| type: 'remove', | ||
| start: start, | ||
| end: end, | ||
| value: oldValue | ||
| }); | ||
| }; | ||
| /** | ||
| * Set the ObservableString to an empty string. | ||
| */ | ||
| ObservableString.prototype.clear = function () { | ||
| this.text = ''; | ||
| }; | ||
| Object.defineProperty(ObservableString.prototype, "isDisposed", { | ||
| /** | ||
| * Test whether the string has been disposed. | ||
| */ | ||
| get: function () { | ||
| return this._isDisposed; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| /** | ||
| * Dispose of the resources held by the string. | ||
| */ | ||
| ObservableString.prototype.dispose = function () { | ||
| if (this._isDisposed) { | ||
| return; | ||
| } | ||
| this._isDisposed = true; | ||
| signaling_1.Signal.clearData(this); | ||
| this.clear(); | ||
| }; | ||
| return ObservableString; | ||
| }()); | ||
| exports.ObservableString = ObservableString; | ||
| //# sourceMappingURL=observablestring.js.map |
| {"version":3,"file":"observablestring.js","sourceRoot":"","sources":["../../../../coreutils/src/observablestring.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAM3D,iDAE6B;AAwH7B;;GAEG;AACH;IAEE;;OAEG;IACH,0BAAY,WAAwB;QAAxB,4BAAA,EAAA,gBAAwB;QAyG5B,UAAK,GAAG,EAAE,CAAC;QACX,gBAAW,GAAa,KAAK,CAAC;QAC9B,aAAQ,GA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OAMG;IACH,iCAAM,GAAN,UAAO,KAAa,EAAE,GAAW;QAC/B,IAAI,QAAQ,GAAW,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACpD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;YAC1B,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACjB,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,KAAK;YACZ,GAAG,EAAE,GAAG;YACR,KAAK,EAAE,QAAQ;SAChB,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,gCAAK,GAAL;QACE,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;IACjB,CAAC;IAKD,sBAAI,wCAAU;QAHd;;WAEG;aACH;YACE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;;;OAAA;IAED;;OAEG;IACH,kCAAO,GAAP;QACE,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;YACrB,MAAM,CAAC;QACT,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,kBAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACvB,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAKH,uBAAC;AAAD,CAAC,AAjHD,IAiHC;AAhHK,4CAAgB","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport {\n IDisposable\n} from '@phosphor/disposable';\n\nimport {\n ISignal, Signal\n} from '@phosphor/signaling';\n\nimport {\n IObservable\n} from './modeldb';\n\n\n/**\n * A string which can be observed for changes.\n */\nexport\ninterface IObservableString extends IDisposable, IObservable {\n /**\n * The type of the Observable.\n */\n type: 'String';\n\n /**\n * A signal emitted when the string has changed.\n */\n readonly changed: ISignal<this, IObservableString.IChangedArgs>;\n\n /**\n * The value of the string.\n */\n text: string;\n\n /**\n * Insert a substring.\n *\n * @param index - The starting index.\n *\n * @param text - The substring to insert.\n */\n insert(index: number, text: string): void;\n\n /**\n * Remove a substring.\n *\n * @param start - The starting index.\n *\n * @param end - The ending index.\n */\n remove(start: number, end: number): void;\n\n /**\n * Set the ObservableString to an empty string.\n */\n clear(): void;\n\n /**\n * Dispose of the resources held by the string.\n */\n dispose(): void;\n}\n\n\n/**\n * The namespace for `IObservableString` associate interfaces.\n */\nexport\nnamespace IObservableString {\n /**\n * The change types which occur on an observable string.\n */\n export\n type ChangeType =\n /**\n * Text was inserted.\n */\n 'insert' |\n\n /**\n * Text was removed.\n */\n 'remove' |\n\n /**\n * Text was set.\n */\n 'set';\n\n /**\n * The changed args object which is emitted by an observable string.\n */\n export\n interface IChangedArgs {\n /**\n * The type of change undergone by the list.\n */\n type: ChangeType;\n\n /**\n * The starting index of the change.\n */\n start: number;\n\n /**\n * The end index of the change.\n */\n end: number;\n\n /**\n * The value of the change.\n *\n * ### Notes\n * If `ChangeType` is `set`, then\n * this is the new value of the string.\n *\n * If `ChangeType` is `insert` this is\n * the value of the inserted string.\n *\n * If `ChangeType` is remove this is the\n * value of the removed substring.\n */\n value: string;\n }\n}\n\n\n/**\n * A concrete implementation of [[IObservableString]]\n */\nexport\nclass ObservableString implements IObservableString {\n /**\n * Construct a new observable string.\n */\n constructor(initialText: string = '') {\n this._text = initialText;\n }\n\n /**\n * The type of the Observable.\n */\n get type(): 'String' {\n return 'String';\n }\n\n /**\n * A signal emitted when the string has changed.\n */\n get changed(): ISignal<this, IObservableString.IChangedArgs> {\n return this._changed;\n }\n\n /**\n * Set the value of the string.\n */\n set text( value: string ) {\n if (value.length === this._text.length && value === this._text) {\n return;\n }\n this._text = value;\n this._changed.emit({\n type: 'set',\n start: 0,\n end: value.length,\n value: value\n });\n }\n\n /**\n * Get the value of the string.\n */\n get text(): string {\n return this._text;\n }\n\n /**\n * Insert a substring.\n *\n * @param index - The starting index.\n *\n * @param text - The substring to insert.\n */\n insert(index: number, text: string): void {\n this._text = this._text.slice(0, index) +\n text +\n this._text.slice(index);\n this._changed.emit({\n type: 'insert',\n start: index,\n end: index + text.length,\n value: text\n });\n }\n\n /**\n * Remove a substring.\n *\n * @param start - The starting index.\n *\n * @param end - The ending index.\n */\n remove(start: number, end: number): void {\n let oldValue: string = this._text.slice(start, end);\n this._text = this._text.slice(0, start) +\n this._text.slice(end);\n this._changed.emit({\n type: 'remove',\n start: start,\n end: end,\n value: oldValue\n });\n }\n\n /**\n * Set the ObservableString to an empty string.\n */\n clear(): void {\n this.text = '';\n }\n\n /**\n * Test whether the string has been disposed.\n */\n get isDisposed(): boolean {\n return this._isDisposed;\n }\n\n /**\n * Dispose of the resources held by the string.\n */\n dispose(): void {\n if (this._isDisposed) {\n return;\n }\n this._isDisposed = true;\n Signal.clearData(this);\n this.clear();\n }\n\n private _text = '';\n private _isDisposed : boolean = false;\n private _changed = new Signal<this, IObservableString.IChangedArgs>(this);\n}\n"]} |
| {"version":3,"file":"pageconfig.js","sourceRoot":"","sources":["../../../../coreutils/src/pageconfig.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D,iDAE6B;AAE7B,mCACkB;AAElB,6BAEe;AAUf;;GAEG;AACH,IACU,UAAU,CAsHnB;AAvHD,WACU,UAAU;IAClB;;;;;;;;;;;;;;;OAeG;IACH,mBACmB,IAAY;QAC7B,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;YACf,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAChC,CAAC;QACD,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,KAAK,GAAG,KAAK,CAAC;QAElB,+BAA+B;QAC/B,EAAE,CAAC,CAAC,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC;YACpC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AAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAClD,CAAC;gBAAC,IAAI,CAAC,CAAC;oBACN,OAAO,GAAG,YAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAC;gBAC3D,CAAC;YACH,CAAC;YACD,KAAK,GAAG,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAClC,CAAC;QACD,MAAM,CAAC,YAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;IACxC,CAAC;IAdQ,mBAAQ,WAchB,CAAA;IAED;;OAEG;IACH,IAAI,UAAU,GAAqC,IAAI,CAAC;AAC1D,CAAC,EAtHS,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAsHnB","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport {\n JSONExt\n} from '@phosphor/coreutils';\n\nimport * as minimist\n from 'minimist';\n\nimport {\n URLExt\n} from './url';\n\n\n/**\n * Declare stubs for the node variables.\n */\ndeclare var process: any;\ndeclare var require: any;\n\n\n/**\n * The namespace for Page Config functions.\n */\nexport\nnamespace PageConfig {\n /**\n * Get global configuration data for the Jupyter application.\n *\n * @param name - The name of the configuration option.\n *\n * @returns The config value or an empty string if not found.\n *\n * #### Notes\n * All values are treated as strings.\n * For browser based applications, it is assumed that the page HTML\n * includes a script tag with the id `jupyter-config-data` containing the\n * configuration as valid JSON.\n * For node applications, it is assumed that the process was launched\n * with a `--jupyter-config-data` option pointing to a JSON settings\n * file.\n */\n export\n function getOption(name: string): string {\n if (configData) {\n return configData[name] || '';\n }\n configData = Object.create(null);\n let found = false;\n\n // Use script tag if available.\n if (typeof document !== 'undefined') {\n const el = document.getElementById('jupyter-config-data');\n\n if (el) {\n configData = JSON.parse(el.textContent || '') as {\n [key: string]: string\n };\n found = true;\n }\n }\n // Otherwise use CLI if given.\n if (!found && typeof process !== 'undefined') {\n try {\n const cli = minimist(process.argv.slice(2));\n if ('jupyter-config-data' in cli) {\n const path: any = require('path');\n const fullPath = path.resolve(cli['jupyter-config-data']);\n\n /* tslint:disable */\n // Force Webpack to ignore this require.\n configData = eval('require')(fullPath) as { [key: string]: string };\n /* tslint:enable */\n }\n } catch (e) {\n console.error(e);\n }\n }\n\n if (!JSONExt.isObject(configData)) {\n configData = Object.create(null);\n } else {\n for (let key in configData) {\n // Quote characters are escaped, unescape them.\n configData[key] = String(configData[key]).split(''').join('\"');\n }\n }\n return configData![name] || '';\n }\n\n /**\n * Set global configuration data for the Jupyter application.\n *\n * @param name - The name of the configuration option.\n * @param value - The value to set the option to.\n *\n * @returns The last config value or an empty string if it doesn't exist.\n */\n export\n function setOption(name: string, value: string): string {\n const last = getOption(name);\n\n configData![name] = value;\n return last;\n }\n\n /**\n * Get the base url for a Jupyter application.\n */\n export\n function getBaseUrl(): string {\n let baseUrl = getOption('baseUrl');\n if (!baseUrl || baseUrl === '/') {\n baseUrl = (typeof location === 'undefined' ?\n 'http://localhost:8888/' : location.origin + '/');\n }\n return URLExt.parse(baseUrl).toString();\n }\n\n /**\n * Get the base websocket URLExt for a Jupyter application.\n */\n export\n function getWsUrl(baseUrl?: string): string {\n let wsUrl = getOption('wsUrl');\n if (!wsUrl) {\n baseUrl = baseUrl || getBaseUrl();\n if (baseUrl.indexOf('http') !== 0) {\n if (typeof location !== 'undefined') {\n baseUrl = URLExt.join(location.origin, baseUrl);\n } else {\n baseUrl = URLExt.join('http://localhost:8888/', baseUrl);\n }\n }\n wsUrl = 'ws' + baseUrl.slice(4);\n }\n return URLExt.parse(wsUrl).toString();\n }\n\n /**\n * Private page config data for the Jupyter application.\n */\n let configData: { [key: string]: string } | null = null;\n}\n"]} |
| {"version":3,"file":"path.js","sourceRoot":"","sources":["../../../../coreutils/src/path.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D,kCACmB;AAGnB;;;;GAIG;AACH,IACU,O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AC;IAFQ,eAAO,UAEf,CAAA;IAED;;;;;;;;;;;;OAYG;IACH,kBACkB,IAAY,EAAE,EAAU;QACxC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;IAFQ,gBAAQ,WAEhB,CAAA;IAED;;;;;;;OAOG;IACH,4BAC4B,SAAiB;QAC3C,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACzD,SAAS,GAAG,MAAI,SAAW,CAAC;QAC9B,CAAC;QACD,MAAM,CAAC,SAAS,CAAC;IACnB,CAAC;IALQ,0BAAkB,qBAK1B,CAAA;IAED;;;;OAIG;IACH,qBACqB,IAAY;QAC/B,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC5B,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;QACD,MAAM,CAAC,IAAI,CAAC;IACd,CAAC;IALQ,mBAAW,cAKnB,CAAA;AACH,CAAC,EAvIS,OAAO,GAAP,eAAO,KAAP,eAAO,QAuIhB","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport * as posix\n from 'path-posix';\n\n\n/**\n * The namespace for path-related functions.\n *\n * Note that Jupyter server paths do not start with a leading slash.\n */\nexport\nnamespace PathExt {\n /**\n * Join all arguments together and normalize the resulting path.\n * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown.\n *\n * @param paths - The string paths to join.\n */\n export\n function join(...paths: string[]): string {\n return removeSlash(posix.join(...paths));\n }\n\n /**\n * Return the last portion of a path. Similar to the Unix basename command.\n * Often used to extract the file name from a fully qualified path.\n *\n * @param path - The path to evaluate.\n *\n * @param ext - An extension to remove from the result.\n */\n export\n function basename(path: string, ext?: string): string {\n return posix.basename(path, ext);\n }\n\n /**\n * Get the directory name of a path, similar to the Unix dirname command.\n * When an empty path is given, returns the root path.\n *\n * @param path - The file path.\n */\n export\n function dirname(path: string): string {\n let dir = removeSlash(posix.dirname(path));\n return dir === '.' ? '' : dir;\n }\n\n /**\n * Get the extension of the path.\n *\n * @param path - The file path.\n *\n * @returns the extension of the file.\n *\n * #### Notes\n * The extension is the string from the last occurence of the `.`\n * character to end of string in the last portion of the path, inclusive.\n * If there is no `.` in the last portion of the path, or if the first\n * character of the basename of path [[basename]] is `.`, then an\n * empty string is returned.\n */\n export\n function extname(path: string): string {\n return posix.extname(path);\n }\n\n /**\n * Normalize a string path, reducing '..' and '.' parts.\n * When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.\n * When an empty path is given, returns the root path.\n *\n * @param path - The string path to normalize.\n */\n export\n function normalize(path: string): string {\n if (path === '') {\n return '';\n }\n return removeSlash(posix.normalize(path));\n }\n\n /**\n * Resolve a sequence of paths or path segments into an absolute path.\n * The root path in the application has no leading slash, so it is removed.\n *\n * @param parts - The paths to join.\n *\n * #### Notes\n * The right-most parameter is considered {to}. Other parameters are considered an array of {from}.\n *\n * Starting from leftmost {from} parameter, resolves {to} to an absolute path.\n *\n * If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory.\n */\n export\n function resolve(...parts: string[]): string {\n return removeSlash(posix.resolve(...parts));\n }\n\n /**\n * Solve the relative path from {from} to {to}.\n *\n * @param from - The source path.\n *\n * @param to - The target path.\n *\n * #### Notes\n * If from and to each resolve to the same path (after calling\n * path.resolve() on each), a zero-length string is returned.\n * If a zero-length string is passed as from or to, `/`\n * will be used instead of the zero-length strings.\n */\n export\n function relative(from: string, to: string): string {\n return removeSlash(posix.relative(from, to));\n }\n\n /**\n * Normalize a file extension to be of the type `'.foo'`.\n *\n * @param extension - the file extension.\n *\n * #### Notes\n * Adds a leading dot if not present and converts to lower case.\n */\n export\n function normalizeExtension(extension: string): string {\n if (extension.length > 0 && extension.indexOf('.') !== 0) {\n extension = `.${extension}`;\n }\n return extension;\n }\n\n /**\n * Remove the leading slash from a path.\n *\n * @param path: the path from which to remove a leading slash.\n */\n export\n function removeSlash(path: string): string {\n if (path.indexOf('/') === 0) {\n path = path.slice(1);\n }\n return path;\n }\n}\n"]} |
| {"version":3,"file":"settingregistry.js","sourceRoot":"","sources":["../../../../coreutils/src/settingregistry.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D,yBAA2B;AAE3B,iDAE6B;AAE7B,iDAE6B;AAM7B,iDAE6B;AAO7B;;GAEG;AAEG,QAAA,cAAc,GAAE,gCAAgC,CAAC;AAEvD;;GAEG;AAEG,QAAA,cAAc,GAAG,gCAAgC,CAAC;AAExD;;GAEG;AACH,IAAM,IAAI,GAAG,mBAAO,CAAC,QAAQ,CAAC;AAqE9B,oBAAoB;AACpB;;GAEG;AAEG,QAAA,gBAAgB,GAAG,IAAI,iBAAK,CAAmB,wCAAwC,CAAC,CAAC;AA4M/F;;GAEG;AACH;IAEE;;OAEG;IACH;QAgFQ,cAAS,GAAG,IAAI,GAAG,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3C,eAAU,GAAG,IAAI,GAAG,EAAE,CAAC;QAhF7B,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjD,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,0CAAS,GAAT,UAAU,MAAc,EAAE,MAAgC;QACxD,IAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC;Q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AAC,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,gBAAgB,MAAc,EAAE,GAAe;QAAf,oBAAA,EAAA,eAAe;QAC7C,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAK,GAAK,CAAC,CAAC;IACnD,CAAC;IAED;;OAEG;IACH,sBACsB,MAAgC,EAAE,IAAa;QACnE,6DAA6D;QAC7D,MAAM,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,EAAG,CAAC;QAE1D,4DAA4D;QAC5D,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC;YACvD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;QACxB,CAAC;QAED,gDAAgD;QAChD,IAAM,MAAM,GAAG,mBAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAEhD,oDAAoD;QACpD,GAAG,CAAC,CAAC,IAAI,QAAQ,IAAI,MAAM,CAAC,UAAU,IAAI,EAAG,CAAC,CAAC,CAAC;YAC9C,MAAM,CAAC,QAAQ,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC/D,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAChB,CAAC;IAlBQ,oBAAY,eAkBpB,CAAA;;AACH,CAAC,EA3GS,OAAO,GAAP,eAAO,KAAP,eAAO,QA2GhB","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport * as Ajv from 'ajv';\n\nimport {\n find\n} from '@phosphor/algorithm';\n\nimport {\n JSONExt, JSONObject, JSONValue, Token\n} from '@phosphor/coreutils';\n\nimport {\n IDisposable\n} from '@phosphor/disposable';\n\nimport {\n ISignal, Signal\n} from '@phosphor/signaling';\n\nimport {\n IDataConnector\n} from './interfaces';\n\n\n/**\n * The key in the schema for setting editor icon class hints.\n */\nexport\nconst ICON_CLASS_KEY ='jupyter.lab.setting-icon-class';\n\n/**\n * The key in the schema for setting editor icon label hints.\n */\nexport\nconst ICON_LABEL_KEY = 'jupyter.lab.setting-icon-label';\n\n/**\n * An alias for the JSON deep copy function.\n */\nconst copy = JSONExt.deepCopy;\n\n\n/**\n * An implementation of a schema validator.\n */\nexport\ninterface ISchemaValidator {\n /**\n * Add a schema to the validator.\n *\n * @param plugin - The plugin ID.\n *\n * @param schema - The schema being added.\n *\n * @return A list of errors if the schema fails to validate or `null` if there\n * are no errors.\n *\n * #### Notes\n * It is safe to call this function multiple times with the same plugin name.\n */\n addSchema(plugin: string, schema: ISettingRegistry.ISchema): ISchemaValidator.IError[] | null;\n\n /**\n * Validate a plugin's schema and user data; populate the `composite` data.\n *\n * @param plugin - The plugin being validated. Its `composite` data will be\n * populated by reference.\n *\n * @return A list of errors if either the schema or data fail to validate or\n * `null` if there are no errors.\n */\n validateData(plugin: ISettingRegistry.IPlugin): ISchemaValidator.IError[] | null;\n}\n\n\n/**\n * A namespace for schema validator interfaces.\n */\nexport\nnamespace ISchemaValidator {\n /**\n * A schema validation error definition.\n */\n export\n interface IError {\n /**\n * The path in the data where the error occurred.\n */\n dataPath: string;\n\n /**\n * The keyword whose validation failed.\n */\n keyword: string;\n\n /**\n * The error message.\n */\n message: string;\n\n /**\n * The path in the schema where the error occurred.\n */\n schemaPath: string;\n }\n}\n\n\n/* tslint:disable */\n/**\n * The setting registry token.\n */\nexport\nconst ISettingRegistry = new Token<ISettingRegistry>('@jupyterlab/coreutils:ISettingRegistry');\n/* tslint:enable */\n\n\n/**\n * A namespace for setting registry interfaces.\n */\nexport\nnamespace ISettingRegistry {\n /**\n * The settings for a specific plugin.\n */\n export\n interface IPlugin extends JSONObject {\n /**\n * The name of the plugin.\n */\n id: string;\n\n /**\n * The collection of values for a specified setting.\n */\n data: ISettingBundle;\n\n /**\n * The JSON schema for the plugin.\n */\n schema: ISchema;\n }\n\n /**\n * A schema type that is a minimal subset of the formal JSON Schema along with\n * optional JupyterLab rendering hints.\n */\n export\n interface ISchema extends JSONObject {\n /**\n * The JupyterLab icon class hint for a plugin can be overridden by user\n * settings. It can also be root level and therefore \"private\".\n */\n 'jupyter.lab.setting-icon-class'?: string;\n\n /**\n * The JupyterLab icon label hint for a plugin can be overridden by user\n * settings. It can also be root level and therefore \"private\".\n */\n 'jupyter.lab.setting-icon-label'?: string;\n\n /**\n * The default value, if any.\n */\n default?: any;\n\n /**\n * The schema description.\n */\n description?: string;\n\n /**\n * The schema's child properties.\n */\n properties?: {\n /**\n * The JupyterLab icon class hint for a plugin can be overridden by user\n * settings. It can also be root level and therefore \"private\".\n */\n 'jupyter.lab.setting-icon-class'?: ISchema;\n\n /**\n * The JupyterLab icon label hint for a plugin can be overridden by user\n * settings. It can also be root level and therefore \"private\".\n */\n 'jupyter.lab.setting-icon-label'?: ISchema;\n\n /**\n * Arbitrary setting keys can be added.\n */\n [key: string]: ISchema;\n };\n\n /**\n * The title of the schema.\n */\n title?: string;\n\n /**\n * The type or types of the data.\n */\n type?: string | string[];\n }\n\n /**\n * The setting values for a plugin.\n */\n export\n interface ISettingBundle extends JSONObject {\n /**\n * A composite of the user setting values and the plugin schema defaults.\n *\n * #### Notes\n * The `composite` values will always be a superset of the `user` values.\n */\n composite: JSONObject;\n\n /**\n * The user setting values.\n */\n user: JSONObject;\n }\n\n /**\n * An interface for manipulating the settings of a specific plugin.\n */\n export\n interface ISettings extends IDisposable {\n /**\n * A signal that emits when the plugin's settings have changed.\n */\n readonly changed: ISignal<this, void>;\n\n /**\n * Get the composite of user settings and extension defaults.\n */\n readonly composite: JSONObject;\n\n /*\n * The plugin name.\n */\n readonly plugin: string;\n\n /**\n * Get the plugin settings schema.\n */\n readonly schema: ISettingRegistry.ISchema;\n\n /**\n * Get the user settings.\n */\n readonly user: JSONObject;\n\n /**\n * Return the defaults in a commented JSON format.\n */\n annotatedDefaults(): string;\n\n /**\n * Calculate the default value of a setting by iterating through the schema.\n *\n * @param key - The name of the setting whose default value is calculated.\n *\n * @returns A calculated default JSON value for a specific setting.\n */\n default(key: string): JSONValue | undefined;\n\n /**\n * Get an individual setting.\n *\n * @param key - The name of the setting being retrieved.\n *\n * @returns The setting value.\n */\n get(key: string): { composite: JSONValue, user: JSONValue };\n\n /**\n * Remove a single setting.\n *\n * @param key - The name of the setting being removed.\n *\n * @returns A promise that resolves when the setting is removed.\n *\n * #### Notes\n * This function is asynchronous because it writes to the setting registry.\n */\n remove(key: string): Promise<void>;\n\n /**\n * Save all of the plugin's user settings at once.\n */\n save(user: JSONObject): Promise<void>;\n\n /**\n * Set a single setting.\n *\n * @param key - The name of the setting being set.\n *\n * @param value - The value of the setting.\n *\n * @returns A promise that resolves when the setting has been saved.\n *\n * #### Notes\n * This function is asynchronous because it writes to the setting registry.\n */\n set(key: string, value: JSONValue): Promise<void>;\n }\n}\n\n\n/**\n * An implementation of a setting registry.\n */\nexport\ninterface ISettingRegistry extends SettingRegistry {}\n\n\n/**\n * The default implementation of a schema validator.\n */\nexport\nclass DefaultSchemaValidator implements ISchemaValidator {\n /**\n * Instantiate a schema validator.\n */\n constructor() {\n this._composer.addSchema(Private.SCHEMA, 'main');\n this._validator.addSchema(Private.SCHEMA, 'main');\n }\n\n /**\n * Add a schema to the validator.\n *\n * @param plugin - The plugin ID.\n *\n * @param schema - The schema being added.\n *\n * @return A list of errors if the schema fails to validate or `null` if there\n * are no errors.\n *\n * #### Notes\n * It is safe to call this function multiple times with the same plugin name.\n */\n addSchema(plugin: string, schema: ISettingRegistry.ISchema): ISchemaValidator.IError[] | null {\n const composer = this._composer;\n const validator = this._validator;\n const validate = validator.getSchema('main');\n\n // Validate against the main schema.\n if (!(validate(schema) as boolean)) {\n return validate.errors as ISchemaValidator.IError[];\n }\n\n // Validate against the JSON schema meta-schema.\n if (!(validator.validateSchema(schema) as boolean)) {\n return validator.errors as ISchemaValidator.IError[];\n }\n\n // Remove if schema already exists.\n composer.removeSchema(plugin);\n validator.removeSchema(plugin);\n\n // Add schema to the validator and composer.\n composer.addSchema(schema, plugin);\n validator.addSchema(schema, plugin);\n\n return null;\n\n }\n\n /**\n * Validate a plugin's schema and user data; populate the `composite` data.\n *\n * @param plugin - The plugin being validated. Its `composite` data will be\n * populated by reference.\n *\n * @return A list of errors if either the schema or data fail to validate or\n * `null` if there are no errors.\n */\n validateData(plugin: ISettingRegistry.IPlugin): ISchemaValidator.IError[] | null {\n const validate = this._validator.getSchema(plugin.id);\n const compose = this._composer.getSchema(plugin.id);\n\n if (!validate || !compose) {\n const errors = this.addSchema(plugin.id, plugin.schema);\n\n if (errors) {\n return errors;\n }\n }\n\n if (!validate(plugin.data.user)) {\n return validate.errors as ISchemaValidator.IError[];\n }\n\n // Copy the user data before validating (and merging defaults).\n plugin.data.composite = copy(plugin.data.user);\n\n if (!compose(plugin.data.composite)) {\n return compose.errors as ISchemaValidator.IError[];\n }\n\n return null;\n }\n\n private _composer = new Ajv({ useDefaults: true });\n private _validator = new Ajv();\n}\n\n\n/**\n * The default concrete implementation of a setting registry.\n */\nexport\nclass SettingRegistry {\n /**\n * Create a new setting registry.\n */\n constructor(options: SettingRegistry.IOptions) {\n this._connector = options.connector;\n this._validator = options.validator || new DefaultSchemaValidator();\n }\n\n /**\n * The schema of the setting registry.\n */\n readonly schema = Private.SCHEMA;\n\n /**\n * A signal that emits the name of a plugin when its settings change.\n */\n get pluginChanged(): ISignal<this, string> {\n return this._pluginChanged;\n }\n\n /**\n * Returns a list of plugin settings held in the registry.\n */\n get plugins(): ISettingRegistry.IPlugin[] {\n const plugins = this._plugins;\n\n return Object.keys(plugins)\n .map(p => copy(plugins[p]) as ISettingRegistry.IPlugin);\n }\n\n /**\n * Get an individual setting.\n *\n * @param plugin - The name of the plugin whose settings are being retrieved.\n *\n * @param key - The name of the setting being retrieved.\n *\n * @returns A promise that resolves when the setting is retrieved.\n */\n get(plugin: string, key: string): Promise<{ composite: JSONValue, user: JSONValue }> {\n const plugins = this._plugins;\n\n if (plugin in plugins) {\n const { composite, user } = plugins[plugin].data;\n const result = {\n composite: key in composite ? copy(composite[key]) : void 0,\n user: key in user ? copy(user[key]) : void 0\n };\n\n return Promise.resolve(result);\n }\n\n return this.load(plugin).then(() => this.get(plugin, key));\n }\n\n /**\n * Load a plugin's settings into the setting registry.\n *\n * @param plugin - The name of the plugin whose settings are being loaded.\n *\n * @returns A promise that resolves with a plugin settings object or rejects\n * if the plugin is not found.\n */\n load(plugin: string): Promise<ISettingRegistry.ISettings> {\n const plugins = this._plugins;\n const registry = this;\n\n // If the plugin exists, resolve.\n if (plugin in plugins) {\n const settings = new Settings({ plugin: plugins[plugin], registry });\n\n return Promise.resolve(settings);\n }\n\n // If the plugin needs to be loaded from the data connector, fetch.\n return this.reload(plugin);\n }\n\n /**\n * Reload a plugin's settings into the registry even if they already exist.\n *\n * @param plugin - The name of the plugin whose settings are being reloaded.\n *\n * @returns A promise that resolves with a plugin settings object or rejects\n * with a list of `ISchemaValidator.IError` objects if it fails.\n */\n reload(plugin: string): Promise<ISettingRegistry.ISettings> {\n const connector = this._connector;\n const plugins = this._plugins;\n\n // If the plugin needs to be loaded from the connector, fetch.\n return connector.fetch(plugin).then(data => {\n // Validate the response from the connector; populate `composite` field.\n try {\n this._validate(data);\n } catch (errors) {\n const output = [`Validating ${plugin} failed:`];\n (errors as ISchemaValidator.IError[]).forEach((error, index) => {\n const { dataPath, schemaPath, keyword, message } = error;\n\n output.push(`${index} - schema @ ${schemaPath}, data @ ${dataPath}`);\n output.push(`\\t${keyword} ${message}`);\n });\n console.error(output.join('\\n'));\n\n throw new Error(`Failed validating ${plugin}`);\n }\n\n // Emit that a plugin has changed.\n this._pluginChanged.emit(plugin);\n\n return new Settings({\n plugin: copy(plugins[plugin]) as ISettingRegistry.IPlugin,\n registry: this\n });\n });\n }\n\n /**\n * Remove a single setting in the registry.\n *\n * @param plugin - The name of the plugin whose setting is being removed.\n *\n * @param key - The name of the setting being removed.\n *\n * @returns A promise that resolves when the setting is removed.\n */\n remove(plugin: string, key: string): Promise<void> {\n const plugins = this._plugins;\n\n if (!(plugin in plugins)) {\n return Promise.resolve(void 0);\n }\n\n delete plugins[plugin].data.user[key];\n\n return this._save(plugin);\n }\n\n /**\n * Set a single setting in the registry.\n *\n * @param plugin - The name of the plugin whose setting is being set.\n *\n * @param key - The name of the setting being set.\n *\n * @param value - The value of the setting being set.\n *\n * @returns A promise that resolves when the setting has been saved.\n *\n */\n set(plugin: string, key: string, value: JSONValue): Promise<void> {\n const plugins = this._plugins;\n\n if (!(plugin in plugins)) {\n return this.load(plugin).then(() => this.set(plugin, key, value));\n }\n\n plugins[plugin].data.user[key] = value;\n\n return this._save(plugin);\n }\n\n /**\n * Upload a plugin's settings.\n *\n * @param raw - The raw plugin settings being uploaded.\n *\n * @returns A promise that resolves when the settings have been saved.\n *\n * #### Notes\n * Only the `user` data will be saved.\n */\n upload(raw: ISettingRegistry.IPlugin): Promise<void> {\n const plugins = this._plugins;\n const plugin = raw.id;\n let errors: ISchemaValidator.IError[] | null = null;\n\n // Validate the user data and create the composite data.\n raw.data.user = raw.data.user || { };\n delete raw.data.composite;\n errors = this._validator.validateData(raw);\n if (errors) {\n return Promise.reject(errors);\n }\n\n // Set the local copy.\n plugins[plugin] = raw;\n\n return this._save(plugin);\n }\n\n /**\n * Save a plugin in the registry.\n */\n private _save(plugin: string): Promise<void> {\n const plugins = this._plugins;\n\n if (!(plugin in plugins)) {\n return Promise.reject(`${plugin} does not exist in setting registry.`);\n }\n\n this._validate(plugins[plugin]);\n\n return this._connector.save(plugin, plugins[plugin].data.user)\n .then(() => { this._pluginChanged.emit(plugin); });\n }\n\n /**\n * Validate a plugin's data and schema, compose the `composite` data.\n */\n private _validate(plugin: ISettingRegistry.IPlugin): void {\n let errors: ISchemaValidator.IError[] | null = null;\n\n // Add the schema to the registry.\n errors = this._validator.addSchema(plugin.id, plugin.schema);\n if (errors) {\n throw errors;\n }\n\n // Validate the user data and create the composite data.\n plugin.data.user = plugin.data.user || { };\n delete plugin.data.composite;\n errors = this._validator.validateData(plugin);\n if (errors) {\n throw errors;\n }\n\n // Set the local copy.\n this._plugins[plugin.id] = plugin;\n }\n\n private _connector: IDataConnector<ISettingRegistry.IPlugin, JSONObject>;\n private _pluginChanged = new Signal<this, string>(this);\n private _plugins: { [name: string]: ISettingRegistry.IPlugin } = Object.create(null);\n private _validator: ISchemaValidator;\n}\n\n\n/**\n * A manager for a specific plugin's settings.\n */\nexport\nclass Settings implements ISettingRegistry.ISettings {\n /**\n * Instantiate a new plugin settings manager.\n */\n constructor(options: Settings.IOptions) {\n const { plugin } = options;\n\n this.plugin = plugin.id;\n this.registry = options.registry;\n\n this._composite = plugin.data.composite || { };\n this._schema = plugin.schema || { type: 'object' };\n this._user = plugin.data.user || { };\n\n this.registry.pluginChanged.connect(this._onPluginChanged, this);\n }\n\n /**\n * A signal that emits when the plugin's settings have changed.\n */\n get changed(): ISignal<this, void> {\n return this._changed;\n }\n\n /**\n * Get the composite of user settings and extension defaults.\n */\n get composite(): JSONObject {\n return this._composite;\n }\n\n /**\n * Test whether the plugin settings manager disposed.\n */\n get isDisposed(): boolean {\n return this._isDisposed;\n }\n\n /**\n * Get the plugin settings schema.\n */\n get schema(): ISettingRegistry.ISchema {\n return this._schema;\n }\n\n /**\n * Get the user settings.\n */\n get user(): JSONObject {\n return this._user;\n }\n\n /*\n * The plugin name.\n */\n readonly plugin: string;\n\n /**\n * The system registry instance used by the settings manager.\n */\n readonly registry: SettingRegistry;\n\n /**\n * Return the defaults in a commented JSON format.\n */\n annotatedDefaults(): string {\n return Private.annotatedDefaults(this._schema, this.plugin);\n }\n\n /**\n * Calculate the default value of a setting by iterating through the schema.\n *\n * @param key - The name of the setting whose default value is calculated.\n *\n * @returns A calculated default JSON value for a specific setting.\n */\n default(key: string): JSONValue | undefined {\n return Private.reifyDefault(this.schema, key);\n }\n\n /**\n * Dispose of the plugin settings resources.\n */\n dispose(): void {\n if (this._isDisposed) {\n return;\n }\n\n this._isDisposed = true;\n Signal.clearData(this);\n }\n\n /**\n * Get an individual setting.\n *\n * @param key - The name of the setting being retrieved.\n *\n * @returns The setting value.\n *\n * #### Notes\n * This method returns synchronously because it uses a cached copy of the\n * plugin settings that is synchronized with the registry.\n */\n get(key: string): { composite: JSONValue, user: JSONValue } {\n const { composite, user } = this;\n\n return {\n composite: key in composite ? copy(composite[key]) : void 0,\n user: key in user ? copy(user[key]) : void 0\n };\n }\n\n /**\n * Remove a single setting.\n *\n * @param key - The name of the setting being removed.\n *\n * @returns A promise that resolves when the setting is removed.\n *\n * #### Notes\n * This function is asynchronous because it writes to the setting registry.\n */\n remove(key: string): Promise<void> {\n return this.registry.remove(this.plugin, key);\n }\n\n /**\n * Save all of the plugin's user settings at once.\n */\n save(user: JSONObject): Promise<void> {\n return this.registry.upload({\n id: this.plugin,\n data: { composite: this._composite, user },\n schema: this._schema\n });\n }\n\n /**\n * Set a single setting.\n *\n * @param key - The name of the setting being set.\n *\n * @param value - The value of the setting.\n *\n * @returns A promise that resolves when the setting has been saved.\n *\n * #### Notes\n * This function is asynchronous because it writes to the setting registry.\n */\n set(key: string, value: JSONValue): Promise<void> {\n return this.registry.set(this.plugin, key, value);\n }\n\n /**\n * Handle plugin changes in the setting registry.\n */\n private _onPluginChanged(sender: any, plugin: string): void {\n if (plugin === this.plugin) {\n const found = find(this.registry.plugins, p => p.id === plugin);\n\n if (!found) {\n return;\n }\n\n const { composite, user } = found.data;\n const schema = found.schema;\n\n this._composite = composite || { };\n this._schema = schema || { type: 'object' };\n this._user = user || { };\n this._changed.emit(void 0);\n }\n }\n\n private _changed = new Signal<this, void>(this);\n private _composite: JSONObject = Object.create(null);\n private _isDisposed = false;\n private _schema: ISettingRegistry.ISchema = Object.create(null);\n private _user: JSONObject = Object.create(null);\n}\n\n\n/**\n * A namespace for `SettingRegistry` statics.\n */\nexport\nnamespace SettingRegistry {\n /**\n * The instantiation options for a setting registry\n */\n export\n interface IOptions {\n /**\n * The data connector used by the setting registry.\n */\n connector: IDataConnector<ISettingRegistry.IPlugin, JSONObject>;\n\n /**\n * The validator used to enforce the settings JSON schema.\n */\n validator?: ISchemaValidator;\n }\n}\n\n\n/**\n * A namespace for `Settings` statics.\n */\nexport\nnamespace Settings {\n /**\n * The instantiation options for a `Settings` object.\n */\n export\n interface IOptions {\n /**\n * The setting values for a plugin.\n */\n plugin: ISettingRegistry.IPlugin;\n\n /**\n * The system registry instance used by the settings manager.\n */\n registry: SettingRegistry;\n }\n}\n\n\n/**\n * A namespace for private module data.\n */\nexport\nnamespace Private {\n /* tslint:disable */\n /**\n * The schema for settings.\n */\n export\n const SCHEMA: ISettingRegistry.ISchema = {\n \"$schema\": \"http://json-schema.org/draft-06/schema\",\n \"title\": \"Jupyter Settings/Preferences Schema\",\n \"description\": \"Jupyter settings/preferences schema v0.1.0\",\n \"type\": \"object\",\n \"additionalProperties\": true,\n \"properties\": {\n [ICON_CLASS_KEY]: { \"type\": \"string\", \"default\": \"jp-FileIcon\" },\n [ICON_LABEL_KEY]: { \"type\": \"string\", \"default\": \"Plugin\" }\n }\n };\n /* tslint:enable */\n\n /**\n * Replacement text for schema properties missing a `description` field.\n */\n const nondescript = '[missing schema description]';\n\n /**\n * Replacement text for schema properties missing a `default` field.\n */\n const undefaulted = '[missing schema default]';\n\n /**\n * Replacement text for schema properties missing a `title` field.\n */\n const untitled = '[missing schema title]';\n\n /**\n * Returns an annotated (JSON with comments) version of a schema's defaults.\n */\n export\n function annotatedDefaults(schema: ISettingRegistry.ISchema, plugin: string): string {\n const { description, properties, title } = schema;\n const keys = Object.keys(properties).sort((a, b) => a.localeCompare(b));\n\n return [\n '{',\n prefix(`${title || untitled}`),\n prefix(plugin),\n prefix(description || nondescript),\n prefix(line((description || nondescript).length)),\n '',\n keys.map(key => docstring(schema, key)).join('\\n\\n'),\n '}'\n ].join('\\n');\n }\n\n /**\n * Returns a documentation string for a specific schema property.\n */\n function docstring(schema: ISettingRegistry.ISchema, key: string): string {\n const { description, title } = schema.properties[key];\n const reified = reifyDefault(schema, key);\n const defaults = reified === undefined ? prefix(`\"${key}\": ${undefaulted}`)\n : prefix(`\"${key}\": ${JSON.stringify(reified, null, 2)}`, ' ');\n\n return [\n prefix(`${title || untitled}`),\n prefix(description || nondescript),\n defaults\n ].join('\\n');\n }\n\n /**\n * Returns a line of a specified length.\n */\n function line(length: number, ch = '*'): string {\n return (new Array(length + 1)).join(ch);\n }\n\n /**\n * Returns a documentation string with a comment prefix added on every line.\n */\n function prefix(source: string, pre = ' \\/\\/ '): string {\n return pre + source.split('\\n').join(`\\n${pre}`);\n }\n\n /**\n * Create a fully extrapolated default value for a root key in a schema.\n */\n export\n function reifyDefault(schema: ISettingRegistry.ISchema, root?: string): JSONValue | undefined {\n // If the property is at the root level, traverse its schema.\n schema = (root ? schema.properties[root] : schema) || { };\n\n // If the property has no default or is a primitive, return.\n if (!('default' in schema) || schema.type !== 'object') {\n return schema.default;\n }\n\n // Make a copy of the default value to populate.\n const result = JSONExt.deepCopy(schema.default);\n\n // Iterate through and populate each child property.\n for (let property in schema.properties || { }) {\n result[property] = reifyDefault(schema.properties[property]);\n }\n\n return result;\n }\n}\n"]} |
| {"version":3,"file":"statedb.js","sourceRoot":"","sources":["../../../../coreutils/src/statedb.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D,iDAE6B;AAO7B,oBAAoB;AACpB;;GAEG;AAEG,QAAA,QAAQ,GAAG,IAAI,iBAAK,CAAW,gCAAgC,CAAC,CAAC;AA6DvE;;GAEG;AACH;IAEE;;;;OAIG;IACH,iBAAY,OAAyB;QAIrC;;WAEG;QACM,cAAS,GAAG,IAAI,CAAC;QANxB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IACrC,CAAC;IAiBD;;OAEG;IACH,uBAAK,GAAL;QACE,IAAM,MAAM,GA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,IAAI,CAAC,SAAS,SAAI,EAAI,CAAC;YACtC,IAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YACzC,IAAM,QAAM,GAAG,UAAU,CAAC,MAAM,CAAC;YACjC,IAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC;YAC3B,EAAE,CAAC,CAAC,QAAM,GAAG,GAAG,CAAC,CAAC,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,kBAAgB,QAAM,2BAAsB,GAAG,MAAG,CAAC,CAAC;YACtE,CAAC;YACD,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;YAC7C,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QACjC,CAAC;QAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YACf,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IACH,cAAC;AAAD,CAAC,AAzJD,IAyJC;AAxJK,0BAAO","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport {\n ReadonlyJSONObject, Token\n} from '@phosphor/coreutils';\n\nimport {\n IDataConnector\n} from '.';\n\n\n/* tslint:disable */\n/**\n * The default state database token.\n */\nexport\nconst IStateDB = new Token<IStateDB>('@jupyterlab/coreutils:IStateDB');\n/* tslint:enable */\n\n\n/**\n * An object which holds an id/value pair.\n */\nexport\ninterface IStateItem {\n /**\n * The identifier key for a state item.\n */\n id: string;\n\n /**\n * The data value for a state item.\n */\n value: ReadonlyJSONObject;\n}\n\n\n/**\n * The description of a state database.\n */\nexport\ninterface IStateDB extends IDataConnector<ReadonlyJSONObject> {\n /**\n * The maximum allowed length of the data after it has been serialized.\n */\n readonly maxLength: number;\n\n /**\n * The namespace prefix for all state database entries.\n *\n * #### Notes\n * This value should be set at instantiation and will only be used\n * internally by a state database. That means, for example, that an\n * app could have multiple, mutually exclusive state databases.\n */\n readonly namespace: string;\n\n /**\n * Retrieve all the saved bundles for a namespace.\n *\n * @param namespace - The namespace to retrieve.\n *\n * @returns A promise that bears a collection data payloads for a namespace.\n *\n * #### Notes\n * Namespaces are entirely conventional entities. The `id` values of stored\n * items in the state database are formatted: `'namespace:identifier'`, which\n * is the same convention that command identifiers in JupyterLab use as well.\n *\n * If there are any errors in retrieving the data, they will be logged to the\n * console in order to optimistically return any extant data without failing.\n * This promise will always succeed.\n */\n fetchNamespace(namespace: string): Promise<IStateItem[]>;\n}\n\n\n/**\n * The default concrete implementation of a state database.\n */\nexport\nclass StateDB implements IStateDB {\n /**\n * Create a new state database.\n *\n * @param options - The instantiation options for a state database.\n */\n constructor(options: StateDB.IOptions) {\n this.namespace = options.namespace;\n }\n\n /**\n * The maximum allowed length of the data after it has been serialized.\n */\n readonly maxLength = 2000;\n\n /**\n * The namespace prefix for all state database entries.\n *\n * #### Notes\n * This value should be set at instantiation and will only be used internally\n * by a state database. That means, for example, that an app could have\n * multiple, mutually exclusive state databases.\n */\n readonly namespace: string;\n\n /**\n * Clear the entire database.\n */\n clear(): Promise<void> {\n const prefix = `${this.namespace}:`;\n let i = window.localStorage.length;\n while (i) {\n let key = window.localStorage.key(--i);\n if (key && key.indexOf(prefix) === 0) {\n window.localStorage.removeItem(key);\n }\n }\n return Promise.resolve(void 0);\n }\n\n /**\n * Retrieve a saved bundle from the database.\n *\n * @param id - The identifier used to retrieve a data bundle.\n *\n * @returns A promise that bears a data payload if available.\n *\n * #### Notes\n * The `id` values of stored items in the state database are formatted:\n * `'namespace:identifier'`, which is the same convention that command\n * identifiers in JupyterLab use as well. While this is not a technical\n * requirement for `fetch()`, `remove()`, and `save()`, it *is* necessary for\n * using the `fetchNamespace()` method.\n *\n * The promise returned by this method may be rejected if an error occurs in\n * retrieving the data. Non-existence of an `id` will succeed with `null`.\n */\n fetch(id: string): Promise<ReadonlyJSONObject | undefined> {\n const key = `${this.namespace}:${id}`;\n const value = window.localStorage.getItem(key);\n if (!value) {\n return Promise.resolve(undefined);\n }\n try {\n return Promise.resolve(JSON.parse(value));\n } catch (error) {\n return Promise.reject(error);\n }\n }\n\n /**\n * Retrieve all the saved bundles for a namespace.\n *\n * @param namespace - The namespace to retrieve.\n *\n * @returns A promise that bears a collection data payloads for a namespace.\n *\n * #### Notes\n * Namespaces are entirely conventional entities. The `id` values of stored\n * items in the state database are formatted: `'namespace:identifier'`, which\n * is the same convention that command identifiers in JupyterLab use as well.\n *\n * If there are any errors in retrieving the data, they will be logged to the\n * console in order to optimistically return any extant data without failing.\n * This promise will always succeed.\n */\n fetchNamespace(namespace: string): Promise<IStateItem[]> {\n const prefix = `${this.namespace}:${namespace}:`;\n const regex = new RegExp(`^${this.namespace}\\:`);\n let items: IStateItem[] = [];\n let i = window.localStorage.length;\n while (i) {\n let key = window.localStorage.key(--i);\n if (key && key.indexOf(prefix) === 0) {\n let value = window.localStorage.getItem(key);\n try {\n items.push({\n id: key.replace(regex, ''),\n value: value ? JSON.parse(value) : undefined\n });\n } catch (error) {\n console.warn(error);\n window.localStorage.removeItem(key);\n }\n }\n }\n return Promise.resolve(items);\n }\n\n /**\n * Remove a value from the database.\n *\n * @param id - The identifier for the data being removed.\n *\n * @returns A promise that is rejected if remove fails and succeeds otherwise.\n */\n remove(id: string): Promise<void> {\n window.localStorage.removeItem(`${this.namespace}:${id}`);\n return Promise.resolve(void 0);\n }\n\n /**\n * Save a value in the database.\n *\n * @param id - The identifier for the data being saved.\n *\n * @param value - The data being saved.\n *\n * @returns A promise that is rejected if saving fails and succeeds otherwise.\n *\n * #### Notes\n * The `id` values of stored items in the state database are formatted:\n * `'namespace:identifier'`, which is the same convention that command\n * identifiers in JupyterLab use as well. While this is not a technical\n * requirement for `fetch()`, `remove()`, and `save()`, it *is* necessary for\n * using the `fetchNamespace()` method.\n */\n save(id: string, value: ReadonlyJSONObject): Promise<void> {\n try {\n const key = `${this.namespace}:${id}`;\n const serialized = JSON.stringify(value);\n const length = serialized.length;\n const max = this.maxLength;\n if (length > max) {\n throw new Error(`Data length (${length}) exceeds maximum (${max})`);\n }\n window.localStorage.setItem(key, serialized);\n return Promise.resolve(void 0);\n } catch (error) {\n return Promise.reject(error);\n }\n }\n}\n\n/**\n * A namespace for StateDB statics.\n */\nexport\nnamespace StateDB {\n /**\n * The instantiation options for a state database.\n */\n export\n interface IOptions {\n /**\n * The namespace prefix for all state database entries.\n */\n namespace: string;\n }\n}\n"]} |
| {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../../coreutils/src/text.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D;;GAEG;AACH,IACU,IAAI,CAqEb;AAtED,WACU,IAAI;IAEZ,uEAAuE;IACvE,+DAA+D;IAC/D,qDAAqD;IACrD,0EAA0E;IAC1E,wDAAwD;IAExD,IAAM,cAAc,GAAY,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAElD;;;;;;;;OAQG;IACH,4BAC6B,KAAa,EAAE,IAAY;QACtD,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;YACnB,sCAAsC;YACtC,MAAM,CAAC,KAAK,CAAC;QACf,CAAC;QACD,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YACtD,IAAI,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAClC,2BAA2B;YAC3B,EAAE,CAAC,CAAC,QAAQ,IAAI,MAAM,IAAI,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC;gBAC7C,IAAI,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,GAAC,CAAC,CAAC,CAAC;gBACxC,EAAE,CAAC,CAAC,YAAY,IAAI,MAAM,IAAI,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC;oBACrD,OAAO,EAAE,CAAC;oBACV,CAAC,EAAE,CAAC;gBACN,CAAC;YACH,CAAC;QACH,CAAC;QACD,MAAM,CAAC,OAAO,CAAC;IACjB,CAAC;IAlBQ,uBAAkB,qBAkB1B,CAAA;IAED;;;;;;;;OAQG;IACH,4BAC6B,OAAe,EAAE,IAAY;QACxD,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;YACnB,sCAAsC;YACtC,MAAM,CAAC,OAAO,CAAC;QACjB,CAAC;QACD,IAAI,KAAK,GAAG,OAAO,CAAC;QACpB,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YACtD,IAAI,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAClC,2BAA2B;YAC3B,EAAE,CAAC,CAAC,QAAQ,IAAI,MAAM,IAAI,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC;gBAC7C,IAAI,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,GAAC,CAAC,CAAC,CAAC;gBACxC,EAAE,CAAC,CAAC,YAAY,IAAI,MAAM,IAAI,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC;oBACrD,KAAK,EAAE,CAAC;oBACR,CAAC,EAAE,CAAC;gBACN,CAAC;YACH,CAAC;QACH,CAAC;QACD,MAAM,CAAC,KAAK,CAAC;IACf,CAAC;IAlBQ,uBAAkB,qBAkB1B,CAAA;AACH,CAAC,EArES,IAAI,GAAJ,YAAI,KAAJ,YAAI,QAqEb","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\n/**\n * The namespace for text-related functions.\n */\nexport\nnamespace Text {\n\n // javascript stores text as utf16 and string indices use \"code units\",\n // which stores high-codepoint characters as \"surrogate pairs\",\n // which occupy two indices in the javascript string.\n // We need to translate cursor_pos in the Jupyter protocol (in characters)\n // to js offset (with surrogate pairs taking two spots).\n\n const HAS_SURROGATES: boolean = ('𝐚'.length > 1);\n\n /**\n * Convert a javascript string index into a unicode character offset\n *\n * @param jsIdx - The javascript string index (counting surrogate pairs)\n *\n * @param text - The text in which the offset is calculated\n *\n * @returns The unicode character offset\n */\n export\n function jsIndexToCharIndex (jsIdx: number, text: string): number {\n if (HAS_SURROGATES) {\n // not using surrogates, nothing to do\n return jsIdx;\n }\n var charIdx = jsIdx;\n for (var i = 0; i + 1 < text.length && i < jsIdx; i++) {\n var charCode = text.charCodeAt(i);\n // check for surrogate pair\n if (charCode >= 0xD800 && charCode <= 0xDBFF) {\n var nextCharCode = text.charCodeAt(i+1);\n if (nextCharCode >= 0xDC00 && nextCharCode <= 0xDFFF) {\n charIdx--;\n i++;\n }\n }\n }\n return charIdx;\n }\n\n /**\n * Convert a unicode character offset to a javascript string index.\n *\n * @param charIdx - The index in unicode characters\n *\n * @param text - The text in which the offset is calculated\n *\n * @returns The js-native index\n */\n export\n function charIndexToJsIndex (charIdx: number, text: string): number {\n if (HAS_SURROGATES) {\n // not using surrogates, nothing to do\n return charIdx;\n }\n var jsIdx = charIdx;\n for (var i = 0; i + 1 < text.length && i < jsIdx; i++) {\n var charCode = text.charCodeAt(i);\n // check for surrogate pair\n if (charCode >= 0xD800 && charCode <= 0xDBFF) {\n var nextCharCode = text.charCodeAt(i+1);\n if (nextCharCode >= 0xDC00 && nextCharCode <= 0xDFFF) {\n jsIdx++;\n i++;\n }\n }\n }\n return jsIdx;\n }\n}\n"]} |
| {"version":3,"file":"time.js","sourceRoot":"","sources":["../../../../coreutils/src/time.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D,+BACe;AAGf;;GAEG;AACH,IACU,IAAI,CA4Bb;AA7BD,WACU,IAAI;IACZ;;;;;;OAMG;IACH,qBACqB,KAAoB;QACvC,IAAI,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;QACnC,IAAI,GAAG,IAAI,KAAK,mBAAmB,GAAG,aAAa,GAAG,IAAI,CAAC;QAC3D,MAAM,CAAC,IAAI,CAAC;IACd,CAAC;IAJQ,gBAAW,cAInB,CAAA;IAED;;;;;;;;OAQG;IACH,gBACgB,KAAoB,EAAE,MAAyB;QAAzB,uBAAA,EAAA,2BAAyB;QAC7D,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAFQ,WAAM,SAEd,CAAA;AACH,CAAC,EA5BS,IAAI,GAAJ,YAAI,KAAJ,YAAI,QA4Bb","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport * as moment\n from 'moment';\n\n\n/**\n * The namespace for date functions.\n */\nexport\nnamespace Time {\n /**\n * Convert a timestring to a human readable string (e.g. 'two minutes ago').\n *\n * @param value - The date timestring or date object.\n *\n * @returns A formatted date.\n */\n export\n function formatHuman(value: string | Date): string {\n let time = moment(value).fromNow();\n time = time === 'a few seconds ago' ? 'seconds ago' : time;\n return time;\n }\n\n /**\n * Convert a timestring to a date format.\n *\n * @param value - The date timestring or date object.\n *\n * @param format - The format string.\n *\n * @returns A formatted date.\n */\n export\n function format(value: string | Date, format='YYYY-MM-DD HH:mm'): string {\n return moment(value).format(format);\n }\n}\n"]} |
| import { JSONValue } from '@phosphor/coreutils'; | ||
| import { IObservableList, ObservableList } from './observablelist'; | ||
| /** | ||
| * An object which knows how to serialize and | ||
| * deserialize the type T. | ||
| */ | ||
| export interface ISerializer<T> { | ||
| /** | ||
| * Convert the object to JSON. | ||
| */ | ||
| toJSON(value: T): JSONValue; | ||
| /** | ||
| * Deserialize the object from JSON. | ||
| */ | ||
| fromJSON(value: JSONValue): T; | ||
| } | ||
| /** | ||
| * An observable list that supports undo/redo. | ||
| */ | ||
| export interface IObservableUndoableList<T> extends IObservableList<T> { | ||
| /** | ||
| * Whether the object can redo changes. | ||
| */ | ||
| readonly canRedo: boolean; | ||
| /** | ||
| * Whether the object can undo changes. | ||
| */ | ||
| readonly canUndo: boolean; | ||
| /** | ||
| * Begin a compound operation. | ||
| * | ||
| * @param isUndoAble - Whether the operation is undoable. | ||
| * The default is `false`. | ||
| */ | ||
| beginCompoundOperation(isUndoAble?: boolean): void; | ||
| /** | ||
| * End a compound operation. | ||
| */ | ||
| endCompoundOperation(): void; | ||
| /** | ||
| * Undo an operation. | ||
| */ | ||
| undo(): void; | ||
| /** | ||
| * Redo an operation. | ||
| */ | ||
| redo(): void; | ||
| /** | ||
| * Clear the change stack. | ||
| */ | ||
| clearUndo(): void; | ||
| } | ||
| /** | ||
| * A concrete implementation of an observable undoable list. | ||
| */ | ||
| export declare class ObservableUndoableList<T> extends ObservableList<T> implements IObservableUndoableList<T> { | ||
| /** | ||
| * Construct a new undoable observable list. | ||
| */ | ||
| constructor(serializer: ISerializer<T>); | ||
| /** | ||
| * Whether the object can redo changes. | ||
| */ | ||
| readonly canRedo: boolean; | ||
| /** | ||
| * Whether the object can undo changes. | ||
| */ | ||
| readonly canUndo: boolean; | ||
| /** | ||
| * Begin a compound operation. | ||
| * | ||
| * @param isUndoAble - Whether the operation is undoable. | ||
| * The default is `true`. | ||
| */ | ||
| beginCompoundOperation(isUndoAble?: boolean): void; | ||
| /** | ||
| * End a compound operation. | ||
| */ | ||
| endCompoundOperation(): void; | ||
| /** | ||
| * Undo an operation. | ||
| */ | ||
| undo(): void; | ||
| /** | ||
| * Redo an operation. | ||
| */ | ||
| redo(): void; | ||
| /** | ||
| * Clear the change stack. | ||
| */ | ||
| clearUndo(): void; | ||
| /** | ||
| * Handle a change in the list. | ||
| */ | ||
| private _onListChanged(list, change); | ||
| /** | ||
| * Undo a change event. | ||
| */ | ||
| private _undoChange(change); | ||
| /** | ||
| * Redo a change event. | ||
| */ | ||
| private _redoChange(change); | ||
| /** | ||
| * Copy a change as JSON. | ||
| */ | ||
| private _copyChange(change); | ||
| private _inCompound; | ||
| private _isUndoable; | ||
| private _madeCompoundChange; | ||
| private _index; | ||
| private _stack; | ||
| private _serializer; | ||
| } | ||
| /** | ||
| * Namespace for ObservableUndoableList utilities. | ||
| */ | ||
| export declare namespace ObservableUndoableList { | ||
| /** | ||
| * A default, identity serializer. | ||
| */ | ||
| class IdentitySerializer<T extends JSONValue> implements ISerializer<T> { | ||
| /** | ||
| * Identity serialize. | ||
| */ | ||
| toJSON(value: T): JSONValue; | ||
| /** | ||
| * Identity deserialize. | ||
| */ | ||
| fromJSON(value: JSONValue): T; | ||
| } | ||
| } |
| "use strict"; | ||
| // Copyright (c) Jupyter Development Team. | ||
| // Distributed under the terms of the Modified BSD License. | ||
| var __extends = (this && this.__extends) || (function () { | ||
| var extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
| return function (d, b) { | ||
| extendStatics(d, b); | ||
| function __() { this.constructor = d; } | ||
| d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| }; | ||
| })(); | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var algorithm_1 = require("@phosphor/algorithm"); | ||
| var observablelist_1 = require("./observablelist"); | ||
| /** | ||
| * A concrete implementation of an observable undoable list. | ||
| */ | ||
| var ObservableUndoableList = (function (_super) { | ||
| __extends(ObservableUndoableList, _super); | ||
| /** | ||
| * Construct a new undoable observable list. | ||
| */ | ||
| function ObservableUndoableList(serializer) { | ||
| var _this = _super.call(this) || this; | ||
| _this._inCompound = false; | ||
| _this._isUndoable = true; | ||
| _this._madeCompoundChange = false; | ||
| _this._index = -1; | ||
| _this._stack = []; | ||
| _this._serializer = serializer; | ||
| _this.changed.connect(_this._onListChanged, _this); | ||
| return _this; | ||
| } | ||
| Object.defineProperty(ObservableUndoableList.prototype, "canRedo", { | ||
| /** | ||
| * Whether the object can redo changes. | ||
| */ | ||
| get: function () { | ||
| return this._index < this._stack.length - 1; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| Object.defineProperty(ObservableUndoableList.prototype, "canUndo", { | ||
| /** | ||
| * Whether the object can undo changes. | ||
| */ | ||
| get: function () { | ||
| return this._index >= 0; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| /** | ||
| * Begin a compound operation. | ||
| * | ||
| * @param isUndoAble - Whether the operation is undoable. | ||
| * The default is `true`. | ||
| */ | ||
| ObservableUndoableList.prototype.beginCompoundOperation = function (isUndoAble) { | ||
| this._inCompound = true; | ||
| this._isUndoable = (isUndoAble !== false); | ||
| this._madeCompoundChange = false; | ||
| }; | ||
| /** | ||
| * End a compound operation. | ||
| */ | ||
| ObservableUndoableList.prototype.endCompoundOperation = function () { | ||
| this._inCompound = false; | ||
| this._isUndoable = true; | ||
| if (this._madeCompoundChange) { | ||
| this._index++; | ||
| } | ||
| }; | ||
| /** | ||
| * Undo an operation. | ||
| */ | ||
| ObservableUndoableList.prototype.undo = function () { | ||
| if (!this.canUndo) { | ||
| return; | ||
| } | ||
| var changes = this._stack[this._index]; | ||
| this._isUndoable = false; | ||
| for (var _i = 0, _a = changes.reverse(); _i < _a.length; _i++) { | ||
| var change = _a[_i]; | ||
| this._undoChange(change); | ||
| } | ||
| this._isUndoable = true; | ||
| this._index--; | ||
| }; | ||
| /** | ||
| * Redo an operation. | ||
| */ | ||
| ObservableUndoableList.prototype.redo = function () { | ||
| if (!this.canRedo) { | ||
| return; | ||
| } | ||
| this._index++; | ||
| var changes = this._stack[this._index]; | ||
| this._isUndoable = false; | ||
| for (var _i = 0, changes_1 = changes; _i < changes_1.length; _i++) { | ||
| var change = changes_1[_i]; | ||
| this._redoChange(change); | ||
| } | ||
| this._isUndoable = true; | ||
| }; | ||
| /** | ||
| * Clear the change stack. | ||
| */ | ||
| ObservableUndoableList.prototype.clearUndo = function () { | ||
| this._index = -1; | ||
| this._stack = []; | ||
| }; | ||
| /** | ||
| * Handle a change in the list. | ||
| */ | ||
| ObservableUndoableList.prototype._onListChanged = function (list, change) { | ||
| if (this.isDisposed || !this._isUndoable) { | ||
| return; | ||
| } | ||
| // Clear everything after this position if necessary. | ||
| if (!this._inCompound || !this._madeCompoundChange) { | ||
| this._stack = this._stack.slice(0, this._index + 1); | ||
| } | ||
| // Copy the change. | ||
| var evt = this._copyChange(change); | ||
| // Put the change in the stack. | ||
| if (this._stack[this._index + 1]) { | ||
| this._stack[this._index + 1].push(evt); | ||
| } | ||
| else { | ||
| this._stack.push([evt]); | ||
| } | ||
| // If not in a compound operation, increase index. | ||
| if (!this._inCompound) { | ||
| this._index++; | ||
| } | ||
| else { | ||
| this._madeCompoundChange = true; | ||
| } | ||
| }; | ||
| /** | ||
| * Undo a change event. | ||
| */ | ||
| ObservableUndoableList.prototype._undoChange = function (change) { | ||
| var _this = this; | ||
| var index = 0; | ||
| var serializer = this._serializer; | ||
| switch (change.type) { | ||
| case 'add': | ||
| algorithm_1.each(change.newValues, function () { | ||
| _this.remove(change.newIndex); | ||
| }); | ||
| break; | ||
| case 'set': | ||
| index = change.oldIndex; | ||
| algorithm_1.each(change.oldValues, function (value) { | ||
| _this.set(index++, serializer.fromJSON(value)); | ||
| }); | ||
| break; | ||
| case 'remove': | ||
| index = change.oldIndex; | ||
| algorithm_1.each(change.oldValues, function (value) { | ||
| _this.insert(index++, serializer.fromJSON(value)); | ||
| }); | ||
| break; | ||
| case 'move': | ||
| this.move(change.newIndex, change.oldIndex); | ||
| break; | ||
| default: | ||
| return; | ||
| } | ||
| }; | ||
| /** | ||
| * Redo a change event. | ||
| */ | ||
| ObservableUndoableList.prototype._redoChange = function (change) { | ||
| var _this = this; | ||
| var index = 0; | ||
| var serializer = this._serializer; | ||
| switch (change.type) { | ||
| case 'add': | ||
| index = change.newIndex; | ||
| algorithm_1.each(change.newValues, function (value) { | ||
| _this.insert(index++, serializer.fromJSON(value)); | ||
| }); | ||
| break; | ||
| case 'set': | ||
| index = change.newIndex; | ||
| algorithm_1.each(change.newValues, function (value) { | ||
| _this.set(change.newIndex++, serializer.fromJSON(value)); | ||
| }); | ||
| break; | ||
| case 'remove': | ||
| algorithm_1.each(change.oldValues, function () { | ||
| _this.remove(change.oldIndex); | ||
| }); | ||
| break; | ||
| case 'move': | ||
| this.move(change.oldIndex, change.newIndex); | ||
| break; | ||
| default: | ||
| return; | ||
| } | ||
| }; | ||
| /** | ||
| * Copy a change as JSON. | ||
| */ | ||
| ObservableUndoableList.prototype._copyChange = function (change) { | ||
| var _this = this; | ||
| var oldValues = []; | ||
| algorithm_1.each(change.oldValues, function (value) { | ||
| oldValues.push(_this._serializer.toJSON(value)); | ||
| }); | ||
| var newValues = []; | ||
| algorithm_1.each(change.newValues, function (value) { | ||
| newValues.push(_this._serializer.toJSON(value)); | ||
| }); | ||
| return { | ||
| type: change.type, | ||
| oldIndex: change.oldIndex, | ||
| newIndex: change.newIndex, | ||
| oldValues: oldValues, | ||
| newValues: newValues | ||
| }; | ||
| }; | ||
| return ObservableUndoableList; | ||
| }(observablelist_1.ObservableList)); | ||
| exports.ObservableUndoableList = ObservableUndoableList; | ||
| /** | ||
| * Namespace for ObservableUndoableList utilities. | ||
| */ | ||
| (function (ObservableUndoableList) { | ||
| /** | ||
| * A default, identity serializer. | ||
| */ | ||
| var IdentitySerializer = (function () { | ||
| function IdentitySerializer() { | ||
| } | ||
| /** | ||
| * Identity serialize. | ||
| */ | ||
| IdentitySerializer.prototype.toJSON = function (value) { | ||
| return value; | ||
| }; | ||
| /** | ||
| * Identity deserialize. | ||
| */ | ||
| IdentitySerializer.prototype.fromJSON = function (value) { | ||
| return value; | ||
| }; | ||
| return IdentitySerializer; | ||
| }()); | ||
| ObservableUndoableList.IdentitySerializer = IdentitySerializer; | ||
| })(ObservableUndoableList = exports.ObservableUndoableList || (exports.ObservableUndoableList = {})); | ||
| exports.ObservableUndoableList = ObservableUndoableList; | ||
| //# sourceMappingURL=undoablelist.js.map |
| {"version":3,"file":"undoablelist.js","sourceRoot":"","sources":["../../../../coreutils/src/undoablelist.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;;;;;;;;;;;AAM3D,iDAE6B;AAE7B,mDAE0B;AAkE1B;;GAEG;AACH;IACwC,0CAAiB;IACvD;;OAEG;IACH,gCAAY,UAA0B;QAAtC,YACE,iBAAO,SAGR;QA+LO,iBAAW,GAAG,KAAK,CAAC;QACpB,iBAAW,GAAG,IAAI,CAAC;QACnB,yBAAmB,GAAG,KAAK,CAAC;QAC5B,YAAM,GAAG,CAAC,CAAC,CAAC;QACZ,YAAM,GAAgD,EAAE,CAAC;QArM/D,KAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,KAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAI,CAAC,cAAc,EAAE,KAAI,CAAC,CAAC;;IAClD,CAAC;IAKD,sBAAI,2CAAO;QAHX;;WAEG;aACH;YACE,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAC9C,CAAC;;;OAAA;IAKD,sBAAI,2CAAO;QAHX;;WAEG;aACH;YACE,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;QAC1B,CAAC;;;OAAA;IAED;;;;;OAKG;IACH,uDAAsB,GAAtB,UAAuB,UAAoB;QACzC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,CAAC,UAAU,KAAK,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,qDAAoB,GAApB;QACE,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,EAAE,C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ACL,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,SAAS,WAAA;YACT,SAAS,WAAA;SACV,CAAC;IACJ,CAAC;IAQH,6BAAC;AAAD,CAAC,AA9MD,CACwC,+BAAc,GA6MrD;AA7MK,wDAAsB;AA+M5B;;GAEG;AACH,WACU,sBAAsB;IAC9B;;OAEG;IACH;QAAA;QAeA,CAAC;QAbC;;WAEG;QACH,mCAAM,GAAN,UAAO,KAAQ;YACb,MAAM,CAAC,KAAK,CAAC;QACf,CAAC;QAED;;WAEG;QACH,qCAAQ,GAAR,UAAS,KAAgB;YACvB,MAAM,CAAC,KAAU,CAAC;QACpB,CAAC;QACH,yBAAC;IAAD,CAAC,AAfD,IAeC;IAdK,yCAAkB,qBAcvB,CAAA;AACH,CAAC,EApBS,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAoB/B;AAvOK,wDAAsB","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport {\n JSONValue\n} from '@phosphor/coreutils';\n\nimport {\n each\n} from '@phosphor/algorithm';\n\nimport {\n IObservableList, ObservableList\n} from './observablelist';\n\n\n/**\n * An object which knows how to serialize and\n * deserialize the type T.\n */\nexport\ninterface ISerializer<T> {\n /**\n * Convert the object to JSON.\n */\n toJSON(value: T): JSONValue;\n\n /**\n * Deserialize the object from JSON.\n */\n fromJSON(value: JSONValue): T;\n}\n\n\n/**\n * An observable list that supports undo/redo.\n */\nexport\ninterface IObservableUndoableList<T> extends IObservableList<T> {\n /**\n * Whether the object can redo changes.\n */\n readonly canRedo: boolean;\n\n /**\n * Whether the object can undo changes.\n */\n readonly canUndo: boolean;\n\n /**\n * Begin a compound operation.\n *\n * @param isUndoAble - Whether the operation is undoable.\n * The default is `false`.\n */\n beginCompoundOperation(isUndoAble?: boolean): void;\n\n /**\n * End a compound operation.\n */\n endCompoundOperation(): void;\n\n /**\n * Undo an operation.\n */\n undo(): void;\n\n /**\n * Redo an operation.\n */\n redo(): void;\n\n /**\n * Clear the change stack.\n */\n clearUndo(): void;\n}\n\n\n/**\n * A concrete implementation of an observable undoable list.\n */\nexport\nclass ObservableUndoableList<T> extends ObservableList<T> implements IObservableUndoableList<T> {\n /**\n * Construct a new undoable observable list.\n */\n constructor(serializer: ISerializer<T>) {\n super();\n this._serializer = serializer;\n this.changed.connect(this._onListChanged, this);\n }\n\n /**\n * Whether the object can redo changes.\n */\n get canRedo(): boolean {\n return this._index < this._stack.length - 1;\n }\n\n /**\n * Whether the object can undo changes.\n */\n get canUndo(): boolean {\n return this._index >= 0;\n }\n\n /**\n * Begin a compound operation.\n *\n * @param isUndoAble - Whether the operation is undoable.\n * The default is `true`.\n */\n beginCompoundOperation(isUndoAble?: boolean): void {\n this._inCompound = true;\n this._isUndoable = (isUndoAble !== false);\n this._madeCompoundChange = false;\n }\n\n /**\n * End a compound operation.\n */\n endCompoundOperation(): void {\n this._inCompound = false;\n this._isUndoable = true;\n if (this._madeCompoundChange) {\n this._index++;\n }\n }\n\n /**\n * Undo an operation.\n */\n undo(): void {\n if (!this.canUndo) {\n return;\n }\n let changes = this._stack[this._index];\n this._isUndoable = false;\n for (let change of changes.reverse()) {\n this._undoChange(change);\n }\n this._isUndoable = true;\n this._index--;\n }\n\n /**\n * Redo an operation.\n */\n redo(): void {\n if (!this.canRedo) {\n return;\n }\n this._index++;\n let changes = this._stack[this._index];\n this._isUndoable = false;\n for (let change of changes) {\n this._redoChange(change);\n }\n this._isUndoable = true;\n }\n\n /**\n * Clear the change stack.\n */\n clearUndo(): void {\n this._index = -1;\n this._stack = [];\n }\n\n /**\n * Handle a change in the list.\n */\n private _onListChanged(list: IObservableList<T>, change: IObservableList.IChangedArgs<T>): void {\n if (this.isDisposed || !this._isUndoable) {\n return;\n }\n // Clear everything after this position if necessary.\n if (!this._inCompound || !this._madeCompoundChange) {\n this._stack = this._stack.slice(0, this._index + 1);\n }\n // Copy the change.\n let evt = this._copyChange(change);\n // Put the change in the stack.\n if (this._stack[this._index + 1]) {\n this._stack[this._index + 1].push(evt);\n } else {\n this._stack.push([evt]);\n }\n // If not in a compound operation, increase index.\n if (!this._inCompound) {\n this._index++;\n } else {\n this._madeCompoundChange = true;\n }\n }\n\n /**\n * Undo a change event.\n */\n private _undoChange(change: IObservableList.IChangedArgs<JSONValue>): void {\n let index = 0;\n let serializer = this._serializer;\n switch (change.type) {\n case 'add':\n each(change.newValues, () => {\n this.remove(change.newIndex);\n });\n break;\n case 'set':\n index = change.oldIndex;\n each(change.oldValues, value => {\n this.set(index++, serializer.fromJSON(value));\n });\n break;\n case 'remove':\n index = change.oldIndex;\n each(change.oldValues, value => {\n this.insert(index++, serializer.fromJSON(value));\n });\n break;\n case 'move':\n this.move(change.newIndex, change.oldIndex);\n break;\n default:\n return;\n }\n }\n\n /**\n * Redo a change event.\n */\n private _redoChange(change: IObservableList.IChangedArgs<JSONValue>): void {\n let index = 0;\n let serializer = this._serializer;\n switch (change.type) {\n case 'add':\n index = change.newIndex;\n each(change.newValues, value => {\n this.insert(index++, serializer.fromJSON(value));\n });\n break;\n case 'set':\n index = change.newIndex;\n each(change.newValues, value => {\n this.set(change.newIndex++, serializer.fromJSON(value));\n });\n break;\n case 'remove':\n each(change.oldValues, () => {\n this.remove(change.oldIndex);\n });\n break;\n case 'move':\n this.move(change.oldIndex, change.newIndex);\n break;\n default:\n return;\n }\n }\n\n /**\n * Copy a change as JSON.\n */\n private _copyChange(change: IObservableList.IChangedArgs<T>): IObservableList.IChangedArgs<JSONValue> {\n let oldValues: JSONValue[] = [];\n each(change.oldValues, value => {\n oldValues.push(this._serializer.toJSON(value));\n });\n let newValues: JSONValue[] = [];\n each(change.newValues, value => {\n newValues.push(this._serializer.toJSON(value));\n });\n return {\n type: change.type,\n oldIndex: change.oldIndex,\n newIndex: change.newIndex,\n oldValues,\n newValues\n };\n }\n\n private _inCompound = false;\n private _isUndoable = true;\n private _madeCompoundChange = false;\n private _index = -1;\n private _stack: IObservableList.IChangedArgs<JSONValue>[][] = [];\n private _serializer: ISerializer<T>;\n}\n\n/**\n * Namespace for ObservableUndoableList utilities.\n */\nexport\nnamespace ObservableUndoableList {\n /**\n * A default, identity serializer.\n */\n export\n class IdentitySerializer<T extends JSONValue> implements ISerializer<T> {\n /**\n * Identity serialize.\n */\n toJSON(value: T): JSONValue {\n return value;\n }\n\n /**\n * Identity deserialize.\n */\n fromJSON(value: JSONValue): T {\n return value as T;\n }\n }\n}\n"]} |
| {"version":3,"file":"url.js","sourceRoot":"","sources":["../../../../coreutils/src/url.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAM3D,oCACkB;AAElB;;GAEG;AACH,IACU,MAAM,CAgJf;AAjJD,WACU,MAAM;IACd;;;;;;OAMG;IACH,eACe,GAAW;QACxB,EAAE,CAAC,CAAC,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC;YACpC,IAAI,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;YACpC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC;YACb,MAAM,CAAC,CAAC,CAAC;QACX,CAAC;QACD,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IAPQ,YAAK,QAOb,CAAA;IAED;;;;;;OAMG;IACH;QACc,eAAkB;aAAlB,UAAkB,EAAlB,qBAAkB,EAAlB,IAAkB;YAAlB,0BAAkB;;QAC9B,yBAAyB;QACzB,sDAAsD;QACtD,uEAAuE;QACvE,IAAI,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE5C,gDAAgD;QAChD,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAEjC,6BAA6B;QAC7B,GAAG,GAA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D License.\n\nimport {\n JSONObject\n} from '@phosphor/coreutils';\n\nimport * as urlparse\n from 'url-parse';\n\n/**\n * The namespace for URL-related functions.\n */\nexport\nnamespace URLExt {\n /**\n * Parse a url into a URL object.\n *\n * @param urlString - The URL string to parse.\n *\n * @returns A URL object.\n */\n export\n function parse(url: string): IUrl {\n if (typeof document !== 'undefined') {\n let a = document.createElement('a');\n a.href = url;\n return a;\n }\n return urlparse(url);\n }\n\n /**\n * Join a sequence of url components and normalizes as in node `path.join`.\n *\n * @param parts - The url components.\n *\n * @returns the joined url.\n */\n export\n function join(...parts: string[]): string {\n // Adapted from url-join.\n // Copyright (c) 2016 José F. Romaniello, MIT License.\n // https://github.com/jfromaniello/url-join/blob/v1.1.0/lib/url-join.js\n let str = [].slice.call(parts, 0).join('/');\n\n // make sure protocol is followed by two slashes\n str = str.replace(/:\\//g, '://');\n\n // remove consecutive slashes\n str = str.replace(/([^:\\s])\\/+/g, '$1/');\n\n // remove trailing slash before parameters or hash\n str = str.replace(/\\/(\\?|&|#[^!])/g, '$1');\n\n // replace ? in parameters with &\n str = str.replace(/(\\?.+)\\?/g, '$1&');\n\n return str;\n }\n\n /**\n * Encode the components of a multi-segment url.\n *\n * @param url - The url to encode.\n *\n * @returns the encoded url.\n *\n * #### Notes\n * Preserves the `'/'` separators.\n * Should not include the base url, since all parts are escaped.\n */\n export\n function encodeParts(url: string): string {\n return join(...url.split('/').map(encodeURIComponent));\n }\n\n /**\n * Return a serialized object string suitable for a query.\n *\n * @param object - The source object.\n *\n * @returns an encoded url query.\n *\n * #### Notes\n * From [stackoverflow](http://stackoverflow.com/a/30707423).\n */\n export\n function objectToQueryString(value: JSONObject): string {\n return '?' + Object.keys(value).map(key =>\n encodeURIComponent(key) + '=' + encodeURIComponent(String(value[key]))\n ).join('&');\n }\n\n /**\n * Test whether the url is a local url.\n */\n export\n function isLocal(url: string): boolean {\n switch (parse(url).host) {\n case location.host:\n case '':\n return true;\n default:\n return false;\n }\n }\n\n /**\n * The interface for a URL object\n */\n export interface IUrl {\n /**\n * The full URL string that was parsed with both the protocol and host\n * components converted to lower-case.\n */\n href?: string;\n\n /**\n * Identifies the URL's lower-cased protocol scheme.\n */\n protocol?: string;\n\n /**\n * The full lower-cased host portion of the URL, including the port if\n * specified.\n */\n host?: string;\n\n /**\n * The lower-cased host name portion of the host component without the\n * port included.\n */\n hostname?: string;\n\n /**\n * The numeric port portion of the host component.\n */\n port?: string;\n\n /**\n * The entire path section of the URL.\n */\n pathname?: string;\n\n /**\n * The \"fragment\" portion of the URL including the leading ASCII hash\n * `(#)` character\n */\n hash?: string;\n\n\n /**\n * The search element, including leading question mark (`'?'`), if any,\n * of the URL.\n */\n search?: string;\n }\n}\n"]} |
| {"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../../../coreutils/src/uuid.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D;;;;GAIG;AACH,cACc,MAAiB;IAAjB,uBAAA,EAAA,WAAiB;IAC7B,IAAI,CAAC,GAAG,IAAI,KAAK,CAAS,MAAM,CAAC,CAAC;IAClC,IAAI,SAAS,GAAG,kBAAkB,CAAC;IACnC,IAAI,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;IAC9B,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC;IACD,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACpB,CAAC;AATD,oBASC","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\n/**\n * Get a random hex string (not a formal UUID).\n *\n * @param length - The length of the hex string.\n */\nexport\nfunction uuid(length: number=32): string {\n let s = new Array<string>(length);\n let hexDigits = '0123456789abcdef';\n let nChars = hexDigits.length;\n for (let i = 0; i < length; i++) {\n s[i] = hexDigits.charAt(Math.floor(Math.random() * nChars));\n }\n return s.join('');\n}\n"]} |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
107774
-70.03%4
33.33%30
-49.15%3255
-45.06%14
7.69%16
45.45%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed