@jupyterlab/observables 2.0.5 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +34 -0
- package/package.json +11 -5
- package/lib/index.js.map +0 -1
- package/lib/modeldb.js.map +0 -1
- package/lib/observablejson.js.map +0 -1
- package/lib/observablelist.js.map +0 -1
- package/lib/observablemap.js.map +0 -1
- package/lib/observablestring.js.map +0 -1
- package/lib/undoablelist.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Copyright (c) 2015 Project Jupyter Contributors
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
15
|
+
contributors may be used to endorse or promote products derived from
|
|
16
|
+
this software without specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28
|
+
|
|
29
|
+
Semver File License
|
|
30
|
+
===================
|
|
31
|
+
|
|
32
|
+
The semver.py file is from https://github.com/podhmo/python-semver
|
|
33
|
+
which is licensed under the "MIT" license. See the semver.py file for details.
|
|
34
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlab/observables",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Data structures which may be observed for changes.",
|
|
5
5
|
"homepage": "https://github.com/jupyterlab/jupyterlab",
|
|
6
6
|
"bugs": {
|
|
@@ -22,10 +22,11 @@
|
|
|
22
22
|
"url": "https://github.com/jupyterlab/jupyterlab.git"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
|
-
"build": "tsc",
|
|
25
|
+
"build": "tsc -b",
|
|
26
26
|
"clean": "rimraf lib",
|
|
27
|
+
"docs": "typedoc --options tdoptions.json --theme ../../typedoc-theme src",
|
|
27
28
|
"prepublishOnly": "npm run build",
|
|
28
|
-
"watch": "tsc -
|
|
29
|
+
"watch": "tsc -b --watch"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
32
|
"@phosphor/algorithm": "^1.1.2",
|
|
@@ -36,6 +37,11 @@
|
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"rimraf": "~2.6.2",
|
|
39
|
-
"
|
|
40
|
-
|
|
40
|
+
"typedoc": "~0.12.0",
|
|
41
|
+
"typescript": "~3.1.1"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"gitHead": "7fc900168981e58051253ecc66a18015a052cd2f"
|
|
41
47
|
}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../observables/src/index.ts"],"names":[],"mappings":";AAAA;;;+EAG+E;;;;;AAE/E,+BAA0B;AAC1B,sCAAiC;AACjC,sCAAiC;AACjC,qCAAgC;AAChC,wCAAmC;AACnC,oCAA+B","sourcesContent":["/*-----------------------------------------------------------------------------\n| Copyright (c) Jupyter Development Team.\n| Distributed under the terms of the Modified BSD License.\n|----------------------------------------------------------------------------*/\n\nexport * from './modeldb';\nexport * from './observablejson';\nexport * from './observablelist';\nexport * from './observablemap';\nexport * from './observablestring';\nexport * from './undoablelist';\n"]}
|
package/lib/modeldb.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"modeldb.js","sourceRoot":"","sources":["../../../../observables/src/modeldb.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D,qDAAkE;AAElE,mDAAsD;AAEtD,mDAAqE;AAErE,mDAAgD;AAEhD,qDAAmE;AAEnE,yDAAyE;AAEzE,iDAGwB;AAsOxB;;GAEG;AACH;IACE;;;;OAIG;IACH,YAAY,eAA0B,IAAI;QA2DlC,WAAM,GAAc,IAAI,CAAC;QACzB,aAAQ,GAAG,IAAI,kBAAM,CAAqC,IAAI,CAAC,CAAC;QAChE,gBAAW,GAAG,KAAK,CAAC;QA5D1B,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,IAAI,UA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E,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QACnD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CAAC,IAAY,EAAE,KAAkB;QAClC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,OAAO;SACR;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;SACpB;QACD,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACK,YAAY,CAAC,IAAY;QAC/B,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,IAAI,GAAG,IAAI,CAAC,SAAS,GAAG,GAAG,GAAG,IAAI,CAAC;SACpC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CAOF;AA9ND,0BA8NC","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport { IDisposable, DisposableSet } from '@phosphor/disposable';\n\nimport { ISignal, Signal } from '@phosphor/signaling';\n\nimport { JSONExt, JSONValue, JSONObject } from '@phosphor/coreutils';\n\nimport { ObservableMap } from './observablemap';\n\nimport { IObservableJSON, ObservableJSON } from './observablejson';\n\nimport { IObservableString, ObservableString } from './observablestring';\n\nimport {\n IObservableUndoableList,\n ObservableUndoableList\n} from './undoablelist';\n\nimport { IObservableMap } from './observablemap';\n\n/**\n * String type annotations for Observable objects that can be\n * created and placed in the IModelDB interface.\n */\nexport type ObservableType = 'Map' | 'List' | 'String' | 'Value';\n\n/**\n * Base interface for Observable objects.\n */\nexport interface IObservable extends IDisposable {\n /**\n * The type of this object.\n */\n readonly type: ObservableType;\n}\n\n/**\n * Interface for an Observable object that represents\n * an opaque JSON value.\n */\nexport interface 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 * Interface for an object representing a single collaborator\n * on a realtime model.\n */\nexport interface 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 * Interface for an IObservableMap that tracks collaborators.\n */\nexport interface ICollaboratorMap extends IObservableMap<ICollaborator> {\n /**\n * The local collaborator on a model.\n */\n readonly localCollaborator: ICollaborator;\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 interface 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 * A concrete implementation of an `IObservableValue`.\n */\nexport class 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 if (JSONExt.deepEqual(oldValue, value)) {\n return;\n }\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 * The namespace for the `ObservableValue` class statics.\n */\nexport namespace ObservableValue {\n /**\n * The changed args object emitted by the `IObservableValue`.\n */\n export 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 * A concrete implementation of an `IModelDB`.\n */\nexport class 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 );\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 * 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 namespace ModelDB {\n /**\n * Options for creating a `ModelDB` object.\n */\n export 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 interface IFactory {\n /**\n * Create a new `IModelDB` instance.\n */\n createNew(path: string): IModelDB;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"observablejson.js","sourceRoot":"","sources":["../../../../observables/src/observablejson.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D,mDAAqE;AAErE,mDAA8C;AAE9C,mDAAgE;AAsBhE;;GAEG;AACH,oBAA4B,SAAQ,6BAAwB;IAC1D;;OAEG;IACH,YAAY,UAAmC,EAAE;QAC/C,KAAK,CAAC;YACJ,OAAO,EAAE,mBAAO,CAAC,SAAS;YAC1B,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,MAAM,GAAG,GAAe,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAEzB,KAAK,IAAI,GAAG,IAAI,IAAI,EAAE;YACpB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAE5B,IAAI,KAAK,KAAK,SAAS,EAAE;gBACvB,GAAG,CAAC,GAAG,CAAC,GAAG,mBAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;aACpC;SACF;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AA3BD,wCA2BC;AAED;;GAEG;AACH,WAAiB,cAAc;IAW7B;;OAEG;IACH,mBAA2B,SAAQ,mBAAO;QACxC;;WAEG;QACH,YAAY,IAAkC;YAC5C,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACnB,CAAC;KAMF;IAbY,4BAAa,gBAazB,CAAA;AACH,CAAC,EA5BgB,cAAc,GAAd,sBAAc,KAAd,sBAAc,QA4B9B","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport { JSONExt, JSONObject, JSONValue } from '@phosphor/coreutils';\n\nimport { Message } from '@phosphor/messaging';\n\nimport { IObservableMap, ObservableMap } from './observablemap';\n\n/**\n * An observable JSON value.\n */\nexport interface IObservableJSON extends IObservableMap<JSONValue> {\n /**\n * Serialize the model to JSON.\n */\n toJSON(): JSONObject;\n}\n\n/**\n * The namespace for IObservableJSON related interfaces.\n */\nexport namespace IObservableJSON {\n /**\n * A type alias for observable JSON changed args.\n */\n export type IChangedArgs = IObservableMap.IChangedArgs<JSONValue>;\n}\n\n/**\n * A concrete Observable map for JSON data.\n */\nexport class 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 * The namespace for ObservableJSON static data.\n */\nexport namespace ObservableJSON {\n /**\n * The options use to initialize an observable JSON object.\n */\n export 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 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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"observablelist.js","sourceRoot":"","sources":["../../../../observables/src/observablelist.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAE3D,mDAO6B;AAI7B,mDAAsD;AAkStD;;GAEG;AACH;IACE;;OAEG;IACH,YAAY,UAAsC,EAAE;QAmX5C,WAAM,GAAa,EAAE,CAAC;QACtB,gBAAW,GAAG,KAAK,CAAC;QAEpB,aAAQ,GAAG,IAAI,kBAAM,CA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AC;YACZ,QAAQ;YACR,SAAS,EAAE,EAAE;YACb,SAAS,EAAE,mBAAO,CAAC,MAAM,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,WAAW,CAAC,UAAkB,EAAE,QAAgB;QAC9C,IAAI,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QACxD,KAAK,IAAI,CAAC,GAAG,UAAU,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE;YAC1C,oBAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;SAC5C;QACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACjB,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,UAAU;YACpB,QAAQ,EAAE,CAAC,CAAC;YACZ,SAAS;YACT,SAAS,EAAE,EAAE;SACd,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CAMF;AA3XD,wCA2XC;AAwBD;;GAEG;AACH,IAAU,OAAO,CAOhB;AAPD,WAAU,OAAO;IACf;;OAEG;IACH,iBAAwB,KAAU,EAAE,MAAW;QAC7C,OAAO,KAAK,KAAK,MAAM,CAAC;IAC1B,CAAC;IAFe,eAAO,UAEtB,CAAA;AACH,CAAC,EAPS,OAAO,KAAP,OAAO,QAOhB","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport {\n ArrayExt,\n ArrayIterator,\n IIterator,\n IterableOrArrayLike,\n each,\n toArray\n} from '@phosphor/algorithm';\n\nimport { IDisposable } from '@phosphor/disposable';\n\nimport { ISignal, Signal } from '@phosphor/signaling';\n\n/**\n * A list which can be observed for changes.\n */\nexport interface 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 * The namespace for IObservableList related interfaces.\n */\nexport namespace IObservableList {\n /**\n * The change types which occur on an observable list.\n */\n export 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 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 * A concrete implementation of [[IObservableList]].\n */\nexport class 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 => {\n this._array.push(value);\n });\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 * 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 each(values, value => {\n this._array.push(value);\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 each(values, value => {\n ArrayExt.insert(this._array, index++, value);\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 * The namespace for `ObservableList` class statics.\n */\nexport namespace ObservableList {\n /**\n * The options used to initialize an observable map.\n */\n export interface IOptions<T> {\n /**\n * An optional initial 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 * The namespace for module private data.\n */\nnamespace Private {\n /**\n * The default strict equality item cmp.\n */\n export function itemCmp(first: any, second: any): boolean {\n return first === second;\n }\n}\n"]}
|
package/lib/observablemap.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"observablemap.js","sourceRoot":"","sources":["../../../../observables/src/observablemap.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAI3D,mDAAsD;AAyItD;;GAEG;AACH;IACE;;OAEG;IACH,YAAY,UAAqC,EAAE;QAmK3C,SAAI,GAAmB,IAAI,GAAG,EAAa,CAAC;QAE5C,aAAQ,GAAG,IAAI,kBAAM,CAAuC,IAAI,CAAC,CAAC;QAClE,gBAAW,GAAG,KAAK,CAAC;QArK1B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;QACnD,IAAI,OAAO,CAAC,MAAM,EAAE;YAClB,KAAK,IAAI,GAAG,IAAI,OAAO,CAAC,MAAM,EAAE;gBAC9B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;aACzC;SACF;IACH,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,MAAM,KAAK,CAAC,2CAA2C,CAAC,CAAC;SAC1D;QACD,qCAAqC;QAC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AAC,GAAW;QAChB,IAAI,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACtB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACjB,IAAI,EAAE,QAAQ;YACd,GAAG,EAAE,GAAG;YACR,QAAQ,EAAE,MAAM;YAChB,QAAQ,EAAE,SAAS;SACpB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,KAAK;QACH,iDAAiD;QACjD,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACvC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;SACzB;IACH,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,OAAO;SACR;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;CAMF;AA3KD,sCA2KC;AAwBD;;GAEG;AACH,IAAU,OAAO,CAOhB;AAPD,WAAU,OAAO;IACf;;OAEG;IACH,iBAAwB,KAAU,EAAE,MAAW;QAC7C,OAAO,KAAK,KAAK,MAAM,CAAC;IAC1B,CAAC;IAFe,eAAO,UAEtB,CAAA;AACH,CAAC,EAPS,OAAO,KAAP,OAAO,QAOhB","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport { IDisposable } from '@phosphor/disposable';\n\nimport { ISignal, Signal } from '@phosphor/signaling';\n\nimport { IObservable } from './modeldb';\n\n/**\n * A map which can be observed for changes.\n */\nexport interface 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 * The interfaces associated with an IObservableMap.\n */\nexport namespace IObservableMap {\n /**\n * The change types which occur on an observable map.\n */\n export 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 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 * A concrete implementation of IObservbleMap<T>.\n */\nexport class 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 * 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 * 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 * The namespace for `ObservableMap` class statics.\n */\nexport namespace ObservableMap {\n /**\n * The options used to initialize an observable map.\n */\n export interface IOptions<T> {\n /**\n * An optional initial 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 * The namespace for module private data.\n */\nnamespace Private {\n /**\n * The default strict equality item comparator.\n */\n export function itemCmp(first: any, second: any): boolean {\n return first === second;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"observablestring.js","sourceRoot":"","sources":["../../../../observables/src/observablestring.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAI3D,mDAAsD;AA+GtD;;GAEG;AACH;IACE;;OAEG;IACH,YAAY,cAAsB,EAAE;QAsG5B,UAAK,GAAG,EAAE,CAAC;QACX,gBAAW,GAAY,KAAK,CAAC;QAC7B,aAAQ,GAAG,IAAI,kBA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C,CAAC;QACpD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAChE,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,KAAK;QACH,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO;SACR;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,kBAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACvB,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;CAKF;AA7GD,4CA6GC","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport { IDisposable } from '@phosphor/disposable';\n\nimport { ISignal, Signal } from '@phosphor/signaling';\n\nimport { IObservable } from './modeldb';\n\n/**\n * A string which can be observed for changes.\n */\nexport interface 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 * The namespace for `IObservableString` associate interfaces.\n */\nexport namespace IObservableString {\n /**\n * The change types which occur on an observable string.\n */\n export 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 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 * A concrete implementation of [[IObservableString]]\n */\nexport class 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) + text + 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) + 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"]}
|
package/lib/undoablelist.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"undoablelist.js","sourceRoot":"","sources":["../../../../observables/src/undoablelist.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,2DAA2D;;AAI3D,mDAA2C;AAE3C,qDAAmE;AA6DnE;;GAEG;AACH,4BAAuC,SAAQ,+BAAiB;IAE9D;;OAEG;IACH,YAAY,UAA0B;QACpC,KAAK,EAAE,CAAC;QAuMF,gBAAW,GAAG,KAAK,CAAC;QACpB,gBAAW,GAAG,IAAI,CAAC;QACnB,wBAAmB,GAAG,KAAK,CAAC;QAC5B,WAAM,GAAG,CAAC,CAAC,CAAC;QACZ,WAAM,GAAgD,EAAE,CAAC;QA1M/D,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,sBAA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OAAO,KAAK,CAAC;QACf,CAAC;QAED;;WAEG;QACH,QAAQ,CAAC,KAAgB;YACvB,OAAO,KAAU,CAAC;QACpB,CAAC;KACF;IAfY,yCAAkB,qBAe9B,CAAA;AACH,CAAC,EApBgB,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAoBtC","sourcesContent":["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport { JSONValue } from '@phosphor/coreutils';\n\nimport { each } from '@phosphor/algorithm';\n\nimport { IObservableList, ObservableList } from './observablelist';\n\n/**\n * An object which knows how to serialize and\n * deserialize the type T.\n */\nexport interface 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 * An observable list that supports undo/redo.\n */\nexport interface 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 * A concrete implementation of an observable undoable list.\n */\nexport class ObservableUndoableList<T> extends ObservableList<T>\n 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(\n list: IObservableList<T>,\n change: IObservableList.IChangedArgs<T>\n ): 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(\n change: IObservableList.IChangedArgs<T>\n ): 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 namespace ObservableUndoableList {\n /**\n * A default, identity serializer.\n */\n export class IdentitySerializer<T extends JSONValue>\n 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"]}
|