mirror of
https://github.com/nasa/openmct.git
synced 2024-12-19 21:27:52 +00:00
Generate type declarations for CompositionAPI and publish with OpenMCT (#5838)
* add typescript
* update tsconfig
* convert to es6 class
* Convert more stuff to es6 class
* skip checking libs, test files
* more es6 classes!
* Fix some jsdocs
* Rename file
* Improve jsdoc types
* Rename references as well
* more types
* types for CompositionAPI
* Types for CompositionCollection
* Types for CompositionProvider
* type
* types for api
* nvm
* cleanup MCT
* Fix API type definition
* Generate types before publish
* fix openmct 👀
* rename PublicAPI -> OpenMCT and document methods
* try and fix visual test ?
* Make private methods private
* more private methods!!
* import all es6 api's so we get more types for free
* convert Selection to es6 class
* remove redundant docs
* fix Branding types
* fix openmct.start() types
* Remove useless `@memberof`
* Add parameter name
* [docs] Add a section on Types
* markdownlint
* word
* Add section on limitations / contibuting types
* Let these methods be private
* make private members private, fix a type
* fix another type
* Make method private
* Update docs for `skipMutate` and related methods
* Rename file and fix references
* `DefaultCompositionProvider` extends `CompositionProvider`
* Make private members private
* Type for `AbortSignal`
* `domainObject` must be accessible for perf tests
Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
parent
b4554d2fc1
commit
41fc502564
224
API.md
224
API.md
@ -2,10 +2,13 @@
|
||||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
||||
**Table of Contents**
|
||||
|
||||
- [Building Applications With Open MCT](#building-applications-with-open-mct)
|
||||
- [Building Applications With Open MCT](#developing-applications-with-open-mct)
|
||||
- [Scope and purpose of this document](#scope-and-purpose-of-this-document)
|
||||
- [Building From Source](#building-from-source)
|
||||
- [Starting an Open MCT application](#starting-an-open-mct-application)
|
||||
- [Types](#types)
|
||||
- [Using Types](#using-types)
|
||||
- [Limitations](#limitations)
|
||||
- [Plugins](#plugins)
|
||||
- [Defining and Installing a New Plugin](#defining-and-installing-a-new-plugin)
|
||||
- [Domain Objects and Identifiers](#domain-objects-and-identifiers)
|
||||
@ -133,6 +136,48 @@ do anything with the application initially. Any of these plugins can, in
|
||||
principle, be replaced with a custom plugin. The included plugins are
|
||||
documented in the [Included Plugins](#included-plugins) section.
|
||||
|
||||
## Types
|
||||
|
||||
The Open MCT library includes its own TypeScript declaration files which can be
|
||||
used to provide code hints and typechecking in your own Open MCT application.
|
||||
|
||||
Open MCT's type declarations are generated via `tsc` from JSDoc-style comment
|
||||
blocks. For more information on this, [check out TypeScript's documentation](https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html).
|
||||
|
||||
### Using Types
|
||||
|
||||
In order to use Open MCT's provided types in your own application, create a
|
||||
`jsconfig.js` at the root of your project with this minimal configuration:
|
||||
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"target": "es6",
|
||||
"checkJs": true,
|
||||
"moduleResolution": "node",
|
||||
"paths": {
|
||||
"openmct": ["node_modules/openmct/dist/openmct.d.ts"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then, simply import and use `openmct` in your application:
|
||||
|
||||
```js
|
||||
import openmct from "openmct";
|
||||
```
|
||||
|
||||
### Limitations
|
||||
|
||||
The effort to add types for Open MCT's public API is ongoing, and the provided
|
||||
type declarations may be incomplete.
|
||||
|
||||
If you would like to contribute types to Open MCT, please check out
|
||||
[TypeScript's documentation](https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html) on generating type declarations from JSDoc-style comment blocks.
|
||||
Then read through our [contributing guide](https://github.com/nasa/openmct/blob/f7cf3f72c2efd46da7ce5719c5e52c8806d166f0/CONTRIBUTING.md) and open a PR!
|
||||
|
||||
## Plugins
|
||||
|
||||
### Defining and Installing a New Plugin
|
||||
@ -189,10 +234,10 @@ looks like this:
|
||||
|
||||
The main attributes to note are the `identifier`, and `type` attributes.
|
||||
|
||||
* `identifier`: A composite key that provides a universally unique identifier
|
||||
- `identifier`: A composite key that provides a universally unique identifier
|
||||
for this object. The `namespace` and `key` are used to identify the object.
|
||||
The `key` must be unique within the namespace.
|
||||
* `type`: All objects in Open MCT have a type. Types allow you to form an
|
||||
- `type`: All objects in Open MCT have a type. Types allow you to form an
|
||||
ontology of knowledge and provide an abstraction for grouping, visualizing,
|
||||
and interpreting data. Details on how to define a new object type are
|
||||
provided below.
|
||||
@ -206,6 +251,7 @@ Custom types may be registered via the `addType` function on the Open MCT Type
|
||||
registry.
|
||||
|
||||
eg.
|
||||
|
||||
```javascript
|
||||
openmct.types.addType('example.my-type', {
|
||||
name: "My Type",
|
||||
@ -215,20 +261,21 @@ openmct.types.addType('example.my-type', {
|
||||
```
|
||||
|
||||
The `addType` function accepts two arguments:
|
||||
* A `string` key identifying the type. This key is used when specifying a type
|
||||
|
||||
- A `string` key identifying the type. This key is used when specifying a type
|
||||
for an object. We recommend prefixing your types with a namespace to avoid
|
||||
conflicts with other plugins.
|
||||
* An object type specification. An object type definition supports the following
|
||||
- An object type specification. An object type definition supports the following
|
||||
attributes
|
||||
* `name`: a `string` naming this object type
|
||||
* `description`: a `string` specifying a longer-form description of this type
|
||||
* `initialize`: a `function` which initializes the model for new domain objects
|
||||
- `name`: a `string` naming this object type
|
||||
- `description`: a `string` specifying a longer-form description of this type
|
||||
- `initialize`: a `function` which initializes the model for new domain objects
|
||||
of this type. This can be used for setting default values on an object when
|
||||
it is instantiated.
|
||||
* `creatable`: A `boolean` indicating whether users should be allowed to create
|
||||
- `creatable`: A `boolean` indicating whether users should be allowed to create
|
||||
this type (default: `false`). This will determine whether the type appears
|
||||
in the `Create` menu.
|
||||
* `cssClass`: A `string` specifying a CSS class to apply to each representation
|
||||
- `cssClass`: A `string` specifying a CSS class to apply to each representation
|
||||
of this object. This is used for specifying an icon to appear next to each
|
||||
object of this type.
|
||||
|
||||
@ -246,6 +293,7 @@ as a hierarchy of telemetry-providing domain objects in this fashion.
|
||||
To do so, use the `addRoot` method of the object API.
|
||||
|
||||
eg.
|
||||
|
||||
```javascript
|
||||
openmct.objects.addRoot({
|
||||
namespace: "example.namespace",
|
||||
@ -260,6 +308,7 @@ level objects, or a function that returns a promise for an identifier or an arra
|
||||
When using the `getAll` method of the object API, they will be returned in order of priority.
|
||||
|
||||
eg.
|
||||
|
||||
```javascript
|
||||
openmct.objects.addRoot(identifier, openmct.priority.LOW); // low = -1000, will appear last in composition or tree
|
||||
openmct.objects.addRoot(otherIdentifier, openmct.priority.HIGH); // high = 1000, will appear first in composition or tree
|
||||
@ -287,11 +336,12 @@ openmct.objects.addProvider('example.namespace', {
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
The `addProvider` function takes two arguments:
|
||||
|
||||
* `namespace`: A `string` representing the namespace that this object provider
|
||||
- `namespace`: A `string` representing the namespace that this object provider
|
||||
will provide objects for.
|
||||
* `provider`: An `object` with a single function, `get`. This function accepts an
|
||||
- `provider`: An `object` with a single function, `get`. This function accepts an
|
||||
[Identifier](#domain-objects-and-identifiers) for the object to be provided.
|
||||
It is expected that the `get` function will return a
|
||||
[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
||||
@ -323,12 +373,13 @@ openmct.composition.addProvider({
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
The `addProvider` function accepts a Composition Provider object as its sole
|
||||
argument. A Composition Provider is a javascript object exposing two functions:
|
||||
* `appliesTo`: A `function` that accepts a `domainObject` argument, and returns
|
||||
- `appliesTo`: A `function` that accepts a `domainObject` argument, and returns
|
||||
a `boolean` value indicating whether this composition provider applies to the
|
||||
given object.
|
||||
* `load`: A `function` that accepts a `domainObject` as an argument, and returns
|
||||
- `load`: A `function` that accepts a `domainObject` as an argument, and returns
|
||||
a `Promise` that resolves with an array of [Identifier](#domain-objects-and-identifiers).
|
||||
These identifiers will be used to fetch Domain Objects from an [Object Provider](#object-provider)
|
||||
|
||||
@ -429,24 +480,22 @@ attribute | type | flags | notes
|
||||
`max` | number | optional | the maximum possible value of this measurement. Will be used by plots, gauges, etc to automatically set a max value.
|
||||
`enumerations` | array | optional | for objects where `format` is `"enum"`, this array tracks all possible enumerations of the value. Each entry in this array is an object, with a `value` property that is the numerical value of the enumeration, and a `string` property that is the text value of the enumeration. ex: `{"value": 0, "string": "OFF"}`. If you use an enumerations array, `min` and `max` will be set automatically for you.
|
||||
|
||||
|
||||
###### Value Hints
|
||||
|
||||
Each telemetry value description has an object defining hints. Keys in this object represent the hint itself, and the value represents the weight of that hint. A lower weight means the hint has a higher priority. For example, multiple values could be hinted for use as the y-axis of a plot (raw, engineering), but the highest priority would be the default choice. Likewise, a table will use hints to determine the default order of columns.
|
||||
|
||||
Known hints:
|
||||
|
||||
* `domain`: Values with a `domain` hint will be used for the x-axis of a plot, and tables will render columns for these values first.
|
||||
* `range`: Values with a `range` hint will be used as the y-axis on a plot, and tables will render columns for these values after the `domain` values.
|
||||
* `image`: Indicates that the value may be interpreted as the URL to an image file, in which case appropriate views will be made available.
|
||||
* `imageDownloadName`: Indicates that the value may be interpreted as the name of the image file.
|
||||
- `domain`: Values with a `domain` hint will be used for the x-axis of a plot, and tables will render columns for these values first.
|
||||
- `range`: Values with a `range` hint will be used as the y-axis on a plot, and tables will render columns for these values after the `domain` values.
|
||||
- `image`: Indicates that the value may be interpreted as the URL to an image file, in which case appropriate views will be made available.
|
||||
- `imageDownloadName`: Indicates that the value may be interpreted as the name of the image file.
|
||||
|
||||
##### The Time Conductor and Telemetry
|
||||
|
||||
Open MCT provides a number of ways to pivot through data and link data via time. The Time Conductor helps synchronize multiple views around the same time.
|
||||
|
||||
In order for the time conductor to work, there will always be an active "time system". All telemetry metadata *must* have a telemetry value with a `key` that matches the `key` of the active time system. You can use the `source` attribute on the value metadata to remap this to a different field in the telemetry datum-- especially useful if you are working with disparate datasources that have different field mappings.
|
||||
|
||||
In order for the time conductor to work, there will always be an active "time system". All telemetry metadata _must_ have a telemetry value with a `key` that matches the `key` of the active time system. You can use the `source` attribute on the value metadata to remap this to a different field in the telemetry datum-- especially useful if you are working with disparate datasources that have different field mappings.
|
||||
|
||||
#### Telemetry Providers
|
||||
|
||||
@ -454,14 +503,14 @@ Telemetry providers are responsible for providing historical and real-time telem
|
||||
|
||||
A telemetry provider is a javascript object with up to four methods:
|
||||
|
||||
* `supportsSubscribe(domainObject, callback, options)` optional. Must be implemented to provide realtime telemetry. Should return `true` if the provider supports subscriptions for the given domain object (and request options).
|
||||
* `subscribe(domainObject, callback, options)` required if `supportsSubscribe` is implemented. Establish a subscription for realtime data for the given domain object. Should invoke `callback` with a single telemetry datum every time data is received. Must return an unsubscribe function. Multiple views can subscribe to the same telemetry object, so it should always return a new unsubscribe function.
|
||||
* `supportsRequest(domainObject, options)` optional. Must be implemented to provide historical telemetry. Should return `true` if the provider supports historical requests for the given domain object.
|
||||
* `request(domainObject, options)` required if `supportsRequest` is implemented. Must return a promise for an array of telemetry datums that fulfills the request. The `options` argument will include a `start`, `end`, and `domain` attribute representing the query bounds. See [Telemetry Requests and Responses](#telemetry-requests-and-responses) for more info on how to respond to requests.
|
||||
* `supportsMetadata(domainObject)` optional. Implement and return `true` for objects that you want to provide dynamic metadata for.
|
||||
* `getMetadata(domainObject)` required if `supportsMetadata` is implemented. Must return a valid telemetry metadata definition that includes at least one valueMetadata definition.
|
||||
* `supportsLimits(domainObject)` optional. Implement and return `true` for domain objects that you want to provide a limit evaluator for.
|
||||
* `getLimitEvaluator(domainObject)` required if `supportsLimits` is implemented. Must return a valid LimitEvaluator for a given domain object.
|
||||
- `supportsSubscribe(domainObject, callback, options)` optional. Must be implemented to provide realtime telemetry. Should return `true` if the provider supports subscriptions for the given domain object (and request options).
|
||||
- `subscribe(domainObject, callback, options)` required if `supportsSubscribe` is implemented. Establish a subscription for realtime data for the given domain object. Should invoke `callback` with a single telemetry datum every time data is received. Must return an unsubscribe function. Multiple views can subscribe to the same telemetry object, so it should always return a new unsubscribe function.
|
||||
- `supportsRequest(domainObject, options)` optional. Must be implemented to provide historical telemetry. Should return `true` if the provider supports historical requests for the given domain object.
|
||||
- `request(domainObject, options)` required if `supportsRequest` is implemented. Must return a promise for an array of telemetry datums that fulfills the request. The `options` argument will include a `start`, `end`, and `domain` attribute representing the query bounds. See [Telemetry Requests and Responses](#telemetry-requests-and-responses) for more info on how to respond to requests.
|
||||
- `supportsMetadata(domainObject)` optional. Implement and return `true` for objects that you want to provide dynamic metadata for.
|
||||
- `getMetadata(domainObject)` required if `supportsMetadata` is implemented. Must return a valid telemetry metadata definition that includes at least one valueMetadata definition.
|
||||
- `supportsLimits(domainObject)` optional. Implement and return `true` for domain objects that you want to provide a limit evaluator for.
|
||||
- `getLimitEvaluator(domainObject)` required if `supportsLimits` is implemented. Must return a valid LimitEvaluator for a given domain object.
|
||||
|
||||
Telemetry providers are registered by calling `openmct.telemetry.addProvider(provider)`, e.g.
|
||||
|
||||
@ -474,7 +523,7 @@ openmct.telemetry.addProvider({
|
||||
|
||||
Note: it is not required to implement all of the methods on every provider. Depending on the complexity of your implementation, it may be helpful to instantiate and register your realtime, historical, and metadata providers separately.
|
||||
|
||||
#### Telemetry Requests and Responses.
|
||||
#### Telemetry Requests and Responses
|
||||
|
||||
Telemetry requests support time bounded queries. A call to a _Telemetry Provider_'s `request` function will include an `options` argument. These are simply javascript objects with attributes for the request parameters. An example of a telemetry request object with a start and end time is included below:
|
||||
|
||||
@ -507,6 +556,7 @@ the number of results it desires. The `size` parameter is a hint; views
|
||||
must not assume the response will have the exact number of results requested.
|
||||
|
||||
example:
|
||||
|
||||
```javascript
|
||||
{
|
||||
start: 1487981997240,
|
||||
@ -522,6 +572,7 @@ This strategy says "I want the latest data point in this time range". A provide
|
||||
##### `minmax` request strategy
|
||||
|
||||
example:
|
||||
|
||||
```javascript
|
||||
{
|
||||
start: 1487981997240,
|
||||
@ -539,8 +590,8 @@ MinMax queries are issued by plots, and may be issued by other types as well. T
|
||||
Telemetry format objects define how to interpret and display telemetry data.
|
||||
They have a simple structure:
|
||||
|
||||
* `key`: A `string` that uniquely identifies this formatter.
|
||||
* `format`: A `function` that takes a raw telemetry value, and returns a
|
||||
- `key`: A `string` that uniquely identifies this formatter.
|
||||
- `format`: A `function` that takes a raw telemetry value, and returns a
|
||||
human-readable `string` representation of that value. It has one required
|
||||
argument, and three optional arguments that provide context and can be used
|
||||
for returning scaled representations of a value. An example of this is
|
||||
@ -548,16 +599,16 @@ They have a simple structure:
|
||||
are multiple ways of representing a point in time, and by providing a minimum
|
||||
scale value, maximum scale value, and a count, it's possible to provide more
|
||||
useful representations of time given the provided limitations.
|
||||
* `value`: The raw telemetry value in its native type.
|
||||
* `minValue`: An __optional__ argument specifying the minimum displayed
|
||||
- `value`: The raw telemetry value in its native type.
|
||||
- `minValue`: An **optional** argument specifying the minimum displayed
|
||||
value.
|
||||
* `maxValue`: An __optional__ argument specifying the maximum displayed
|
||||
- `maxValue`: An **optional** argument specifying the maximum displayed
|
||||
value.
|
||||
* `count`: An __optional__ argument specifying the number of displayed
|
||||
- `count`: An **optional** argument specifying the number of displayed
|
||||
values.
|
||||
* `parse`: A `function` that takes a `string` representation of a telemetry
|
||||
- `parse`: A `function` that takes a `string` representation of a telemetry
|
||||
value, and returns the value in its native type. **Note** parse might receive an already-parsed value. This function should be idempotent.
|
||||
* `validate`: A `function` that takes a `string` representation of a telemetry
|
||||
- `validate`: A `function` that takes a `string` representation of a telemetry
|
||||
value, and returns a `boolean` value indicating whether the provided string
|
||||
can be parsed.
|
||||
|
||||
@ -583,9 +634,9 @@ openmct.telemetry.addFormat({
|
||||
#### Telemetry Data
|
||||
|
||||
A single telemetry point is considered a Datum, and is represented by a standard
|
||||
javascript object. Realtime subscriptions (obtained via __subscribe__) will
|
||||
javascript object. Realtime subscriptions (obtained via **subscribe**) will
|
||||
invoke the supplied callback once for each telemetry datum recieved. Telemetry
|
||||
requests (obtained via __request__) will return a promise for an array of
|
||||
requests (obtained via **request**) will return a promise for an array of
|
||||
telemetry datums.
|
||||
|
||||
##### Telemetry Datums
|
||||
@ -622,7 +673,6 @@ For an example of a limit evaluator, take a look at `examples/generator/Sinewave
|
||||
|
||||
The APIs for requesting telemetry from Open MCT -- e.g. for use in custom views -- are currently in draft state and are being revised. If you'd like to experiment with them before they are finalized, please contact the team via the contact-us link on our website.
|
||||
|
||||
|
||||
## Time API
|
||||
|
||||
Open MCT provides API for managing the temporal state of the application.
|
||||
@ -664,25 +714,25 @@ is configured and activated by default from `index.html` in the default
|
||||
installation of Open MCT if you download the source from GitHub. Some details of
|
||||
each of the required properties is provided below.
|
||||
|
||||
* `key`: A `string` that uniquely identifies this time system.
|
||||
* `name`: A `string` providing a brief human readable label. If the [Time Conductor](#the-time-conductor)
|
||||
- `key`: A `string` that uniquely identifies this time system.
|
||||
- `name`: A `string` providing a brief human readable label. If the [Time Conductor](#the-time-conductor)
|
||||
plugin is enabled, this name will identify the time system in a dropdown menu.
|
||||
* `cssClass`: A class name `string` that will be applied to the time system when
|
||||
- `cssClass`: A class name `string` that will be applied to the time system when
|
||||
it appears in the UI. This will be used to represent the time system with an icon.
|
||||
There are a number of built-in icon classes [available in Open MCT](https://github.com/nasa/openmct/blob/master/platform/commonUI/general/res/sass/_glyphs.scss),
|
||||
or a custom class can be used here.
|
||||
* `timeFormat`: A `string` corresponding to the key of a registered
|
||||
- `timeFormat`: A `string` corresponding to the key of a registered
|
||||
[telemetry time format](#telemetry-formats). The format will be used for
|
||||
displaying discrete timestamps from telemetry streams when this time system is
|
||||
activated. If the [UTCTimeSystem](#included-plugins) is enabled, then the `utc`
|
||||
format can be used if this is a utc-based time system
|
||||
* `durationFormat`: A `string` corresponding to the key of a registered
|
||||
- `durationFormat`: A `string` corresponding to the key of a registered
|
||||
[telemetry time format](#telemetry-formats). The format will be used for
|
||||
displaying time ranges, for example `00:15:00` might be used to represent a time
|
||||
period of fifteen minutes. These are used by the Time Conductor plugin to specify
|
||||
relative time offsets. If the [UTCTimeSystem](#included-plugins) is enabled,
|
||||
then the `duration` format can be used if this is a utc-based time system
|
||||
* `isUTCBased`: A `boolean` that defines whether this time system represents
|
||||
- `isUTCBased`: A `boolean` that defines whether this time system represents
|
||||
numbers in UTC terrestrial time.
|
||||
|
||||
#### Getting and Setting the Active Time System
|
||||
@ -711,10 +761,10 @@ event. If you supplied bounds, a [`'bounds'`](#time-events) event will be trigg
|
||||
The TimeAPI provides a getter/setter for querying and setting time bounds. Time
|
||||
bounds are simply an object with a `start` and an end `end` attribute.
|
||||
|
||||
* `start`: A `number` representing a moment in time in the active [Time System](#defining-and-registering-time-systems).
|
||||
- `start`: A `number` representing a moment in time in the active [Time System](#defining-and-registering-time-systems).
|
||||
This will be used as the beginning of the time period displayed by time-responsive
|
||||
telemetry views.
|
||||
* `end`: A `number` representing a moment in time in the active [Time System](#defining-and-registering-time-systems).
|
||||
- `end`: A `number` representing a moment in time in the active [Time System](#defining-and-registering-time-systems).
|
||||
This will be used as the end of the time period displayed by time-responsive
|
||||
telemetry views.
|
||||
|
||||
@ -753,28 +803,28 @@ context of the active [Time System](#defining-and-registering-time-systems).
|
||||
|
||||
A clock is an object that defines certain required metadata and functions:
|
||||
|
||||
* `key`: A `string` uniquely identifying this clock. This can be used later to
|
||||
- `key`: A `string` uniquely identifying this clock. This can be used later to
|
||||
reference the clock in places such as the [Time Conductor configuration](#time-conductor-configuration)
|
||||
* `cssClass`: A `string` identifying a CSS class to apply to this clock when it's
|
||||
- `cssClass`: A `string` identifying a CSS class to apply to this clock when it's
|
||||
displayed in the UI. This will be used to represent the time system with an icon.
|
||||
There are a number of built-in icon classes [available in Open MCT](https://github.com/nasa/openmct/blob/master/platform/commonUI/general/res/sass/_glyphs.scss),
|
||||
or a custom class can be used here.
|
||||
* `name`: A `string` providing a human-readable identifier for the clock source.
|
||||
- `name`: A `string` providing a human-readable identifier for the clock source.
|
||||
This will be displayed in the clock selector menu in the Time Conductor UI
|
||||
component, if active.
|
||||
* `description`: An __optional__ `string` providing a longer description of the
|
||||
- `description`: An **optional** `string` providing a longer description of the
|
||||
clock. The description will be visible in the clock selection menu in the Time
|
||||
Conductor plugin.
|
||||
* `on`: A `function` supporting registration of a new callback that will be
|
||||
- `on`: A `function` supporting registration of a new callback that will be
|
||||
invoked when the clock next ticks. It will be invoked with two arguments:
|
||||
* `eventName`: A `string` specifying the event to listen on. For now, clocks
|
||||
- `eventName`: A `string` specifying the event to listen on. For now, clocks
|
||||
support one event - `tick`.
|
||||
* `callback`: A `function` that will be invoked when this clock ticks. The
|
||||
- `callback`: A `function` that will be invoked when this clock ticks. The
|
||||
function must be invoked with one parameter - a `number` representing a valid
|
||||
time in the current time system.
|
||||
* `off`: A `function` that allows deregistration of a tick listener. It accepts
|
||||
- `off`: A `function` that allows deregistration of a tick listener. It accepts
|
||||
the same arguments as `on`.
|
||||
* `currentValue`: A `function` that returns a `number` representing a point in
|
||||
- `currentValue`: A `function` that returns a `number` representing a point in
|
||||
time in the active time system. It should be the last value provided by a tick,
|
||||
or some default value if no ticking has yet occurred.
|
||||
|
||||
@ -812,7 +862,6 @@ active clock. [`clockOffsets`](#clock-offsets) must be specified when changing a
|
||||
|
||||
Setting the clock triggers a [`'clock'`](#time-events) event, followed by a [`'clockOffsets'`](#time-events) event, and then a [`'bounds'`](#time-events) event as the offsets are applied to the clock's currentValue().
|
||||
|
||||
|
||||
```
|
||||
openmct.time.clock(someClock, clockOffsets);
|
||||
```
|
||||
@ -841,10 +890,10 @@ the current value provided by the active clock (via its `tick` event, or its
|
||||
Unlike bounds, which represent absolute time values, clock offsets represent
|
||||
relative time spans. Offsets are defined as an object with two properties:
|
||||
|
||||
* `start`: A `number` that must be < 0 and which is used to calculate the start
|
||||
- `start`: A `number` that must be < 0 and which is used to calculate the start
|
||||
bounds on each clock tick. The start offset will be calculated relative to the
|
||||
value provided by a clock's tick callback, or its `currentValue()` function.
|
||||
* `end`: A `number` that must be >= 0 and which is used to calculate the end
|
||||
- `end`: A `number` that must be >= 0 and which is used to calculate the end
|
||||
bounds on each clock tick.
|
||||
|
||||
The `clockOffsets` function can be used to get or set clock offsets. For example,
|
||||
@ -859,7 +908,7 @@ openmct.time.clockOffsets({
|
||||
})
|
||||
```
|
||||
|
||||
__Note:__ Setting the clock offsets will trigger an immediate bounds change, as
|
||||
**Note:** Setting the clock offsets will trigger an immediate bounds change, as
|
||||
new bounds will be calculated based on the `currentValue()` of the active clock.
|
||||
Clock offsets are only relevant when a clock source is active.
|
||||
|
||||
@ -879,11 +928,11 @@ openmct.time.on('bounds', function callback (newBounds, tick) {
|
||||
|
||||
The events emitted by the Time API are:
|
||||
|
||||
* `bounds`: emitted whenever the bounds change. The callback will be invoked
|
||||
- `bounds`: emitted whenever the bounds change. The callback will be invoked
|
||||
with two arguments:
|
||||
* `bounds`: A [bounds](#getting-and-setting-bounds) bounds object
|
||||
- `bounds`: A [bounds](#getting-and-setting-bounds) bounds object
|
||||
representing a new time period bound by the specified start and send times.
|
||||
* `tick`: A `boolean` indicating whether or not this bounds change is due to
|
||||
- `tick`: A `boolean` indicating whether or not this bounds change is due to
|
||||
a "tick" from a [clock source](#clocks). This information can be useful
|
||||
when determining a strategy for fetching telemetry data in response to a
|
||||
bounds change event. For example, if the bounds change was automatic, and
|
||||
@ -894,16 +943,15 @@ The events emitted by the Time API are:
|
||||
If `tick` is false,then the bounds change was not due to an automatic tick,
|
||||
and a query for historical data may be necessary, depending on your data
|
||||
caching strategy, and how significantly the start bound has changed.
|
||||
* `timeSystem`: emitted whenever the active time system changes. The callback will be invoked with a single argument:
|
||||
* `timeSystem`: The newly active [time system](#defining-and-registering-time-systems).
|
||||
* `clock`: emitted whenever the clock changes. The callback will be invoked
|
||||
- `timeSystem`: emitted whenever the active time system changes. The callback will be invoked with a single argument:
|
||||
- `timeSystem`: The newly active [time system](#defining-and-registering-time-systems).
|
||||
- `clock`: emitted whenever the clock changes. The callback will be invoked
|
||||
with a single argument:
|
||||
* `clock`: The newly active [clock](#clocks), or `undefined` if an active
|
||||
- `clock`: The newly active [clock](#clocks), or `undefined` if an active
|
||||
clock has been deactivated.
|
||||
* `clockOffsets`: emitted whenever the active clock offsets change. The
|
||||
- `clockOffsets`: emitted whenever the active clock offsets change. The
|
||||
callback will be invoked with a single argument:
|
||||
* `clockOffsets`: The new [clock offsets](#clock-offsets).
|
||||
|
||||
- `clockOffsets`: The new [clock offsets](#clock-offsets).
|
||||
|
||||
### The Time Conductor
|
||||
|
||||
@ -928,29 +976,29 @@ array is an object with some properties specifying configuration. The configurat
|
||||
options specified are slightly different depending on whether or not it is for
|
||||
an active clock mode.
|
||||
|
||||
__Configuration for Fixed Time Mode (no active clock)__
|
||||
**Configuration for Fixed Time Mode (no active clock)**
|
||||
|
||||
* `timeSystem`: A `string`, the key for the time system that this configuration
|
||||
- `timeSystem`: A `string`, the key for the time system that this configuration
|
||||
relates to.
|
||||
* `bounds`: A [`Time Bounds`](#time-bounds) object. These bounds will be applied
|
||||
- `bounds`: A [`Time Bounds`](#time-bounds) object. These bounds will be applied
|
||||
when the user selects the time system specified in the previous `timeSystem`
|
||||
property.
|
||||
* `zoomOutLimit`: An __optional__ `number` specifying the longest period of time
|
||||
- `zoomOutLimit`: An **optional** `number` specifying the longest period of time
|
||||
that can be represented by the conductor when zooming. If a `zoomOutLimit` is
|
||||
provided, then a `zoomInLimit` must also be provided. If provided, the zoom
|
||||
slider will automatically become available in the Time Conductor UI.
|
||||
* `zoomInLimit`: An __optional__ `number` specifying the shortest period of time
|
||||
- `zoomInLimit`: An **optional** `number` specifying the shortest period of time
|
||||
that can be represented by the conductor when zooming. If a `zoomInLimit` is
|
||||
provided, then a `zoomOutLimit` must also be provided. If provided, the zoom
|
||||
slider will automatically become available in the Time Conductor UI.
|
||||
|
||||
__Configuration for Active Clock__
|
||||
**Configuration for Active Clock**
|
||||
|
||||
* `clock`: A `string`, the `key` of the clock that this configuration applies to.
|
||||
* `timeSystem`: A `string`, the key for the time system that this configuration
|
||||
- `clock`: A `string`, the `key` of the clock that this configuration applies to.
|
||||
- `timeSystem`: A `string`, the key for the time system that this configuration
|
||||
relates to. Separate configuration must be provided for each time system that you
|
||||
wish to be available to users when they select the specified clock.
|
||||
* `clockOffsets`: A [`clockOffsets`](#clock-offsets) object that will be
|
||||
- `clockOffsets`: A [`clockOffsets`](#clock-offsets) object that will be
|
||||
automatically applied when the combination of clock and time system specified in
|
||||
this configuration is selected from the UI.
|
||||
|
||||
@ -1017,6 +1065,7 @@ A simple indicator with an icon and some text can be created and added with mini
|
||||
of this type exposes functions for customizing the text, icon, and style of the indicator.
|
||||
|
||||
eg.
|
||||
|
||||
``` javascript
|
||||
var myIndicator = openmct.indicators.simpleIndicator();
|
||||
myIndicator.text("Hello World!");
|
||||
@ -1028,20 +1077,20 @@ By default, the indicator will appear as an information icon. Hovering over the
|
||||
reveal the text set via the call to `.text()`. The Indicator object returned by the API
|
||||
call exposes a number of functions for customizing the content and appearance of the indicator:
|
||||
|
||||
* `.text([text])`: Gets or sets the text shown when the user hovers over the indicator.
|
||||
Accepts an __optional__ `string` argument that, if provided, will be used to set the text.
|
||||
- `.text([text])`: Gets or sets the text shown when the user hovers over the indicator.
|
||||
Accepts an **optional** `string` argument that, if provided, will be used to set the text.
|
||||
Hovering over the indicator will expand it to its full size, revealing this text alongside
|
||||
the icon. Returns the currently set text as a `string`.
|
||||
* `.description([description])`: Gets or sets the indicator's description. Accepts an
|
||||
__optional__ `string` argument that, if provided, will be used to set the text. The description
|
||||
- `.description([description])`: Gets or sets the indicator's description. Accepts an
|
||||
**optional** `string` argument that, if provided, will be used to set the text. The description
|
||||
allows for more detail to be provided in a tooltip when the user hovers over the indicator.
|
||||
Returns the currently set text as a `string`.
|
||||
* `.iconClass([className])`: Gets or sets the CSS class used to define the icon. Accepts an __optional__
|
||||
- `.iconClass([className])`: Gets or sets the CSS class used to define the icon. Accepts an **optional**
|
||||
`string` parameter to be used to set the class applied to the indicator. Any of
|
||||
[the built-in glyphs](https://nasa.github.io/openmct/style-guide/#/browse/styleguide:home/glyphs?view=styleguide.glyphs)
|
||||
may be used here, or a custom CSS class can be provided. Returns the currently defined CSS
|
||||
class as a `string`.
|
||||
* `.statusClass([className])`: Gets or sets the CSS class used to determine status. Accepts an __optional __
|
||||
- `.statusClass([className])`: Gets or sets the CSS class used to determine status. Accepts an __optional__
|
||||
`string` parameter to be used to set a status class applied to the indicator. May be used to apply
|
||||
different colors to indicate status.
|
||||
|
||||
@ -1068,6 +1117,7 @@ Open MCT provides some built-in priority values that can be used in the applicat
|
||||
### Priority Types
|
||||
|
||||
Currently, the Open MCT Priority API provides (type: numeric value):
|
||||
|
||||
- HIGH: 1000
|
||||
- Default: 0
|
||||
- LOW: -1000
|
||||
|
45
openmct.js
45
openmct.js
@ -30,8 +30,53 @@ if (document.currentScript) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {object} BuildInfo
|
||||
* @property {string} version
|
||||
* @property {string} buildDate
|
||||
* @property {string} revision
|
||||
* @property {string} branch
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} OpenMCT
|
||||
* @property {BuildInfo} buildInfo
|
||||
* @property {*} selection
|
||||
* @property {import('./src/api/time/TimeAPI').default} time
|
||||
* @property {import('./src/api/composition/CompositionAPI').default} composition
|
||||
* @property {*} objectViews
|
||||
* @property {*} inspectorViews
|
||||
* @property {*} propertyEditors
|
||||
* @property {*} toolbars
|
||||
* @property {*} types
|
||||
* @property {import('./src/api/objects/ObjectAPI').default} objects
|
||||
* @property {import('./src/api/telemetry/TelemetryAPI').default} telemetry
|
||||
* @property {import('./src/api/indicators/IndicatorAPI').default} indicators
|
||||
* @property {import('./src/api/user/UserAPI').default} user
|
||||
* @property {import('./src/api/notifications/NotificationAPI').default} notifications
|
||||
* @property {import('./src/api/Editor').default} editor
|
||||
* @property {import('./src/api/overlays/OverlayAPI')} overlays
|
||||
* @property {import('./src/api/menu/MenuAPI').default} menus
|
||||
* @property {import('./src/api/actions/ActionsAPI').default} actions
|
||||
* @property {import('./src/api/status/StatusAPI').default} status
|
||||
* @property {*} priority
|
||||
* @property {import('./src/ui/router/ApplicationRouter')} router
|
||||
* @property {import('./src/api/faultmanagement/FaultManagementAPI').default} faults
|
||||
* @property {import('./src/api/forms/FormsAPI').default} forms
|
||||
* @property {import('./src/api/Branding').default} branding
|
||||
* @property {import('./src/api/annotation/AnnotationAPI').default} annotation
|
||||
* @property {{(plugin: OpenMCTPlugin) => void}} install
|
||||
* @property {{() => string}} getAssetPath
|
||||
* @property {{(domElement: HTMLElement, isHeadlessMode: boolean) => void}} start
|
||||
* @property {{() => void}} startHeadless
|
||||
* @property {{() => void}} destroy
|
||||
* @property {OpenMCTPlugin[]} plugins
|
||||
* @property {OpenMCTComponent[]} components
|
||||
*/
|
||||
|
||||
const MCT = require('./src/MCT');
|
||||
|
||||
/** @type {OpenMCT} */
|
||||
const openmct = new MCT();
|
||||
|
||||
module.exports = openmct;
|
||||
|
@ -57,6 +57,7 @@
|
||||
"sass-loader": "13.0.2",
|
||||
"sinon": "14.0.0",
|
||||
"style-loader": "^3.3.1",
|
||||
"typescript": "4.8.4",
|
||||
"uuid": "9.0.0",
|
||||
"vue": "2.6.14",
|
||||
"vue-eslint-parser": "9.1.0",
|
||||
@ -96,7 +97,7 @@
|
||||
"cov:e2e:full:publish": "codecov --disable=gcov -f ./coverage/e2e/lcov.info -F e2e-full",
|
||||
"cov:e2e:stable:publish": "codecov --disable=gcov -f ./coverage/e2e/lcov.info -F e2e-stable",
|
||||
"cov:unit:publish": "codecov --disable=gcov -f ./coverage/unit/lcov.info -F unit",
|
||||
"prepare": "npm run build:prod"
|
||||
"prepare": "npm run build:prod && npx tsc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
10
src/MCT.js
10
src/MCT.js
@ -19,7 +19,7 @@
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
/* eslint-disable no-undef */
|
||||
define([
|
||||
'EventEmitter',
|
||||
'./api/api',
|
||||
@ -81,13 +81,11 @@ define([
|
||||
/**
|
||||
* The Open MCT application. This may be configured by installing plugins
|
||||
* or registering extensions before the application is started.
|
||||
* @class MCT
|
||||
* @constructor
|
||||
* @memberof module:openmct
|
||||
* @augments {EventEmitter}
|
||||
*/
|
||||
function MCT() {
|
||||
EventEmitter.call(this);
|
||||
/* eslint-disable no-undef */
|
||||
this.buildInfo = {
|
||||
version: __OPENMCT_VERSION__,
|
||||
buildDate: __OPENMCT_BUILD_DATE__,
|
||||
@ -101,7 +99,7 @@ define([
|
||||
* Tracks current selection state of the application.
|
||||
* @private
|
||||
*/
|
||||
['selection', () => new Selection(this)],
|
||||
['selection', () => new Selection.default(this)],
|
||||
|
||||
/**
|
||||
* MCT's time conductor, which may be used to synchronize view contents
|
||||
@ -125,7 +123,7 @@ define([
|
||||
* @memberof module:openmct.MCT#
|
||||
* @name composition
|
||||
*/
|
||||
['composition', () => new api.CompositionAPI(this)],
|
||||
['composition', () => new api.CompositionAPI.default(this)],
|
||||
|
||||
/**
|
||||
* Registry for views of domain objects which should appear in the
|
||||
|
@ -23,8 +23,7 @@
|
||||
let brandingOptions = {};
|
||||
|
||||
/**
|
||||
* @typedef {Object} BrandingOptions
|
||||
* @memberOf openmct/branding
|
||||
* @typedef {object} BrandingOptions
|
||||
* @property {string} smallLogoImage URL to the image to use as the applications logo.
|
||||
* This logo will appear on every screen and when clicked will launch the about dialog.
|
||||
* @property {string} aboutHtml Custom content for the about screen. When defined the
|
||||
|
@ -37,7 +37,9 @@ define([
|
||||
'./types/TypeRegistry',
|
||||
'./user/UserAPI',
|
||||
'./annotation/AnnotationAPI'
|
||||
], function (
|
||||
],
|
||||
|
||||
function (
|
||||
ActionsAPI,
|
||||
CompositionAPI,
|
||||
EditorAPI,
|
||||
|
@ -20,34 +20,41 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
'lodash',
|
||||
'EventEmitter',
|
||||
'./DefaultCompositionProvider',
|
||||
'./CompositionCollection'
|
||||
], function (
|
||||
_,
|
||||
EventEmitter,
|
||||
DefaultCompositionProvider,
|
||||
CompositionCollection
|
||||
) {
|
||||
import DefaultCompositionProvider from './DefaultCompositionProvider';
|
||||
import CompositionCollection from './CompositionCollection';
|
||||
|
||||
/**
|
||||
* @typedef {import('./CompositionProvider').default} CompositionProvider
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('../objects/ObjectAPI').DomainObject} DomainObject
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('../../../openmct').OpenMCT} OpenMCT
|
||||
*/
|
||||
|
||||
/**
|
||||
* An interface for interacting with the composition of domain objects.
|
||||
* The composition of a domain object is the list of other domain objects
|
||||
* it "contains" (for instance, that should be displayed beneath it
|
||||
* in the tree.)
|
||||
*
|
||||
* @interface CompositionAPI
|
||||
* @returns {module:openmct.CompositionCollection}
|
||||
* @memberof module:openmct
|
||||
* @constructor
|
||||
*/
|
||||
function CompositionAPI(publicAPI) {
|
||||
export default class CompositionAPI {
|
||||
/**
|
||||
* @param {OpenMCT} publicAPI
|
||||
*/
|
||||
constructor(publicAPI) {
|
||||
/** @type {CompositionProvider[]} */
|
||||
this.registry = [];
|
||||
/** @type {CompositionPolicy[]} */
|
||||
this.policies = [];
|
||||
this.addProvider(new DefaultCompositionProvider(publicAPI, this));
|
||||
/** @type {OpenMCT} */
|
||||
this.publicAPI = publicAPI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a composition provider.
|
||||
*
|
||||
@ -55,21 +62,19 @@ define([
|
||||
* behavior for certain domain objects.
|
||||
*
|
||||
* @method addProvider
|
||||
* @param {module:openmct.CompositionProvider} provider the provider to add
|
||||
* @memberof module:openmct.CompositionAPI#
|
||||
* @param {CompositionProvider} provider the provider to add
|
||||
*/
|
||||
CompositionAPI.prototype.addProvider = function (provider) {
|
||||
addProvider(provider) {
|
||||
this.registry.unshift(provider);
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* Retrieve the composition (if any) of this domain object.
|
||||
*
|
||||
* @method get
|
||||
* @returns {module:openmct.CompositionCollection}
|
||||
* @memberof module:openmct.CompositionAPI#
|
||||
* @param {DomainObject} domainObject
|
||||
* @returns {CompositionCollection}
|
||||
*/
|
||||
CompositionAPI.prototype.get = function (domainObject) {
|
||||
get(domainObject) {
|
||||
const provider = this.registry.find(p => {
|
||||
return p.appliesTo(domainObject);
|
||||
});
|
||||
@ -79,8 +84,7 @@ define([
|
||||
}
|
||||
|
||||
return new CompositionCollection(domainObject, provider, this.publicAPI);
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* A composition policy is a function which either allows or disallows
|
||||
* placing one object in another's composition.
|
||||
@ -90,52 +94,51 @@ define([
|
||||
* generally be written to return true in the default case.
|
||||
*
|
||||
* @callback CompositionPolicy
|
||||
* @memberof module:openmct.CompositionAPI~
|
||||
* @param {module:openmct.DomainObject} containingObject the object which
|
||||
* @param {DomainObject} containingObject the object which
|
||||
* would act as a container
|
||||
* @param {module:openmct.DomainObject} containedObject the object which
|
||||
* @param {DomainObject} containedObject the object which
|
||||
* would be contained
|
||||
* @returns {boolean} false if this composition should be disallowed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add a composition policy. Composition policies may disallow domain
|
||||
* objects from containing other domain objects.
|
||||
*
|
||||
* @method addPolicy
|
||||
* @param {module:openmct.CompositionAPI~CompositionPolicy} policy
|
||||
* @param {CompositionPolicy} policy
|
||||
* the policy to add
|
||||
* @memberof module:openmct.CompositionAPI#
|
||||
*/
|
||||
CompositionAPI.prototype.addPolicy = function (policy) {
|
||||
addPolicy(policy) {
|
||||
this.policies.push(policy);
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* Check whether or not a domain object is allowed to contain another
|
||||
* domain object.
|
||||
*
|
||||
* @private
|
||||
* @method checkPolicy
|
||||
* @param {module:openmct.DomainObject} containingObject the object which
|
||||
* @param {DomainObject} container the object which
|
||||
* would act as a container
|
||||
* @param {module:openmct.DomainObject} containedObject the object which
|
||||
* @param {DomainObject} containee the object which
|
||||
* would be contained
|
||||
* @returns {boolean} false if this composition should be disallowed
|
||||
|
||||
* @param {module:openmct.CompositionAPI~CompositionPolicy} policy
|
||||
* @param {CompositionPolicy} policy
|
||||
* the policy to add
|
||||
* @memberof module:openmct.CompositionAPI#
|
||||
*/
|
||||
CompositionAPI.prototype.checkPolicy = function (container, containee) {
|
||||
checkPolicy(container, containee) {
|
||||
return this.policies.every(function (policy) {
|
||||
return policy(container, containee);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
CompositionAPI.prototype.supportsComposition = function (domainObject) {
|
||||
/**
|
||||
* Check whether or not a domainObject supports composition
|
||||
*
|
||||
* @param {DomainObject} domainObject
|
||||
* @returns {boolean} true if the domainObject supports composition
|
||||
*/
|
||||
supportsComposition(domainObject) {
|
||||
return this.get(domainObject) !== undefined;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return CompositionAPI;
|
||||
});
|
||||
|
@ -1,10 +1,5 @@
|
||||
define([
|
||||
'./CompositionAPI',
|
||||
'./CompositionCollection'
|
||||
], function (
|
||||
CompositionAPI,
|
||||
CompositionCollection
|
||||
) {
|
||||
import CompositionAPI from './CompositionAPI';
|
||||
import CompositionCollection from './CompositionCollection';
|
||||
|
||||
describe('The Composition API', function () {
|
||||
let publicAPI;
|
||||
@ -322,4 +317,3 @@ define([
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -20,11 +20,26 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
'lodash'
|
||||
], function (
|
||||
_
|
||||
) {
|
||||
/**
|
||||
* @typedef {import('../objects/ObjectAPI').DomainObject} DomainObject
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('./CompositionAPI').default} CompositionAPI
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('../../../openmct').OpenMCT} OpenMCT
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} ListenerMap
|
||||
* @property {Array.<any>} add
|
||||
* @property {Array.<any>} remove
|
||||
* @property {Array.<any>} load
|
||||
* @property {Array.<any>} reorder
|
||||
*/
|
||||
|
||||
/**
|
||||
* A CompositionCollection represents the list of domain objects contained
|
||||
* by another domain object. It provides methods for loading this
|
||||
@ -38,57 +53,65 @@ define([
|
||||
* myViewComposition.on('remove', removeObjectFromView);
|
||||
* myViewComposition.load(); // will trigger `add` for all loaded objects.
|
||||
* ```
|
||||
*
|
||||
* @interface CompositionCollection
|
||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
||||
* whose composition will be contained
|
||||
* @param {module:openmct.CompositionProvider} provider the provider
|
||||
* to use to retrieve other domain objects
|
||||
* @param {module:openmct.CompositionAPI} api the composition API, for
|
||||
* policy checks
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
function CompositionCollection(domainObject, provider, publicAPI) {
|
||||
export default class CompositionCollection {
|
||||
domainObject;
|
||||
#provider;
|
||||
#publicAPI;
|
||||
#listeners;
|
||||
#mutables;
|
||||
/**
|
||||
* @constructor
|
||||
* @param {DomainObject} domainObject the domain object
|
||||
* whose composition will be contained
|
||||
* @param {import('./CompositionProvider').default} provider the provider
|
||||
* to use to retrieve other domain objects
|
||||
* @param {OpenMCT} publicAPI the composition API, for
|
||||
* policy checks
|
||||
*/
|
||||
constructor(domainObject, provider, publicAPI) {
|
||||
this.domainObject = domainObject;
|
||||
this.provider = provider;
|
||||
this.publicAPI = publicAPI;
|
||||
this.listeners = {
|
||||
/** @type {import('./CompositionProvider').default} */
|
||||
this.#provider = provider;
|
||||
/** @type {OpenMCT} */
|
||||
this.#publicAPI = publicAPI;
|
||||
/** @type {ListenerMap} */
|
||||
this.#listeners = {
|
||||
add: [],
|
||||
remove: [],
|
||||
load: [],
|
||||
reorder: []
|
||||
};
|
||||
this.onProviderAdd = this.onProviderAdd.bind(this);
|
||||
this.onProviderRemove = this.onProviderRemove.bind(this);
|
||||
this.mutables = {};
|
||||
this.onProviderAdd = this.#onProviderAdd.bind(this);
|
||||
this.onProviderRemove = this.#onProviderRemove.bind(this);
|
||||
this.#mutables = {};
|
||||
|
||||
if (this.domainObject.isMutable) {
|
||||
this.returnMutables = true;
|
||||
let unobserve = this.domainObject.$on('$_destroy', () => {
|
||||
Object.values(this.mutables).forEach(mutable => {
|
||||
this.publicAPI.objects.destroyMutable(mutable);
|
||||
Object.values(this.#mutables).forEach(mutable => {
|
||||
this.#publicAPI.objects.destroyMutable(mutable);
|
||||
});
|
||||
unobserve();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for changes to this composition. Supports 'add', 'remove', and
|
||||
* 'load' events.
|
||||
*
|
||||
* @param event event to listen for, either 'add', 'remove' or 'load'.
|
||||
* @param callback to trigger when event occurs.
|
||||
* @param [context] context to use when invoking callback, optional.
|
||||
* @param {string} event event to listen for, either 'add', 'remove' or 'load'.
|
||||
* @param {(...args: any[]) => void} callback to trigger when event occurs.
|
||||
* @param {any} [context] to use when invoking callback, optional.
|
||||
*/
|
||||
CompositionCollection.prototype.on = function (event, callback, context) {
|
||||
if (!this.listeners[event]) {
|
||||
on(event, callback, context) {
|
||||
if (!this.#listeners[event]) {
|
||||
throw new Error('Event not supported by composition: ' + event);
|
||||
}
|
||||
|
||||
if (this.provider.on && this.provider.off) {
|
||||
if (this.#provider.on && this.#provider.off) {
|
||||
if (event === 'add') {
|
||||
this.provider.on(
|
||||
this.#provider.on(
|
||||
this.domainObject,
|
||||
'add',
|
||||
this.onProviderAdd,
|
||||
@ -97,7 +120,7 @@ define([
|
||||
}
|
||||
|
||||
if (event === 'remove') {
|
||||
this.provider.on(
|
||||
this.#provider.on(
|
||||
this.domainObject,
|
||||
'remove',
|
||||
this.onProviderRemove,
|
||||
@ -106,36 +129,34 @@ define([
|
||||
}
|
||||
|
||||
if (event === 'reorder') {
|
||||
this.provider.on(
|
||||
this.#provider.on(
|
||||
this.domainObject,
|
||||
'reorder',
|
||||
this.onProviderReorder,
|
||||
this.#onProviderReorder,
|
||||
this
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this.listeners[event].push({
|
||||
this.#listeners[event].push({
|
||||
callback: callback,
|
||||
context: context
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* Remove a listener. Must be called with same exact parameters as
|
||||
* `off`.
|
||||
*
|
||||
* @param event
|
||||
* @param callback
|
||||
* @param [context]
|
||||
* @param {string} event
|
||||
* @param {(...args: any[]) => void} callback
|
||||
* @param {any} [context]
|
||||
*/
|
||||
|
||||
CompositionCollection.prototype.off = function (event, callback, context) {
|
||||
if (!this.listeners[event]) {
|
||||
off(event, callback, context) {
|
||||
if (!this.#listeners[event]) {
|
||||
throw new Error('Event not supported by composition: ' + event);
|
||||
}
|
||||
|
||||
const index = this.listeners[event].findIndex(l => {
|
||||
const index = this.#listeners[event].findIndex(l => {
|
||||
return l.callback === callback && l.context === context;
|
||||
});
|
||||
|
||||
@ -143,125 +164,116 @@ define([
|
||||
throw new Error('Tried to remove a listener that does not exist');
|
||||
}
|
||||
|
||||
this.listeners[event].splice(index, 1);
|
||||
if (this.listeners[event].length === 0) {
|
||||
this.#listeners[event].splice(index, 1);
|
||||
if (this.#listeners[event].length === 0) {
|
||||
this._destroy();
|
||||
|
||||
// Remove provider listener if this is the last callback to
|
||||
// be removed.
|
||||
if (this.provider.off && this.provider.on) {
|
||||
if (this.#provider.off && this.#provider.on) {
|
||||
if (event === 'add') {
|
||||
this.provider.off(
|
||||
this.#provider.off(
|
||||
this.domainObject,
|
||||
'add',
|
||||
this.onProviderAdd,
|
||||
this
|
||||
);
|
||||
} else if (event === 'remove') {
|
||||
this.provider.off(
|
||||
this.#provider.off(
|
||||
this.domainObject,
|
||||
'remove',
|
||||
this.onProviderRemove,
|
||||
this
|
||||
);
|
||||
} else if (event === 'reorder') {
|
||||
this.provider.off(
|
||||
this.#provider.off(
|
||||
this.domainObject,
|
||||
'reorder',
|
||||
this.onProviderReorder,
|
||||
this.#onProviderReorder,
|
||||
this
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* Add a domain object to this composition.
|
||||
*
|
||||
* A call to [load]{@link module:openmct.CompositionCollection#load}
|
||||
* must have resolved before using this method.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} child the domain object to add
|
||||
* @param {boolean} skipMutate true if the underlying provider should
|
||||
* not be updated
|
||||
* @memberof module:openmct.CompositionCollection#
|
||||
* @name add
|
||||
* **TODO:** Remove `skipMutate` parameter.
|
||||
*
|
||||
* @param {DomainObject} child the domain object to add
|
||||
* @param {boolean} skipMutate
|
||||
* **Intended for internal use ONLY.**
|
||||
* true if the underlying provider should not be updated.
|
||||
*/
|
||||
CompositionCollection.prototype.add = function (child, skipMutate) {
|
||||
add(child, skipMutate) {
|
||||
if (!skipMutate) {
|
||||
if (!this.publicAPI.composition.checkPolicy(this.domainObject, child)) {
|
||||
if (!this.#publicAPI.composition.checkPolicy(this.domainObject, child)) {
|
||||
throw `Object of type ${child.type} cannot be added to object of type ${this.domainObject.type}`;
|
||||
}
|
||||
|
||||
this.provider.add(this.domainObject, child.identifier);
|
||||
this.#provider.add(this.domainObject, child.identifier);
|
||||
} else {
|
||||
if (this.returnMutables && this.publicAPI.objects.supportsMutation(child.identifier)) {
|
||||
let keyString = this.publicAPI.objects.makeKeyString(child.identifier);
|
||||
if (this.returnMutables && this.#publicAPI.objects.supportsMutation(child.identifier)) {
|
||||
let keyString = this.#publicAPI.objects.makeKeyString(child.identifier);
|
||||
|
||||
child = this.publicAPI.objects.toMutable(child);
|
||||
this.mutables[keyString] = child;
|
||||
child = this.#publicAPI.objects.toMutable(child);
|
||||
this.#mutables[keyString] = child;
|
||||
}
|
||||
|
||||
this.emit('add', child);
|
||||
this.#emit('add', child);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Load the domain objects in this composition.
|
||||
*
|
||||
* @returns {Promise.<Array.<module:openmct.DomainObject>>} a promise for
|
||||
* @param {AbortSignal} abortSignal
|
||||
* @returns {Promise.<Array.<DomainObject>>} a promise for
|
||||
* the domain objects in this composition
|
||||
* @memberof {module:openmct.CompositionCollection#}
|
||||
* @name load
|
||||
*/
|
||||
CompositionCollection.prototype.load = function (abortSignal) {
|
||||
this.cleanUpMutables();
|
||||
|
||||
return this.provider.load(this.domainObject)
|
||||
.then(function (children) {
|
||||
return Promise.all(children.map((c) => this.publicAPI.objects.get(c, abortSignal)));
|
||||
}.bind(this))
|
||||
.then(function (childObjects) {
|
||||
async load(abortSignal) {
|
||||
this.#cleanUpMutables();
|
||||
const children = await this.#provider.load(this.domainObject);
|
||||
const childObjects = await Promise.all(children.map((c) => this.#publicAPI.objects.get(c, abortSignal)));
|
||||
childObjects.forEach(c => this.add(c, true));
|
||||
this.#emit('load');
|
||||
|
||||
return childObjects;
|
||||
}.bind(this))
|
||||
.then(function (children) {
|
||||
this.emit('load');
|
||||
|
||||
return children;
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* Remove a domain object from this composition.
|
||||
*
|
||||
* A call to [load]{@link module:openmct.CompositionCollection#load}
|
||||
* must have resolved before using this method.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} child the domain object to remove
|
||||
* @param {boolean} skipMutate true if the underlying provider should
|
||||
* not be updated
|
||||
* @memberof module:openmct.CompositionCollection#
|
||||
* **TODO:** Remove `skipMutate` parameter.
|
||||
*
|
||||
* @param {DomainObject} child the domain object to remove
|
||||
* @param {boolean} skipMutate
|
||||
* **Intended for internal use ONLY.**
|
||||
* true if the underlying provider should not be updated.
|
||||
* @name remove
|
||||
*/
|
||||
CompositionCollection.prototype.remove = function (child, skipMutate) {
|
||||
remove(child, skipMutate) {
|
||||
if (!skipMutate) {
|
||||
this.provider.remove(this.domainObject, child.identifier);
|
||||
this.#provider.remove(this.domainObject, child.identifier);
|
||||
} else {
|
||||
if (this.returnMutables) {
|
||||
let keyString = this.publicAPI.objects.makeKeyString(child);
|
||||
if (this.mutables[keyString] !== undefined && this.mutables[keyString].isMutable) {
|
||||
this.publicAPI.objects.destroyMutable(this.mutables[keyString]);
|
||||
delete this.mutables[keyString];
|
||||
let keyString = this.#publicAPI.objects.makeKeyString(child);
|
||||
if (this.#mutables[keyString] !== undefined && this.#mutables[keyString].isMutable) {
|
||||
this.#publicAPI.objects.destroyMutable(this.#mutables[keyString]);
|
||||
delete this.#mutables[keyString];
|
||||
}
|
||||
}
|
||||
|
||||
this.emit('remove', child);
|
||||
this.#emit('remove', child);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Reorder the domain objects in this composition.
|
||||
*
|
||||
@ -270,67 +282,75 @@ define([
|
||||
*
|
||||
* @param {number} oldIndex
|
||||
* @param {number} newIndex
|
||||
* @memberof module:openmct.CompositionCollection#
|
||||
* @name remove
|
||||
*/
|
||||
CompositionCollection.prototype.reorder = function (oldIndex, newIndex, skipMutate) {
|
||||
this.provider.reorder(this.domainObject, oldIndex, newIndex);
|
||||
};
|
||||
|
||||
reorder(oldIndex, newIndex, _skipMutate) {
|
||||
this.#provider.reorder(this.domainObject, oldIndex, newIndex);
|
||||
}
|
||||
/**
|
||||
* Handle reorder from provider.
|
||||
* @private
|
||||
* Destroy mutationListener
|
||||
*/
|
||||
CompositionCollection.prototype.onProviderReorder = function (reorderMap) {
|
||||
this.emit('reorder', reorderMap);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle adds from provider.
|
||||
* @private
|
||||
*/
|
||||
CompositionCollection.prototype.onProviderAdd = function (childId) {
|
||||
return this.publicAPI.objects.get(childId).then(function (child) {
|
||||
this.add(child, true);
|
||||
|
||||
return child;
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle removal from provider.
|
||||
* @private
|
||||
*/
|
||||
CompositionCollection.prototype.onProviderRemove = function (child) {
|
||||
this.remove(child, true);
|
||||
};
|
||||
|
||||
CompositionCollection.prototype._destroy = function () {
|
||||
_destroy() {
|
||||
if (this.mutationListener) {
|
||||
this.mutationListener();
|
||||
delete this.mutationListener;
|
||||
}
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Handle reorder from provider.
|
||||
* @private
|
||||
* @param {object} reorderMap
|
||||
*/
|
||||
#onProviderReorder(reorderMap) {
|
||||
this.#emit('reorder', reorderMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle adds from provider.
|
||||
* @private
|
||||
* @param {import('../objects/ObjectAPI').Identifier} childId
|
||||
* @returns {DomainObject}
|
||||
*/
|
||||
#onProviderAdd(childId) {
|
||||
return this.#publicAPI.objects.get(childId).then(function (child) {
|
||||
this.add(child, true);
|
||||
|
||||
return child;
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle removal from provider.
|
||||
* @param {DomainObject} child
|
||||
*/
|
||||
#onProviderRemove(child) {
|
||||
this.remove(child, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit events.
|
||||
*
|
||||
* @private
|
||||
* @param {string} event
|
||||
* @param {...args.<any>} payload
|
||||
*/
|
||||
CompositionCollection.prototype.emit = function (event, ...payload) {
|
||||
this.listeners[event].forEach(function (l) {
|
||||
#emit(event, ...payload) {
|
||||
this.#listeners[event].forEach(function (l) {
|
||||
if (l.context) {
|
||||
l.callback.apply(l.context, payload);
|
||||
} else {
|
||||
l.callback(...payload);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
CompositionCollection.prototype.cleanUpMutables = function () {
|
||||
Object.values(this.mutables).forEach(mutable => {
|
||||
this.publicAPI.objects.destroyMutable(mutable);
|
||||
});
|
||||
};
|
||||
|
||||
return CompositionCollection;
|
||||
/**
|
||||
* Destroy all mutables.
|
||||
* @private
|
||||
*/
|
||||
#cleanUpMutables() {
|
||||
Object.values(this.#mutables).forEach(mutable => {
|
||||
this.#publicAPI.objects.destroyMutable(mutable);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
262
src/api/composition/CompositionProvider.js
Normal file
262
src/api/composition/CompositionProvider.js
Normal file
@ -0,0 +1,262 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT, Copyright (c) 2014-2022, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT includes source code licensed under additional open source
|
||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
import _ from 'lodash';
|
||||
import objectUtils from "../objects/object-utils";
|
||||
|
||||
/**
|
||||
* @typedef {import('../objects/ObjectAPI').DomainObject} DomainObject
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('../objects/ObjectAPI').Identifier} Identifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('./CompositionAPI').default} CompositionAPI
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('../../../openmct').OpenMCT} OpenMCT
|
||||
*/
|
||||
|
||||
/**
|
||||
* A CompositionProvider provides the underlying implementation of
|
||||
* composition-related behavior for certain types of domain object.
|
||||
*
|
||||
* By default, a composition provider will not support composition
|
||||
* modification. You can add support for mutation of composition by
|
||||
* defining `add` and/or `remove` methods.
|
||||
*
|
||||
* If the composition of an object can change over time-- perhaps via
|
||||
* server updates or mutation via the add/remove methods, then one must
|
||||
* trigger events as necessary.
|
||||
*
|
||||
*/
|
||||
export default class CompositionProvider {
|
||||
#publicAPI;
|
||||
#listeningTo;
|
||||
|
||||
/**
|
||||
* @param {OpenMCT} publicAPI
|
||||
* @param {CompositionAPI} compositionAPI
|
||||
*/
|
||||
constructor(publicAPI, compositionAPI) {
|
||||
this.#publicAPI = publicAPI;
|
||||
this.#listeningTo = {};
|
||||
|
||||
compositionAPI.addPolicy(this.#cannotContainItself.bind(this));
|
||||
compositionAPI.addPolicy(this.#supportsComposition.bind(this));
|
||||
}
|
||||
|
||||
get listeningTo() {
|
||||
return this.#listeningTo;
|
||||
}
|
||||
|
||||
get establishTopicListener() {
|
||||
return this.#establishTopicListener.bind(this);
|
||||
}
|
||||
|
||||
get publicAPI() {
|
||||
return this.#publicAPI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this provider should be used to load composition for a
|
||||
* particular domain object.
|
||||
* @method appliesTo
|
||||
* @param {import('../objects/ObjectAPI').DomainObject} domainObject the domain object
|
||||
* to check
|
||||
* @returns {boolean} true if this provider can provide composition for a given domain object
|
||||
*/
|
||||
appliesTo(domainObject) {
|
||||
throw new Error("This method must be implemented by a subclass.");
|
||||
}
|
||||
/**
|
||||
* Load any domain objects contained in the composition of this domain
|
||||
* object.
|
||||
* @param {DomainObject} domainObject the domain object
|
||||
* for which to load composition
|
||||
* @returns {Promise<Identifier[]>} a promise for
|
||||
* the Identifiers in this composition
|
||||
* @method load
|
||||
*/
|
||||
load(domainObject) {
|
||||
throw new Error("This method must be implemented by a subclass.");
|
||||
}
|
||||
/**
|
||||
* Attach listeners for changes to the composition of a given domain object.
|
||||
* Supports `add` and `remove` events.
|
||||
*
|
||||
* @param {DomainObject} domainObject to listen to
|
||||
* @param {string} event the event to bind to, either `add` or `remove`.
|
||||
* @param {Function} callback callback to invoke when event is triggered.
|
||||
* @param {any} [context] to use when invoking callback.
|
||||
*/
|
||||
on(domainObject,
|
||||
event,
|
||||
callback,
|
||||
context) {
|
||||
throw new Error("This method must be implemented by a subclass.");
|
||||
}
|
||||
/**
|
||||
* Remove a listener that was previously added for a given domain object.
|
||||
* event name, callback, and context must be the same as when the listener
|
||||
* was originally attached.
|
||||
*
|
||||
* @param {DomainObject} domainObject to remove listener for
|
||||
* @param {string} event event to stop listening to: `add` or `remove`.
|
||||
* @param {Function} callback callback to remove.
|
||||
* @param {any} context of callback to remove.
|
||||
*/
|
||||
off(domainObject,
|
||||
event,
|
||||
callback,
|
||||
context) {
|
||||
throw new Error("This method must be implemented by a subclass.");
|
||||
}
|
||||
/**
|
||||
* Remove a domain object from another domain object's composition.
|
||||
*
|
||||
* This method is optional; if not present, adding to a domain object's
|
||||
* composition using this provider will be disallowed.
|
||||
*
|
||||
* @param {DomainObject} domainObject the domain object
|
||||
* which should have its composition modified
|
||||
* @param {Identifier} childId the domain object to remove
|
||||
* @method remove
|
||||
*/
|
||||
remove(domainObject, childId) {
|
||||
throw new Error("This method must be implemented by a subclass.");
|
||||
}
|
||||
/**
|
||||
* Add a domain object to another domain object's composition.
|
||||
*
|
||||
* This method is optional; if not present, adding to a domain object's
|
||||
* composition using this provider will be disallowed.
|
||||
*
|
||||
* @param {DomainObject} parent the domain object
|
||||
* which should have its composition modified
|
||||
* @param {Identifier} childId the domain object to add
|
||||
* @method add
|
||||
*/
|
||||
add(parent, childId) {
|
||||
throw new Error("This method must be implemented by a subclass.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {DomainObject} parent
|
||||
* @param {Identifier} childId
|
||||
* @returns {boolean}
|
||||
*/
|
||||
includes(parent, childId) {
|
||||
throw new Error("This method must be implemented by a subclass.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {DomainObject} domainObject
|
||||
* @param {number} oldIndex
|
||||
* @param {number} newIndex
|
||||
* @returns
|
||||
*/
|
||||
reorder(domainObject, oldIndex, newIndex) {
|
||||
throw new Error("This method must be implemented by a subclass.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens on general mutation topic, using injector to fetch to avoid
|
||||
* circular dependencies.
|
||||
* @private
|
||||
*/
|
||||
#establishTopicListener() {
|
||||
if (this.topicListener) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.#publicAPI.objects.eventEmitter.on('mutation', this.#onMutation.bind(this));
|
||||
this.topicListener = () => {
|
||||
this.#publicAPI.objects.eventEmitter.off('mutation', this.#onMutation.bind(this));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {DomainObject} parent
|
||||
* @param {DomainObject} child
|
||||
* @returns {boolean}
|
||||
*/
|
||||
#cannotContainItself(parent, child) {
|
||||
return !(parent.identifier.namespace === child.identifier.namespace
|
||||
&& parent.identifier.key === child.identifier.key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {DomainObject} parent
|
||||
* @returns {boolean}
|
||||
*/
|
||||
#supportsComposition(parent, _child) {
|
||||
return this.#publicAPI.composition.supportsComposition(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles mutation events. If there are active listeners for the mutated
|
||||
* object, detects changes to composition and triggers necessary events.
|
||||
*
|
||||
* @private
|
||||
* @param {DomainObject} oldDomainObject
|
||||
*/
|
||||
#onMutation(oldDomainObject) {
|
||||
const id = objectUtils.makeKeyString(oldDomainObject.identifier);
|
||||
const listeners = this.#listeningTo[id];
|
||||
|
||||
if (!listeners) {
|
||||
return;
|
||||
}
|
||||
|
||||
const oldComposition = listeners.composition.map(objectUtils.makeKeyString);
|
||||
const newComposition = oldDomainObject.composition.map(objectUtils.makeKeyString);
|
||||
|
||||
const added = _.difference(newComposition, oldComposition).map(objectUtils.parseKeyString);
|
||||
const removed = _.difference(oldComposition, newComposition).map(objectUtils.parseKeyString);
|
||||
|
||||
function notify(value) {
|
||||
return function (listener) {
|
||||
if (listener.context) {
|
||||
listener.callback.call(listener.context, value);
|
||||
} else {
|
||||
listener.callback(value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
listeners.composition = newComposition.map(objectUtils.parseKeyString);
|
||||
|
||||
added.forEach(function (addedChild) {
|
||||
listeners.add.forEach(notify(addedChild));
|
||||
});
|
||||
|
||||
removed.forEach(function (removedChild) {
|
||||
listeners.remove.forEach(notify(removedChild));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -19,14 +19,25 @@
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
import objectUtils from "../objects/object-utils";
|
||||
import CompositionProvider from './CompositionProvider';
|
||||
|
||||
/**
|
||||
* @typedef {import('../objects/ObjectAPI').DomainObject} DomainObject
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('../objects/ObjectAPI').Identifier} Identifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('./CompositionAPI').default} CompositionAPI
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('../../../openmct').OpenMCT} OpenMCT
|
||||
*/
|
||||
|
||||
define([
|
||||
'lodash',
|
||||
'objectUtils'
|
||||
], function (
|
||||
_,
|
||||
objectUtils
|
||||
) {
|
||||
/**
|
||||
* A CompositionProvider provides the underlying implementation of
|
||||
* composition-related behavior for certain types of domain object.
|
||||
@ -38,83 +49,49 @@ define([
|
||||
* If the composition of an object can change over time-- perhaps via
|
||||
* server updates or mutation via the add/remove methods, then one must
|
||||
* trigger events as necessary.
|
||||
*
|
||||
* @interface CompositionProvider
|
||||
* @memberof module:openmct
|
||||
* @extends CompositionProvider
|
||||
*/
|
||||
|
||||
function DefaultCompositionProvider(publicAPI, compositionAPI) {
|
||||
this.publicAPI = publicAPI;
|
||||
this.listeningTo = {};
|
||||
this.onMutation = this.onMutation.bind(this);
|
||||
|
||||
this.cannotContainItself = this.cannotContainItself.bind(this);
|
||||
this.supportsComposition = this.supportsComposition.bind(this);
|
||||
|
||||
compositionAPI.addPolicy(this.cannotContainItself);
|
||||
compositionAPI.addPolicy(this.supportsComposition);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.cannotContainItself = function (parent, child) {
|
||||
return !(parent.identifier.namespace === child.identifier.namespace
|
||||
&& parent.identifier.key === child.identifier.key);
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.supportsComposition = function (parent, child) {
|
||||
return this.publicAPI.composition.supportsComposition(parent);
|
||||
};
|
||||
|
||||
export default class DefaultCompositionProvider extends CompositionProvider {
|
||||
/**
|
||||
* Check if this provider should be used to load composition for a
|
||||
* particular domain object.
|
||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
||||
* @override
|
||||
* @param {DomainObject} domainObject the domain object
|
||||
* to check
|
||||
* @returns {boolean} true if this provider can provide
|
||||
* composition for a given domain object
|
||||
* @memberof module:openmct.CompositionProvider#
|
||||
* @method appliesTo
|
||||
* @returns {boolean} true if this provider can provide composition for a given domain object
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.appliesTo = function (domainObject) {
|
||||
appliesTo(domainObject) {
|
||||
return Boolean(domainObject.composition);
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* Load any domain objects contained in the composition of this domain
|
||||
* object.
|
||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
||||
* @override
|
||||
* @param {DomainObject} domainObject the domain object
|
||||
* for which to load composition
|
||||
* @returns {Promise.<Array.<module:openmct.Identifier>>} a promise for
|
||||
* @returns {Promise<Identifier[]>} a promise for
|
||||
* the Identifiers in this composition
|
||||
* @memberof module:openmct.CompositionProvider#
|
||||
* @method load
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.load = function (domainObject) {
|
||||
load(domainObject) {
|
||||
return Promise.all(domainObject.composition);
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* Attach listeners for changes to the composition of a given domain object.
|
||||
* Supports `add` and `remove` events.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} domainObject to listen to
|
||||
* @param String event the event to bind to, either `add` or `remove`.
|
||||
* @param Function callback callback to invoke when event is triggered.
|
||||
* @param [context] context to use when invoking callback.
|
||||
* @override
|
||||
* @param {DomainObject} domainObject to listen to
|
||||
* @param {string} event the event to bind to, either `add` or `remove`.
|
||||
* @param {Function} callback callback to invoke when event is triggered.
|
||||
* @param {any} [context] to use when invoking callback.
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.on = function (
|
||||
domainObject,
|
||||
on(domainObject,
|
||||
event,
|
||||
callback,
|
||||
context
|
||||
) {
|
||||
context) {
|
||||
this.establishTopicListener();
|
||||
|
||||
/** @type {string} */
|
||||
const keyString = objectUtils.makeKeyString(domainObject.identifier);
|
||||
let objectListeners = this.listeningTo[keyString];
|
||||
|
||||
@ -131,24 +108,24 @@ define([
|
||||
callback: callback,
|
||||
context: context
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* Remove a listener that was previously added for a given domain object.
|
||||
* event name, callback, and context must be the same as when the listener
|
||||
* was originally attached.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} domainObject to remove listener for
|
||||
* @param String event event to stop listening to: `add` or `remove`.
|
||||
* @param Function callback callback to remove.
|
||||
* @param [context] context of callback to remove.
|
||||
* @override
|
||||
* @param {DomainObject} domainObject to remove listener for
|
||||
* @param {string} event event to stop listening to: `add` or `remove`.
|
||||
* @param {Function} callback callback to remove.
|
||||
* @param {any} context of callback to remove.
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.off = function (
|
||||
domainObject,
|
||||
off(domainObject,
|
||||
event,
|
||||
callback,
|
||||
context
|
||||
) {
|
||||
context) {
|
||||
|
||||
/** @type {string} */
|
||||
const keyString = objectUtils.makeKeyString(domainObject.identifier);
|
||||
const objectListeners = this.listeningTo[keyString];
|
||||
|
||||
@ -160,57 +137,64 @@ define([
|
||||
if (!objectListeners.add.length && !objectListeners.remove.length && !objectListeners.reorder.length) {
|
||||
delete this.listeningTo[keyString];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* Remove a domain object from another domain object's composition.
|
||||
*
|
||||
* This method is optional; if not present, adding to a domain object's
|
||||
* composition using this provider will be disallowed.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
||||
* @override
|
||||
* @param {DomainObject} domainObject the domain object
|
||||
* which should have its composition modified
|
||||
* @param {module:openmct.DomainObject} child the domain object to remove
|
||||
* @memberof module:openmct.CompositionProvider#
|
||||
* @param {Identifier} childId the domain object to remove
|
||||
* @method remove
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.remove = function (domainObject, childId) {
|
||||
remove(domainObject, childId) {
|
||||
let composition = domainObject.composition.filter(function (child) {
|
||||
return !(childId.namespace === child.namespace
|
||||
&& childId.key === child.key);
|
||||
});
|
||||
|
||||
this.publicAPI.objects.mutate(domainObject, 'composition', composition);
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* Add a domain object to another domain object's composition.
|
||||
*
|
||||
* This method is optional; if not present, adding to a domain object's
|
||||
* composition using this provider will be disallowed.
|
||||
*
|
||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
||||
* @override
|
||||
* @param {DomainObject} parent the domain object
|
||||
* which should have its composition modified
|
||||
* @param {module:openmct.DomainObject} child the domain object to add
|
||||
* @memberof module:openmct.CompositionProvider#
|
||||
* @param {Identifier} childId the domain object to add
|
||||
* @method add
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.add = function (parent, childId) {
|
||||
add(parent, childId) {
|
||||
if (!this.includes(parent, childId)) {
|
||||
parent.composition.push(childId);
|
||||
this.publicAPI.objects.mutate(parent, 'composition', parent.composition);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @override
|
||||
* @param {DomainObject} parent
|
||||
* @param {Identifier} childId
|
||||
* @returns {boolean}
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.includes = function (parent, childId) {
|
||||
return parent.composition.some(composee =>
|
||||
this.publicAPI.objects.areIdsEqual(composee, childId));
|
||||
};
|
||||
includes(parent, childId) {
|
||||
return parent.composition.some(composee => this.publicAPI.objects.areIdsEqual(composee, childId));
|
||||
}
|
||||
|
||||
DefaultCompositionProvider.prototype.reorder = function (domainObject, oldIndex, newIndex) {
|
||||
/**
|
||||
* @override
|
||||
* @param {DomainObject} domainObject
|
||||
* @param {number} oldIndex
|
||||
* @param {number} newIndex
|
||||
* @returns
|
||||
*/
|
||||
reorder(domainObject, oldIndex, newIndex) {
|
||||
let newComposition = domainObject.composition.slice();
|
||||
let removeId = oldIndex > newIndex ? oldIndex + 1 : oldIndex;
|
||||
let insertPosition = oldIndex < newIndex ? newIndex + 1 : newIndex;
|
||||
@ -241,6 +225,7 @@ define([
|
||||
|
||||
this.publicAPI.objects.mutate(domainObject, 'composition', newComposition);
|
||||
|
||||
/** @type {string} */
|
||||
let id = objectUtils.makeKeyString(domainObject.identifier);
|
||||
const listeners = this.listeningTo[id];
|
||||
|
||||
@ -257,66 +242,5 @@ define([
|
||||
listener.callback(reorderPlan);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Listens on general mutation topic, using injector to fetch to avoid
|
||||
* circular dependencies.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.establishTopicListener = function () {
|
||||
if (this.topicListener) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.publicAPI.objects.eventEmitter.on('mutation', this.onMutation);
|
||||
this.topicListener = () => {
|
||||
this.publicAPI.objects.eventEmitter.off('mutation', this.onMutation);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles mutation events. If there are active listeners for the mutated
|
||||
* object, detects changes to composition and triggers necessary events.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
DefaultCompositionProvider.prototype.onMutation = function (oldDomainObject) {
|
||||
const id = objectUtils.makeKeyString(oldDomainObject.identifier);
|
||||
const listeners = this.listeningTo[id];
|
||||
|
||||
if (!listeners) {
|
||||
return;
|
||||
}
|
||||
|
||||
const oldComposition = listeners.composition.map(objectUtils.makeKeyString);
|
||||
const newComposition = oldDomainObject.composition.map(objectUtils.makeKeyString);
|
||||
|
||||
const added = _.difference(newComposition, oldComposition).map(objectUtils.parseKeyString);
|
||||
const removed = _.difference(oldComposition, newComposition).map(objectUtils.parseKeyString);
|
||||
|
||||
function notify(value) {
|
||||
return function (listener) {
|
||||
if (listener.context) {
|
||||
listener.callback.call(listener.context, value);
|
||||
} else {
|
||||
listener.callback(value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
listeners.composition = newComposition.map(objectUtils.parseKeyString);
|
||||
|
||||
added.forEach(function (addedChild) {
|
||||
listeners.add.forEach(notify(addedChild));
|
||||
});
|
||||
|
||||
removed.forEach(function (removedChild) {
|
||||
listeners.remove.forEach(notify(removedChild));
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
return DefaultCompositionProvider;
|
||||
});
|
||||
|
@ -33,7 +33,7 @@ import InMemorySearchProvider from './InMemorySearchProvider';
|
||||
/**
|
||||
* Uniquely identifies a domain object.
|
||||
*
|
||||
* @typedef Identifier
|
||||
* @typedef {object} Identifier
|
||||
* @property {string} namespace the namespace to/from which this domain
|
||||
* object should be loaded/stored.
|
||||
* @property {string} key a unique identifier for the domain object
|
||||
@ -50,8 +50,8 @@ import InMemorySearchProvider from './InMemorySearchProvider';
|
||||
* A few common properties are defined for domain objects. Beyond these,
|
||||
* individual types of domain objects may add more as they see fit.
|
||||
*
|
||||
* @typedef DomainObject
|
||||
* @property {module:openmct.ObjectAPI~Identifier} identifier a key/namespace pair which
|
||||
* @typedef {object} DomainObject
|
||||
* @property {Identifier} identifier a key/namespace pair which
|
||||
* uniquely identifies this domain object
|
||||
* @property {string} type the type of domain object
|
||||
* @property {string} name the human-readable name for this domain object
|
||||
@ -59,18 +59,18 @@ import InMemorySearchProvider from './InMemorySearchProvider';
|
||||
* object
|
||||
* @property {number} [modified] the time, in milliseconds since the UNIX
|
||||
* epoch, at which this domain object was last modified
|
||||
* @property {module:openmct.ObjectAPI~Identifier[]} [composition] if
|
||||
* @property {Identifier[]} [composition] if
|
||||
* present, this will be used by the default composition provider
|
||||
* to load domain objects
|
||||
* @memberof module:openmct
|
||||
* @memberof module:openmct.ObjectAPI~
|
||||
*/
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @enum {String} SEARCH_TYPES
|
||||
* @property {String} OBJECTS Search for objects
|
||||
* @property {String} ANNOTATIONS Search for annotations
|
||||
* @property {String} TAGS Search for tags
|
||||
* @enum {string} SEARCH_TYPES
|
||||
* @property {string} OBJECTS Search for objects
|
||||
* @property {string} ANNOTATIONS Search for annotations
|
||||
* @property {string} TAGS Search for tags
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -20,36 +20,27 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
[
|
||||
'EventEmitter',
|
||||
'lodash'
|
||||
],
|
||||
function (
|
||||
EventEmitter,
|
||||
_
|
||||
) {
|
||||
import EventEmitter from 'EventEmitter';
|
||||
import _ from 'lodash';
|
||||
|
||||
/**
|
||||
* Manages selection state for Open MCT
|
||||
* @private
|
||||
*/
|
||||
function Selection(openmct) {
|
||||
EventEmitter.call(this);
|
||||
export default class Selection extends EventEmitter {
|
||||
constructor(openmct) {
|
||||
super();
|
||||
|
||||
this.openmct = openmct;
|
||||
this.selected = [];
|
||||
}
|
||||
|
||||
Selection.prototype = Object.create(EventEmitter.prototype);
|
||||
|
||||
/**
|
||||
* Gets the selected object.
|
||||
* @public
|
||||
*/
|
||||
Selection.prototype.get = function () {
|
||||
get() {
|
||||
return this.selected;
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* Selects the selectable object and emits the 'change' event.
|
||||
*
|
||||
@ -57,7 +48,7 @@ define(
|
||||
* @param {Boolean} isMultiSelectEvent flag indication shift key is pressed or not
|
||||
* @private
|
||||
*/
|
||||
Selection.prototype.select = function (selectable, isMultiSelectEvent) {
|
||||
select(selectable, isMultiSelectEvent) {
|
||||
if (!Array.isArray(selectable)) {
|
||||
selectable = [selectable];
|
||||
}
|
||||
@ -72,12 +63,11 @@ define(
|
||||
} else {
|
||||
this.handleSingleSelect(selectable);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Selection.prototype.handleMultiSelect = function (selectable) {
|
||||
handleMultiSelect(selectable) {
|
||||
if (this.elementSelected(selectable)) {
|
||||
this.remove(selectable);
|
||||
} else {
|
||||
@ -86,31 +76,28 @@ define(
|
||||
}
|
||||
|
||||
this.emit('change', this.selected);
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Selection.prototype.handleSingleSelect = function (selectable) {
|
||||
handleSingleSelect(selectable) {
|
||||
if (!_.isEqual([selectable], this.selected)) {
|
||||
this.setSelectionStyles(selectable);
|
||||
this.selected = [selectable];
|
||||
|
||||
this.emit('change', this.selected);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Selection.prototype.elementSelected = function (selectable) {
|
||||
elementSelected(selectable) {
|
||||
return this.selected.some(selectionPath => _.isEqual(selectionPath, selectable));
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Selection.prototype.remove = function (selectable) {
|
||||
remove(selectable) {
|
||||
this.selected = this.selected.filter(selectionPath => !_.isEqual(selectionPath, selectable));
|
||||
|
||||
if (this.selected.length === 0) {
|
||||
@ -119,17 +106,15 @@ define(
|
||||
} else {
|
||||
this.removeSelectionAttributes(selectable, true);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Selection.prototype.setSelectionStyles = function (selectable) {
|
||||
setSelectionStyles(selectable) {
|
||||
this.selected.forEach(selectionPath => this.removeSelectionAttributes(selectionPath));
|
||||
this.addSelectionAttributes(selectable);
|
||||
};
|
||||
|
||||
Selection.prototype.removeSelectionAttributes = function (selectionPath, keepParentStyle) {
|
||||
}
|
||||
removeSelectionAttributes(selectionPath, keepParentStyle) {
|
||||
if (selectionPath[0] && selectionPath[0].element) {
|
||||
selectionPath[0].element.removeAttribute('s-selected');
|
||||
}
|
||||
@ -137,13 +122,12 @@ define(
|
||||
if (selectionPath[1] && selectionPath[1].element && !keepParentStyle) {
|
||||
selectionPath[1].element.removeAttribute('s-selected-parent');
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
}
|
||||
/**
|
||||
* Adds selection attributes to the selected element and its parent.
|
||||
* @private
|
||||
*/
|
||||
Selection.prototype.addSelectionAttributes = function (selectable) {
|
||||
addSelectionAttributes(selectable) {
|
||||
if (selectable[0] && selectable[0].element) {
|
||||
selectable[0].element.setAttribute('s-selected', "");
|
||||
}
|
||||
@ -151,44 +135,39 @@ define(
|
||||
if (selectable[1] && selectable[1].element) {
|
||||
selectable[1].element.setAttribute('s-selected-parent', "");
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Selection.prototype.parentSupportsMultiSelect = function (selectable) {
|
||||
parentSupportsMultiSelect(selectable) {
|
||||
return selectable[1] && selectable[1].context.supportsMultiSelect;
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Selection.prototype.selectionContainsParent = function (selectable) {
|
||||
selectionContainsParent(selectable) {
|
||||
return this.selected.some(selectionPath => _.isEqual(selectionPath[0], selectable[1]));
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Selection.prototype.isPeer = function (selectable) {
|
||||
isPeer(selectable) {
|
||||
return this.selected.some(selectionPath => _.isEqual(selectionPath[1], selectable[1]));
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Selection.prototype.isSelectable = function (element) {
|
||||
isSelectable(element) {
|
||||
if (!element) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Boolean(element.closest('[data-selectable]'));
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Selection.prototype.capture = function (selectable) {
|
||||
capture(selectable) {
|
||||
let capturingContainsSelectable = this.capturing && this.capturing.includes(selectable);
|
||||
|
||||
if (!this.capturing || capturingContainsSelectable) {
|
||||
@ -196,12 +175,11 @@ define(
|
||||
}
|
||||
|
||||
this.capturing.push(selectable);
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Selection.prototype.selectCapture = function (selectable, event) {
|
||||
selectCapture(selectable, event) {
|
||||
if (!this.capturing) {
|
||||
return;
|
||||
}
|
||||
@ -209,8 +187,7 @@ define(
|
||||
let reversedCapturing = this.capturing.reverse();
|
||||
delete this.capturing;
|
||||
this.select(reversedCapturing, event.shiftKey);
|
||||
};
|
||||
|
||||
}
|
||||
/**
|
||||
* Attaches the click handlers to the element.
|
||||
*
|
||||
@ -225,7 +202,7 @@ define(
|
||||
* @returns a function that removes the click handlers from the element
|
||||
* @public
|
||||
*/
|
||||
Selection.prototype.selectable = function (element, context, select) {
|
||||
selectable(element, context, select) {
|
||||
if (!this.isSelectable(element)) {
|
||||
return () => { };
|
||||
}
|
||||
@ -263,7 +240,5 @@ define(
|
||||
this.openmct.objects.destroyMutable(context.item);
|
||||
}
|
||||
}).bind(this);
|
||||
};
|
||||
|
||||
return Selection;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -7,19 +7,27 @@
|
||||
"baseUrl": "./",
|
||||
"allowJs": true,
|
||||
"checkJs": false,
|
||||
"declaration": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"declarationMap": true,
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"noImplicitOverride": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "dist",
|
||||
"skipLibCheck": true,
|
||||
"paths": {
|
||||
// matches the alias in webpack config, so that types for those imports are visible.
|
||||
"@/*": ["src/*"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"src/api/**/*.js"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist"
|
||||
"dist",
|
||||
"**/*Spec.js"
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user