Skip to content

Commit 4ee68cc

Browse files
authored
docs: better docs and types for the API (nasa#7796)
* docs: fix type imports in openmct.js * docs: fix type imports * docs: fix types for eventHelpers * docs: types for TypeRegistry * docs: types for StatusAPI * docs: fix ObjectAPI types and docs * docs: more types * docs: improved types for main entry * docs: improved types * fix: unbreak the linting * chore: remove EventEmitter webpack alias as it hide types * fix: return type * fix: parameter type * fix: types for composables * chore: add webpack consts to eslintrc * fix: remove usage of deprecated timeAPI methods and add a ton of docs and types * docs: update README.md * lint: clean up API.md * chore: upgrade eventemitter to v5.0.2 * refactor: update imports for EventEmitter to remove alias * format: lint * docs: update types for Views and ViewProviders * docs: expose common types at the base import level * docs(types): remove unnecessary tsconfig options * docs: ActionAPI * docs: AnnotationAPI * docs: import common types from the same origin * docs: FormsAPI & TelemetryAPI types * docs: FormController, IndicatorAPI * docs: MenuAPI, ActionsAPI * docs: `@memberof` is not supported by `tsc` and JSDoc generation so remove it * docs: RootRegistry and RootObjectProvider * docs: Transaction + Overlay * lint: words for the word god * fix: review comments
1 parent e3fcbe1 commit 4ee68cc

File tree

117 files changed

+1496
-1091
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+1496
-1091
lines changed

.cspell.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,20 @@
481481
"specced",
482482
"composables",
483483
"countup",
484-
"darkmatter"
484+
"darkmatter",
485+
"Undeletes"
486+
],
487+
"dictionaries": [
488+
"npm",
489+
"softwareTerms",
490+
"node",
491+
"html",
492+
"css",
493+
"bash",
494+
"en_US",
495+
"en-gb",
496+
"misc"
485497
],
486-
"dictionaries": ["npm", "softwareTerms", "node", "html", "css", "bash", "en_US", "en-gb", "misc"],
487498
"ignorePaths": [
488499
"package.json",
489500
"dist/**",
@@ -494,4 +505,4 @@
494505
"html-test-results",
495506
"test-results"
496507
]
497-
}
508+
}

.eslintrc.cjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ const config = {
1010
serviceworker: true
1111
},
1212
globals: {
13-
_: 'readonly'
13+
_: 'readonly',
14+
__webpack_public_path__: 'writeable',
15+
__OPENMCT_VERSION__: 'readonly',
16+
__OPENMCT_BUILD_DATE__: 'readonly',
17+
__OPENMCT_REVISION__: 'readonly',
18+
__OPENMCT_BUILD_BRANCH__: 'readonly'
1419
},
1520
plugins: ['prettier', 'unicorn', 'simple-import-sort'],
1621
extends: [

.webpack/webpack.common.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ const config = {
7070
'@': path.join(projectRootDir, 'src'),
7171
legacyRegistry: path.join(projectRootDir, 'src/legacyRegistry'),
7272
csv: 'comma-separated-values',
73-
EventEmitter: 'eventemitter3',
7473
bourbon: 'bourbon.scss',
7574
'plotly-basic': 'plotly.js-basic-dist-min',
7675
'plotly-gl2d': 'plotly.js-gl2d-dist-min',

API.md

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ openmct.composition.addProvider({
381381

382382
The `addProvider` function accepts a Composition Provider object as its sole
383383
argument. A Composition Provider is a javascript object exposing two functions:
384+
384385
- `appliesTo`: A `function` that accepts a `domainObject` argument, and returns
385386
a `boolean` value indicating whether this composition provider applies to the
386387
given object.
@@ -618,9 +619,10 @@ interface Formatter {
618619

619620
Open MCT on its own defines a handful of built-in formats:
620621

621-
###### **Number Format (default):**
622+
###### **Number Format (default):**
622623

623624
Applied to data with `format: 'number'`
625+
624626
```js
625627
valueMetadata = {
626628
format: 'number'
@@ -635,15 +637,18 @@ interface NumberFormatter extends Formatter {
635637
validate: (value: any) => boolean;
636638
}
637639
```
638-
###### **String Format**:
640+
641+
###### **String Format**
639642

640643
Applied to data with `format: 'string'`
644+
641645
```js
642646
valueMetadata = {
643647
format: 'string'
644648
// ...
645649
};
646650
```
651+
647652
```ts
648653
interface StringFormatter extends Formatter {
649654
parse: (value: any) => string;
@@ -652,8 +657,10 @@ interface StringFormatter extends Formatter {
652657
}
653658
```
654659

655-
###### **Enum Format**:
660+
###### **Enum Format**
661+
656662
Applied to data with `format: 'enum'`
663+
657664
```js
658665
valueMetadata = {
659666
format: 'enum',
@@ -676,6 +683,7 @@ valueMetadata = {
676683

677684
Creates a two-way mapping between enum string and value to be used in the `parse` and `format` methods.
678685
Ex:
686+
679687
- `formatter.parse('APPLE') === 1;`
680688
- `formatter.format(1) === 'APPLE';`
681689

@@ -691,7 +699,6 @@ interface EnumFormatter extends Formatter {
691699

692700
Formats implement the following interface (provided here as TypeScript for simplicity):
693701

694-
695702
Formats are registered with the Telemetry API using the `addFormat` function. eg.
696703

697704
```javascript
@@ -763,8 +770,8 @@ state of the application, and emits events to inform listeners when the state ch
763770

764771
Because the data displayed tends to be time domain data, Open MCT must always
765772
have at least one time system installed and activated. When you download Open
766-
MCT, it will be pre-configured to use the UTC time system, which is installed and activated,
767-
along with other default plugins, in `index.html`. Installing and activating a time system
773+
MCT, it will be pre-configured to use the UTC time system, which is installed and activated,
774+
along with other default plugins, in `index.html`. Installing and activating a time system
768775
is simple, and is covered [in the next section](#defining-and-registering-time-systems).
769776

770777
### Time Systems and Bounds
@@ -817,7 +824,7 @@ numbers in UTC terrestrial time.
817824
#### Getting and Setting the Active Time System
818825

819826
Once registered, a time system can be activated by calling `setTimeSystem` with
820-
the timeSystem `key` or an instance of the time system. You can also specify
827+
the timeSystem `key` or an instance of the time system. You can also specify
821828
valid [bounds](#time-bounds) for the timeSystem.
822829

823830
```javascript
@@ -841,10 +848,9 @@ Setting the active time system will trigger a [`'timeSystemChanged'`](#time-even
841848
event. If you supplied bounds, a [`'boundsChanged'`](#time-events) event will be triggered afterwards with your newly supplied bounds.
842849

843850
> ⚠️ **Deprecated**
851+
>
844852
> - The method `timeSystem()` is deprecated. Please use `getTimeSystem()` and `setTimeSystem()` as a replacement.
845853
846-
847-
848854
#### Time Bounds
849855

850856
The TimeAPI provides a getter and setter for querying and setting time bounds. Time
@@ -875,15 +881,16 @@ To respond to bounds change events, listen for the [`'boundsChanged'`](#time-eve
875881
event.
876882
877883
> ⚠️ **Deprecated**
884+
>
878885
> - The method `bounds()` is deprecated and will be removed in a future release. Please use `getBounds()` and `setBounds()` as a replacement.
879886
880887
### Clocks
881888
882-
The Time API requires a clock source which will cause the bounds to be updated
883-
automatically whenever the clock source "ticks". A clock is simply an object that
884-
supports registration of listeners and periodically invokes its listeners with a
885-
number. Open MCT supports registration of new clock sources that tick on almost
886-
anything. A tick occurs when the clock invokes callback functions registered by its
889+
The Time API requires a clock source which will cause the bounds to be updated
890+
automatically whenever the clock source "ticks". A clock is simply an object that
891+
supports registration of listeners and periodically invokes its listeners with a
892+
number. Open MCT supports registration of new clock sources that tick on almost
893+
anything. A tick occurs when the clock invokes callback functions registered by its
887894
listeners with a new time value.
888895
889896
An example of a clock source is the [LocalClock](https://github.com/nasa/openmct/blob/master/src/plugins/utcTimeSystem/LocalClock.js)
@@ -972,6 +979,7 @@ openmct.time.getClock();
972979
```
973980
974981
> ⚠️ **Deprecated**
982+
>
975983
> - The method `clock()` is deprecated and will be removed in a future release. Please use `getClock()` and `setClock()` as a replacement.
976984
977985
#### ⚠️ [DEPRECATED] Stopping an active clock
@@ -986,12 +994,13 @@ openmct.time.stopClock();
986994
```
987995
988996
> ⚠️ **Deprecated**
997+
>
989998
> - The method `stopClock()` is deprecated and will be removed in a future release.
990999
9911000
#### Clock Offsets
9921001
993-
When in Real-time [mode](#time-modes), the time bounds of the application will be updated automatically each time the
994-
clock "ticks". The bounds are calculated based on the current value provided by
1002+
When in Real-time [mode](#time-modes), the time bounds of the application will be updated automatically each time the
1003+
clock "ticks". The bounds are calculated based on the current value provided by
9951004
the active clock (via its `tick` event, or its `currentValue()` method).
9961005
9971006
Unlike bounds, which represent absolute time values, clock offsets represent
@@ -1026,13 +1035,14 @@ new bounds will be calculated based on the `currentValue()` of the active clock.
10261035
Clock offsets are only relevant when in Real-time [mode](#time-modes).
10271036
10281037
> ⚠️ **Deprecated**
1038+
>
10291039
> - The method `clockOffsets()` is deprecated and will be removed in a future release. Please use `getClockOffsets()` and `setClockOffsets()` as a replacement.
10301040
10311041
### Time Modes
10321042
1033-
There are two time modes in Open MCT, "Fixed" and "Real-time". In Real-time mode the
1043+
There are two time modes in Open MCT, "Fixed" and "Real-time". In Real-time mode the
10341044
time bounds of the application will be updated automatically each time the clock "ticks".
1035-
The bounds are calculated based on the current value provided by the active clock. In
1045+
The bounds are calculated based on the current value provided by the active clock. In
10361046
Fixed mode, the time bounds are set for a specified time range. When Open MCT is first
10371047
initialized, it will be in Real-time mode.
10381048
@@ -1120,6 +1130,7 @@ The events emitted by the Time API are:
11201130
- `mode`: A string representation of the current time mode, either `'realtime'` or `'fixed'`.
11211131
11221132
> ⚠️ **Deprecated Events** (These will be removed in a future release):
1133+
>
11231134
> - `bounds``boundsChanged`
11241135
> - `timeSystem``timeSystemChanged`
11251136
> - `clock``clockChanged`
@@ -1262,7 +1273,7 @@ Returns the currently set text as a `string`.
12621273
[the built-in glyphs](https://nasa.github.io/openmct/style-guide/#/browse/styleguide:home/glyphs?view=styleguide.glyphs)
12631274
may be used here, or a custom CSS class can be provided. Returns the currently defined CSS
12641275
class as a `string`.
1265-
- `.statusClass([className])`: Gets or sets the CSS class used to determine status. Accepts an __optional__
1276+
- `.statusClass([className])`: Gets or sets the CSS class used to determine status. Accepts an **optional**
12661277
`string` parameter to be used to set a status class applied to the indicator. May be used to apply
12671278
different colors to indicate status.
12681279
@@ -1312,7 +1323,7 @@ can be used to manage user information and roles.
13121323
13131324
### Example
13141325
1315-
Open MCT provides an example [user](example/exampleUser/exampleUserCreator.js) and [user provider](example/exampleUser/ExampleUserProvider.js) which
1326+
Open MCT provides an example [user](example/exampleUser/exampleUserCreator.js) and [user provider](example/exampleUser/ExampleUserProvider.js) which
13161327
can be used as a starting point for creating a custom user provider.
13171328
13181329
## Visibility-Based Rendering in View Providers
@@ -1335,10 +1346,10 @@ Here’s the signature for the show function:
13351346
13361347
`show(element, isEditing, viewOptions)`
13371348
1338-
* `element` (HTMLElement) - The DOM element where the view should be rendered.
1339-
* `isEditing` (boolean) - Indicates whether the view is in editing mode.
1340-
* `viewOptions` (Object) - An object with configuration options for the view, including:
1341-
* `renderWhenVisible` (Function) - This function wraps the `requestAnimationFrame` and only triggers the provided render logic when the view is visible in the viewport.
1349+
- `element` (HTMLElement) - The DOM element where the view should be rendered.
1350+
- `isEditing` (boolean) - Indicates whether the view is in editing mode.
1351+
- `viewOptions` (Object) - An object with configuration options for the view, including:
1352+
- `renderWhenVisible` (Function) - This function wraps the `requestAnimationFrame` and only triggers the provided render logic when the view is visible in the viewport.
13421353
13431354
### Example
13441355
@@ -1367,8 +1378,6 @@ const myViewProvider = {
13671378
};
13681379
```
13691380
1370-
13711381
Note that `renderWhenVisible` defers rendering while the view is not visible and caters to the latest execution call. This provides responsiveness for dynamic content while ensuring performance optimizations.
13721382
13731383
Ensure your view logic is prepared to handle potentially multiple deferrals if using this API, as only the last call to renderWhenVisible will be queued for execution upon the view becoming visible.
1374-

0 commit comments

Comments
 (0)