@cognite/reveal-widget 0.3.0 → 1.48535.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -57,7 +57,9 @@ If your bundler doesn't already dedupe singletons across your dependency tree, a
57
57
 
58
58
  ```ts
59
59
  // vite.config.ts
60
- resolve: { dedupe: ['three', '@cognite/reveal'] }
60
+ resolve: {
61
+ dedupe: ['three', '@cognite/reveal'];
62
+ }
61
63
  ```
62
64
 
63
65
  ## Usage
@@ -114,7 +116,9 @@ export function ThreeDViewer({
114
116
  }) {
115
117
  const viewerRef = useRef<ThreeDViewerController>();
116
118
 
117
- function handleWidgetController(widgetController: RevealWidgetController | undefined) {
119
+ function handleWidgetController(
120
+ widgetController: RevealWidgetController | undefined
121
+ ) {
118
122
  viewerRef.current?.dispose();
119
123
 
120
124
  if (widgetController === undefined) {
@@ -165,24 +169,82 @@ CAD/point cloud/image360 resources resolve to a `Reveal3DResourceHandle` usable
165
169
  `styleByInstance`/`getModels()`/`cameraController.focusModel()`; a `'scene'` resource resolves to
166
170
  a handle that only supports `.remove()`.
167
171
 
172
+ ### Loading a scene by location
173
+
174
+ `controller.addResourceByLocation(location, selectedScene?)` loads the scene configured for a
175
+ location, matched by external ID or name and including its sub-locations. It resolves to a result
176
+ with a `status`:
177
+
178
+ - `'loaded'`: exactly one scene was found and added; `scene` is its handle
179
+ - `'selection-required'`: several scenes were found and nothing was loaded; `candidates` lists
180
+ each `{ scene, locationName }`. Call again with the chosen `scene` as `selectedScene`
181
+ - `'not-found'`: no such location, or it has no scene
182
+
183
+ ### Searching mapped assets
184
+
185
+ `controller.assets.searchMappedAssets({ query?, limit? })` searches the data modeling assets
186
+ mapped to the visible CAD models, point clouds and data model 360 image collections, including
187
+ those of a loaded scene. Classic assets are never searched, so use it with `useCoreDm: true` in
188
+ data-modeling-only projects. `limit` defaults to 100 (maximum 1000). There is no pagination; when
189
+ `hasMore` is true, narrow the search with `query`.
190
+
191
+ ```ts
192
+ const { assets, hasMore } = await controller.assets.searchMappedAssets({
193
+ query: 'pump',
194
+ });
195
+ await controller.focusInstances([assets[0].instanceId]);
196
+ ```
197
+
198
+ ### HTML overlays
199
+
200
+ `controller.htmlOverlays.add(element, position)` attaches an HTML element to a position in the 3D scene, e.g. to show a notification.
201
+ The element follows the position as the camera moves and is hidden while the position is out of view.
202
+ `position` is `{ x, y, z }` in CDF coordinates, the same ones the coordinates of CDF 3D models and their assets are given in.
203
+ It returns a handle whose `remove()` removes the overlay.
204
+ Removing an overlay right after adding it is safe.
205
+ Adding the same element again moves it to the new position.
206
+
207
+ The widget sets `position: absolute` on the element, which overlays require.
208
+ Other styling is up to you, e.g. `transform: translate(-50%, -50%)` to center the element on the position, and `pointer-events: none` if it should not interfere with camera navigation.
209
+
210
+ ```ts
211
+ const element = document.createElement('div');
212
+ element.textContent = 'Pump 01 needs attention';
213
+ element.style.transform = 'translate(-50%, -50%)';
214
+
215
+ const overlay = controller.htmlOverlays.add(element, { x: 10, y: 20, z: 5 });
216
+
217
+ // Hide or show all overlays without removing them
218
+ controller.htmlOverlays.setVisible(false);
219
+
220
+ // Remove one overlay, or all of them
221
+ overlay.remove();
222
+ controller.htmlOverlays.clear();
223
+ ```
224
+
225
+ Overlays are removed when the widget unmounts or its controller is replaced.
226
+
168
227
  ### Highlighting instances
169
228
 
170
229
  Instances (assets) are identified either by classic numeric asset ID or by a data modeling
171
230
  `{ externalId, space }` reference:
172
231
 
173
232
  ```ts
174
- instanceIds: [1560727417020285]
175
- instanceIds: [{ externalId: 'CogniteAsset-1022', space: 'my-space' }]
233
+ instanceIds: [1560727417020285];
234
+ instanceIds: [{ externalId: 'CogniteAsset-1022', space: 'my-space' }];
176
235
  ```
177
236
 
178
237
  ### Camera control
179
238
 
180
239
  ```ts
181
240
  controller.cameraController.focusModel(handle); // fit one model
182
- controller.cameraController.focusCameraAll(); // fit all models
241
+ controller.cameraController.focusCameraAll(); // fit all models
183
242
  await controller.focusInstances([someInstanceId]); // zoom to a specific instance
184
243
  ```
185
244
 
245
+ If the instance is mapped to an annotation in a 360 image, `focusInstances` enters that image
246
+ instead of moving to a bounding box.
247
+
186
248
  ## Cleaning up
187
249
 
188
250
  Resources added via `addResource` should be removed when no longer needed:
package/dist/index.d.ts CHANGED
@@ -1,132 +1,274 @@
1
- import { PropsWithChildren, ReactElement } from 'react';
2
- import { CameraState, Cognite3DViewerOptions, NodeAppearance } from '@cognite/reveal';
3
- import { DmsUniqueIdentifier, ExternalId, Space } from '@cognite/reveal-components/data-providers';
4
- import { AssetId } from '@cognite/reveal-components/data-providers/cache';
5
- import { AddReveal3DResource, AllResourceIdentifier, BaseAddOptions, CadAddOptions, NewCadModelStyling as CadModelStyling, CadResourceIdentifier, Classic3DResourceIdentifier, DM3DResourceIdentifier, Image360AddOptions, Image360DMResourceIdentifier, Image360EventsResourceIdentifier, Image360IconCullingOptions, Image360ResourceIdentifier, PointCloudAddOptions, PointCloudResourceIdentifier, SceneAddOptions, SceneResourceIdentifier, ThreeDResourceIdentifier } from '@cognite/reveal-components/data-providers/types';
6
- import { RevealWidgetTrackingProps } from '@cognite/reveal-components/ui/components';
7
- import { InstanceId, UsageMetricsTracker } from '@cognite/reveal-components/utilities';
8
- import { InstanceStylingGroup } from '@cognite/reveal-components/utilities/modelIds';
9
- import { TreeIndexStylingGroup } from '@cognite/reveal-components/utilities/styling';
10
- export type { AddReveal3DResource, AllResourceIdentifier, AssetId, BaseAddOptions, CadAddOptions, CadModelStyling, CadResourceIdentifier, Classic3DResourceIdentifier, DM3DResourceIdentifier, DmsUniqueIdentifier, ExternalId, Image360AddOptions, Image360DMResourceIdentifier, Image360EventsResourceIdentifier, Image360IconCullingOptions, Image360ResourceIdentifier, InstanceId, InstanceStylingGroup, UsageMetricsTracker, PointCloudAddOptions, PointCloudResourceIdentifier, RevealWidgetTrackingProps, SceneAddOptions, SceneResourceIdentifier, Space, ThreeDResourceIdentifier, TreeIndexStylingGroup, };
1
+ import type { PropsWithChildren, ReactElement } from "react";
2
+ import type { CameraState, Cognite3DViewerOptions, NodeAppearance } from "@cognite/reveal";
3
+ import type { DmsUniqueIdentifier, ExternalId, Space } from "@cognite/reveal-components/data-providers";
4
+ import type { AssetId } from "@cognite/reveal-components/data-providers/cache";
5
+ import type { AddReveal3DResource, AllResourceIdentifier, BaseAddOptions, CadAddOptions, NewCadModelStyling as CadModelStyling, CadResourceIdentifier, Classic3DResourceIdentifier, DM3DResourceIdentifier, Image360AddOptions, Image360DMResourceIdentifier, Image360EventsResourceIdentifier, Image360IconCullingOptions, Image360ResourceIdentifier, PointCloudAddOptions, PointCloudResourceIdentifier, SceneAddOptions, SceneResourceIdentifier, ThreeDResourceIdentifier } from "@cognite/reveal-components/data-providers/types";
6
+ import { type RevealWidgetTrackingProps } from "@cognite/reveal-components/ui/components";
7
+ import type { InstanceId, UsageMetricsTracker } from "@cognite/reveal-components/utilities";
8
+ import type { InstanceStylingGroup } from "@cognite/reveal-components/utilities/modelIds";
9
+ import type { TreeIndexStylingGroup } from "@cognite/reveal-components/utilities/styling";
10
+ export type { AddReveal3DResource, AllResourceIdentifier, AssetId, BaseAddOptions, CadAddOptions, CadModelStyling, CadResourceIdentifier, Classic3DResourceIdentifier, DM3DResourceIdentifier, DmsUniqueIdentifier, ExternalId, Image360AddOptions, Image360DMResourceIdentifier, Image360EventsResourceIdentifier, Image360IconCullingOptions, Image360ResourceIdentifier, InstanceId, InstanceStylingGroup, UsageMetricsTracker, PointCloudAddOptions, PointCloudResourceIdentifier, RevealWidgetTrackingProps, SceneAddOptions, SceneResourceIdentifier, Space, ThreeDResourceIdentifier, TreeIndexStylingGroup };
11
11
  /**
12
- * Public API surface for the standalone `@cognite/reveal-widget` npm package.
13
- *
14
- * `RevealWidget` here is the real, unmodified implementation from
15
- * `@cognite/reveal-components` — there is no runtime wrapper. `@cognite/reveal-components`
16
- * is a `dependencies` entry, so it and its own published dependencies (`@cognite/signal-utils`,
17
- * `@cognite/underscore`) are treated as external. The resource/identifier types above are
18
- * re-exported directly from `@cognite/reveal-components`'s narrow, already-subpath-exported
19
- * type barrels (`./data-providers/types`, `./utilities/modelIds`, `./utilities`), which an
20
- * external consumer resolves normally since that package is published.
21
- *
22
- * `Reveal3DResourceHandle`, `RevealWidgetController`, `RevealWidgetCameraController`, and
23
- * `RevealWidgetProps` below are still hand-declared, because their real counterparts (only
24
- * reachable via the entangled `./ui/components` export) expose `RevealDomainObject`/
25
- * `SceneDomainObject` directly in their signatures — too large for API Extractor's type bundler
26
- * and not meaningful for an external consumer anyway. `src/index.test.ts` has compile-time-only
27
- * (`// @ts-expect-error`-driven) tests asserting these hand-written types stay structurally
28
- * compatible with the real implementation — update both together when the real API changes.
29
- * `RevealWidgetTrackingProps` (and its arms) don't have this problem — they only reference
30
- * `UsageMetricsTracker`, so they're imported and re-exported directly from `./ui/components`
31
- * rather than hand-declared.
32
- *
33
- * `tracking`/`appIdentifier` (on `RevealWidgetProps`) plumb through to the real `RevealWidget`'s
34
- * usage-tracking seam, which reports to a dedicated, named `mixpanel-browser` instance *by
35
- * default* — not Fusion's own `@cognite/metrics`/Mixpanel setup, since `@cognite/reveal-widget`
36
- * is also consumed outside this monorepo. Pass `tracking: { disabled: true }` to opt out
37
- * entirely, or `tracking: { mixpanelToken }` (with `appIdentifier`) to report to your own
38
- * Mixpanel project instead.
39
- */
12
+ * Public API surface for the standalone `@cognite/reveal-widget` npm package.
13
+ *
14
+ * `RevealWidget` here is the real, unmodified implementation from
15
+ * `@cognite/reveal-components` — there is no runtime wrapper. `@cognite/reveal-components`
16
+ * is a `dependencies` entry, so it and its own published dependencies (`@cognite/signal-utils`,
17
+ * `@cognite/underscore`) are treated as external. The resource/identifier types above are
18
+ * re-exported directly from `@cognite/reveal-components`'s narrow, already-subpath-exported
19
+ * type barrels (`./data-providers/types`, `./utilities/modelIds`, `./utilities`), which an
20
+ * external consumer resolves normally since that package is published.
21
+ *
22
+ * `Reveal3DResourceHandle`, `RevealWidgetController`, `RevealWidgetCameraController`, `RevealWidgetAssets`, `RevealWidgetHtmlOverlays`, and
23
+ * `RevealWidgetProps` below are still hand-declared, because their real counterparts (only
24
+ * reachable via the entangled `./ui/components` export) expose `RevealDomainObject`/
25
+ * `SceneDomainObject` directly in their signatures — too large for API Extractor's type bundler
26
+ * and not meaningful for an external consumer anyway. `src/index.test.ts` has compile-time-only
27
+ * (`// @ts-expect-error`-driven) tests asserting these hand-written types stay structurally
28
+ * compatible with the real implementation — update both together when the real API changes.
29
+ * `RevealWidgetTrackingProps` (and its arms) don't have this problem — they only reference
30
+ * `UsageMetricsTracker`, so they're imported and re-exported directly from `./ui/components`
31
+ * rather than hand-declared.
32
+ *
33
+ * `tracking`/`appIdentifier` (on `RevealWidgetProps`) plumb through to the real `RevealWidget`'s
34
+ * usage-tracking seam, which reports to a dedicated, named `mixpanel-browser` instance *by
35
+ * default* — not Fusion's own `@cognite/metrics`/Mixpanel setup, since `@cognite/reveal-widget`
36
+ * is also consumed outside this monorepo. Pass `tracking: { disabled: true }` to opt out
37
+ * entirely, or `tracking: { mixpanelToken }` (with `appIdentifier`) to report to your own
38
+ * Mixpanel project instead.
39
+ */
40
40
  export declare const Default3DStyles: {
41
- Highlighted: {
42
- cad: NodeAppearance;
43
- pointcloud: NodeAppearance;
44
- image360: NodeAppearance;
45
- };
41
+ Highlighted: {
42
+ cad: NodeAppearance;
43
+ pointcloud: NodeAppearance;
44
+ image360: NodeAppearance;
45
+ };
46
46
  };
47
47
  /**
48
- * A narrow, external-facing view of a loaded 3D resource (CAD model, point cloud, image360
49
- * collection, or scene). This is a type-only narrowing — the actual object returned at runtime
50
- * by `addResource()`/`getModels()` is still the real `RevealDomainObject`/`SceneDomainObject`.
51
- * Only `.remove()` is published here to keep the exported type surface minimal.
52
- */
48
+ * A narrow, external-facing view of a loaded 3D resource (CAD model, point cloud, image360
49
+ * collection, or scene). This is a type-only narrowing — the actual object returned at runtime
50
+ * by `addResource()`/`getModels()` is still the real `RevealDomainObject`/`SceneDomainObject`.
51
+ * Only `.remove()` is published here to keep the exported type surface minimal.
52
+ */
53
53
  export type Reveal3DResourceHandle = {
54
- remove(): boolean;
54
+ remove(): boolean;
55
+ };
56
+ /**
57
+ * A scene that can be loaded for a location, and the (sub-)location it is
58
+ * configured on.
59
+ */
60
+ export type LocationSceneCandidate = {
61
+ scene: DmsUniqueIdentifier;
62
+ locationName: string;
63
+ };
64
+ /**
65
+ * Outcome of `RevealWidgetController.addResourceByLocation`:
66
+ * - `loaded`: the scene was added to the widget
67
+ * - `selection-required`: the location has several scenes (its own and those of
68
+ * its sub-locations); nothing was loaded, call again with the chosen scene
69
+ * - `not-found`: no such location, or it has no scene
70
+ */
71
+ export type AddResourceByLocationResult = SceneLoadedForLocation | SceneSelectionRequiredForLocation | SceneNotFoundForLocation;
72
+ export type SceneLoadedForLocation = {
73
+ status: "loaded";
74
+ scene: Reveal3DResourceHandle;
75
+ };
76
+ export type SceneSelectionRequiredForLocation = {
77
+ status: "selection-required";
78
+ candidates: LocationSceneCandidate[];
79
+ };
80
+ export type SceneNotFoundForLocation = {
81
+ status: "not-found";
82
+ };
83
+ /**
84
+ * An asset that is mapped to a loaded 3D model.
85
+ */
86
+ export type MappedAsset = {
87
+ name: string;
88
+ description?: string;
89
+ /** Pass to `styleByInstance` / `focusInstances` to highlight or zoom to the asset */
90
+ instanceId: InstanceId;
91
+ };
92
+ /**
93
+ * Options for `RevealWidgetAssets.searchMappedAssets`.
94
+ */
95
+ export type SearchMappedAssetsOptions = {
96
+ /**
97
+ * Free-text search on the asset name and description. Not guaranteed to
98
+ * return all matching assets.
99
+ */
100
+ query?: string;
101
+ /** Maximum number of assets to return (default 100, maximum 1000) */
102
+ limit?: number;
103
+ };
104
+ /**
105
+ * Result of `RevealWidgetAssets.searchMappedAssets`.
106
+ */
107
+ export type SearchMappedAssetsResult = {
108
+ assets: MappedAsset[];
109
+ /**
110
+ * True if there may be more matching assets than were returned. Pagination is
111
+ * not supported, so use `query` to narrow down the search.
112
+ */
113
+ hasMore: boolean;
114
+ };
115
+ /**
116
+ * Search for the assets mapped to the models in the widget.
117
+ */
118
+ export type RevealWidgetAssets = {
119
+ /**
120
+ * Search the core data model assets that are mapped to the visible CAD models,
121
+ * point clouds and data model 360 image collections, including those of a
122
+ * loaded scene. Only data modeling assets are searched, never classic assets,
123
+ * so this is intended for data-modeling-only projects. Use the returned
124
+ * `instanceId`s with `styleByInstance` and `focusInstances` to highlight an
125
+ * asset and zoom to it.
126
+ */
127
+ searchMappedAssets(options?: SearchMappedAssetsOptions): Promise<SearchMappedAssetsResult>;
128
+ };
129
+ /**
130
+ * A position in the CDF coordinate system, i.e. the one the coordinates of
131
+ * CDF 3D models and their assets are given in
132
+ */
133
+ export type HtmlOverlayPosition = {
134
+ x: number;
135
+ y: number;
136
+ z: number;
137
+ };
138
+ /**
139
+ * A handle to an HTML overlay added to the widget
140
+ */
141
+ export type HtmlOverlayHandle = {
142
+ /**
143
+ * Removes the overlay's element from the widget. Does nothing if
144
+ * it has already been removed.
145
+ */
146
+ remove(): void;
147
+ };
148
+ /**
149
+ * Attaching HTML elements to positions in the 3D scene of the widget,
150
+ * e.g. to show notifications.
151
+ */
152
+ export type RevealWidgetHtmlOverlays = {
153
+ /**
154
+ * Attaches an HTML element to a position in the scene. The element follows the
155
+ * position as the camera moves, and is hidden while the position is not in view.
156
+ *
157
+ * The widget sets `position: absolute` on the element, which the overlay requires.
158
+ * Styling such as `transform: translate(-50%, -50%)` to center the element on the
159
+ * position, and `pointer-events: none` to not interfere with camera navigation,
160
+ * is up to the caller.
161
+ *
162
+ * ```
163
+ * const overlay = controller.htmlOverlays.add(element, { x: 10, y: 20, z: 5 });
164
+ *
165
+ * // during cleanup:
166
+ * overlay.remove();
167
+ * ```
168
+ *
169
+ * @param element The element to attach. Adding the same element again moves it.
170
+ * @param position The position in CDF coordinates
171
+ */
172
+ add(element: HTMLElement, position: HtmlOverlayPosition): HtmlOverlayHandle;
173
+ /**
174
+ * Removes all the overlays added to the widget
175
+ */
176
+ clear(): void;
177
+ /**
178
+ * Hides or shows all the overlays, including ones added later. They are visible by default.
179
+ */
180
+ setVisible(visible: boolean): void;
55
181
  };
56
182
  export type RevealWidgetCameraController = {
57
- /**
58
- * Focus all visible models in the scene
59
- */
60
- focusCameraAll(): void;
61
- /**
62
- * Focus on a single given 3D model
63
- */
64
- focusModel(handle: Reveal3DResourceHandle): void;
65
- /**
66
- * Returns the state of the camera in the Reveal viewer
67
- */
68
- getCameraState(): Required<CameraState>;
69
- /**
70
- * Sets the state of the camera
71
- */
72
- setCameraState(cameraState: CameraState): void;
73
- enterNearby360Image(): Promise<void> | undefined;
183
+ /**
184
+ * Focus all visible models in the scene
185
+ */
186
+ focusCameraAll(): void;
187
+ /**
188
+ * Focus on a single given 3D model
189
+ */
190
+ focusModel(handle: Reveal3DResourceHandle): void;
191
+ /**
192
+ * Returns the state of the camera in the Reveal viewer
193
+ */
194
+ getCameraState(): Required<CameraState>;
195
+ /**
196
+ * Sets the state of the camera
197
+ */
198
+ setCameraState(cameraState: CameraState): void;
199
+ enterNearby360Image(): Promise<void> | undefined;
74
200
  };
75
201
  export type RevealWidgetController = {
76
- /**
77
- * Access the RevealWidgetCameraController for camera controls
78
- */
79
- readonly cameraController: RevealWidgetCameraController;
80
- /**
81
- * Add a 3D resource (i.e. model or scene) to the widget.
82
- * Added resources can be removed by calling their `.remove` method.
83
- */
84
- addResource(resource: AllResourceIdentifier): Promise<Reveal3DResourceHandle>;
85
- /**
86
- * Get all models added to the RevealWidget
87
- */
88
- getModels(): Reveal3DResourceHandle[];
89
- /**
90
- * Get all models added to the RevealWidget that are visible
91
- */
92
- getVisibleModels(): Reveal3DResourceHandle[];
93
- /**
94
- * Style the provided instances with the associated styles in the given models, if
95
- * the instances are contextualized to the models
96
- */
97
- styleByInstance(instanceStylingGroups: InstanceStylingGroup[], handles: Reveal3DResourceHandle[]): Promise<void>;
98
- /**
99
- * Moves the camera to show the provided instances in the visible models in the scene.
100
- */
101
- focusInstances(instances: InstanceId[]): Promise<void>;
202
+ /**
203
+ * Access the RevealWidgetCameraController for camera controls
204
+ */
205
+ readonly cameraController: RevealWidgetCameraController;
206
+ /**
207
+ * Access the RevealWidgetAssets for searching the assets mapped to the models
208
+ */
209
+ readonly assets: RevealWidgetAssets;
210
+ /**
211
+ * Access the RevealWidgetHtmlOverlays for attaching HTML elements to positions in the scene
212
+ */
213
+ readonly htmlOverlays: RevealWidgetHtmlOverlays;
214
+ /**
215
+ * Add a 3D resource (i.e. model or scene) to the widget.
216
+ * Added resources can be removed by calling their `.remove` method.
217
+ */
218
+ addResource(resource: AllResourceIdentifier): Promise<Reveal3DResourceHandle>;
219
+ /**
220
+ * Load a scene from a location (matched by external ID or name). If the
221
+ * location, including its sub-locations, has exactly one scene it is loaded.
222
+ * If it has several, nothing is loaded and the candidates are returned so the
223
+ * caller can ask the user to pick one, then call this method again with
224
+ * `selectedScene`.
225
+ */
226
+ addResourceByLocation(location: string, selectedScene?: DmsUniqueIdentifier): Promise<AddResourceByLocationResult>;
227
+ /**
228
+ * Get all models added to the RevealWidget
229
+ */
230
+ getModels(): Reveal3DResourceHandle[];
231
+ /**
232
+ * Get all models added to the RevealWidget that are visible
233
+ */
234
+ getVisibleModels(): Reveal3DResourceHandle[];
235
+ /**
236
+ * Style the provided instances with the associated styles in the given models, if
237
+ * the instances are contextualized to the models
238
+ */
239
+ styleByInstance(instanceStylingGroups: InstanceStylingGroup[], handles: Reveal3DResourceHandle[]): Promise<void>;
240
+ /**
241
+ * Moves the camera to show the provided instances in the visible models in the scene.
242
+ */
243
+ focusInstances(instances: InstanceId[]): Promise<void>;
102
244
  };
103
245
  export type RevealWidgetProps = {
104
- /**
105
- * Defines the initialization options for the RevealWidget, including the SDK and data modeling status
106
- * The user can either specify these separately, or opt for the object
107
- * `{ inheritFromRevealContext: true }`, in which case the Widget will assume the existence of
108
- * a `RevealContext` mounted above it in the hierarchy.
109
- */
110
- viewerOptions: (Pick<Cognite3DViewerOptions, 'sdk' | 'onLoading'> & {
111
- useCoreDm: boolean;
112
- }) | {
113
- /**
114
- * Disables the RevealWidget's own RevealContext, relying on one defined in the application
115
- * layer instead.
116
- */
117
- inheritFromRevealContext: true;
118
- };
119
- /**
120
- * The widget uses this to set a reference to the widget controller.
121
- * The widget calls this with `undefined` when the component unmounts or this callback changes
122
- */
123
- setControllerRef?: (controller: RevealWidgetController | undefined) => void;
124
- /**
125
- * Reports which application is using the widget and which of its features are being triggered
126
- * (e.g. adding a resource, moving the camera). See `RevealWidgetTrackingProps` for the options.
127
- */
128
- tracking?: RevealWidgetTrackingProps;
129
- /** Identifies the host application */
130
- appIdentifier: string;
246
+ /**
247
+ * Defines the initialization options for the RevealWidget, including the SDK and data modeling status
248
+ * The user can either specify these separately, or opt for the object
249
+ * `{ inheritFromRevealContext: true }`, in which case the Widget will assume the existence of
250
+ * a `RevealContext` mounted above it in the hierarchy.
251
+ */
252
+ viewerOptions: (Pick<Cognite3DViewerOptions, "sdk" | "onLoading"> & {
253
+ useCoreDm: boolean;
254
+ }) | {
255
+ /**
256
+ * Disables the RevealWidget's own RevealContext, relying on one defined in the application
257
+ * layer instead.
258
+ */
259
+ inheritFromRevealContext: true;
260
+ };
261
+ /**
262
+ * The widget uses this to set a reference to the widget controller.
263
+ * The widget calls this with `undefined` when the component unmounts or this callback changes
264
+ */
265
+ setControllerRef?: (controller: RevealWidgetController | undefined) => void;
266
+ /**
267
+ * Reports which application is using the widget and which of its features are being triggered
268
+ * (e.g. adding a resource, moving the camera). See `RevealWidgetTrackingProps` for the options.
269
+ */
270
+ tracking?: RevealWidgetTrackingProps;
271
+ /** Identifies the host application */
272
+ appIdentifier: string;
131
273
  };
132
274
  export declare const RevealWidget: (props: PropsWithChildren<RevealWidgetProps>) => ReactElement;
package/dist/index.js CHANGED
@@ -1,10 +1,40 @@
1
- import { DefaultNodeAppearance as e } from "@cognite/reveal";
2
- import { RevealWidget as t } from "@cognite/reveal-components/ui/components";
3
- //#region libs/shared/reveal-widget/src/index.ts
4
- var n = { Highlighted: {
5
- cad: e.Highlighted,
6
- pointcloud: e.Highlighted,
7
- image360: e.Highlighted
8
- } }, r = t;
9
- //#endregion
10
- export { n as Default3DStyles, r as RevealWidget };
1
+ import { DefaultNodeAppearance } from "@cognite/reveal";
2
+ import { RevealWidget as RevealWidgetComponent } from "@cognite/reveal-components/ui/components";
3
+ /**
4
+ * Public API surface for the standalone `@cognite/reveal-widget` npm package.
5
+ *
6
+ * `RevealWidget` here is the real, unmodified implementation from
7
+ * `@cognite/reveal-components` — there is no runtime wrapper. `@cognite/reveal-components`
8
+ * is a `dependencies` entry, so it and its own published dependencies (`@cognite/signal-utils`,
9
+ * `@cognite/underscore`) are treated as external. The resource/identifier types above are
10
+ * re-exported directly from `@cognite/reveal-components`'s narrow, already-subpath-exported
11
+ * type barrels (`./data-providers/types`, `./utilities/modelIds`, `./utilities`), which an
12
+ * external consumer resolves normally since that package is published.
13
+ *
14
+ * `Reveal3DResourceHandle`, `RevealWidgetController`, `RevealWidgetCameraController`, `RevealWidgetAssets`, `RevealWidgetHtmlOverlays`, and
15
+ * `RevealWidgetProps` below are still hand-declared, because their real counterparts (only
16
+ * reachable via the entangled `./ui/components` export) expose `RevealDomainObject`/
17
+ * `SceneDomainObject` directly in their signatures — too large for API Extractor's type bundler
18
+ * and not meaningful for an external consumer anyway. `src/index.test.ts` has compile-time-only
19
+ * (`// @ts-expect-error`-driven) tests asserting these hand-written types stay structurally
20
+ * compatible with the real implementation — update both together when the real API changes.
21
+ * `RevealWidgetTrackingProps` (and its arms) don't have this problem — they only reference
22
+ * `UsageMetricsTracker`, so they're imported and re-exported directly from `./ui/components`
23
+ * rather than hand-declared.
24
+ *
25
+ * `tracking`/`appIdentifier` (on `RevealWidgetProps`) plumb through to the real `RevealWidget`'s
26
+ * usage-tracking seam, which reports to a dedicated, named `mixpanel-browser` instance *by
27
+ * default* — not Fusion's own `@cognite/metrics`/Mixpanel setup, since `@cognite/reveal-widget`
28
+ * is also consumed outside this monorepo. Pass `tracking: { disabled: true }` to opt out
29
+ * entirely, or `tracking: { mixpanelToken }` (with `appIdentifier`) to report to your own
30
+ * Mixpanel project instead.
31
+ */ export const Default3DStyles = {
32
+ Highlighted: {
33
+ cad: DefaultNodeAppearance.Highlighted,
34
+ pointcloud: DefaultNodeAppearance.Highlighted,
35
+ image360: DefaultNodeAppearance.Highlighted
36
+ }
37
+ };
38
+ export const RevealWidget = RevealWidgetComponent;
39
+
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { PropsWithChildren, ReactElement } from 'react';\n\nimport type {\n CameraState,\n Cognite3DViewerOptions,\n NodeAppearance,\n} from '@cognite/reveal';\nimport { DefaultNodeAppearance } from '@cognite/reveal';\nimport type {\n DmsUniqueIdentifier,\n ExternalId,\n Space,\n} from '@cognite/reveal-components/data-providers';\nimport type { AssetId } from '@cognite/reveal-components/data-providers/cache';\nimport type {\n AddReveal3DResource,\n AllResourceIdentifier,\n BaseAddOptions,\n CadAddOptions,\n NewCadModelStyling as CadModelStyling,\n CadResourceIdentifier,\n Classic3DResourceIdentifier,\n DM3DResourceIdentifier,\n Image360AddOptions,\n Image360DMResourceIdentifier,\n Image360EventsResourceIdentifier,\n Image360IconCullingOptions,\n Image360ResourceIdentifier,\n PointCloudAddOptions,\n PointCloudResourceIdentifier,\n SceneAddOptions,\n SceneResourceIdentifier,\n ThreeDResourceIdentifier,\n} from '@cognite/reveal-components/data-providers/types';\nimport {\n RevealWidget as RevealWidgetComponent,\n type RevealWidgetTrackingProps,\n} from '@cognite/reveal-components/ui/components';\nimport type {\n InstanceId,\n UsageMetricsTracker,\n} from '@cognite/reveal-components/utilities';\nimport type { InstanceStylingGroup } from '@cognite/reveal-components/utilities/modelIds';\nimport type { TreeIndexStylingGroup } from '@cognite/reveal-components/utilities/styling';\n\nexport type {\n AddReveal3DResource,\n AllResourceIdentifier,\n AssetId,\n BaseAddOptions,\n CadAddOptions,\n CadModelStyling,\n CadResourceIdentifier,\n Classic3DResourceIdentifier,\n DM3DResourceIdentifier,\n DmsUniqueIdentifier,\n ExternalId,\n Image360AddOptions,\n Image360DMResourceIdentifier,\n Image360EventsResourceIdentifier,\n Image360IconCullingOptions,\n Image360ResourceIdentifier,\n InstanceId,\n InstanceStylingGroup,\n UsageMetricsTracker,\n PointCloudAddOptions,\n PointCloudResourceIdentifier,\n RevealWidgetTrackingProps,\n SceneAddOptions,\n SceneResourceIdentifier,\n Space,\n ThreeDResourceIdentifier,\n TreeIndexStylingGroup,\n};\n\n/**\n * Public API surface for the standalone `@cognite/reveal-widget` npm package.\n *\n * `RevealWidget` here is the real, unmodified implementation from\n * `@cognite/reveal-components` — there is no runtime wrapper. `@cognite/reveal-components`\n * is a `dependencies` entry, so it and its own published dependencies (`@cognite/signal-utils`,\n * `@cognite/underscore`) are treated as external. The resource/identifier types above are\n * re-exported directly from `@cognite/reveal-components`'s narrow, already-subpath-exported\n * type barrels (`./data-providers/types`, `./utilities/modelIds`, `./utilities`), which an\n * external consumer resolves normally since that package is published.\n *\n * `Reveal3DResourceHandle`, `RevealWidgetController`, `RevealWidgetCameraController`, `RevealWidgetAssets`, `RevealWidgetHtmlOverlays`, and\n * `RevealWidgetProps` below are still hand-declared, because their real counterparts (only\n * reachable via the entangled `./ui/components` export) expose `RevealDomainObject`/\n * `SceneDomainObject` directly in their signatures — too large for API Extractor's type bundler\n * and not meaningful for an external consumer anyway. `src/index.test.ts` has compile-time-only\n * (`// @ts-expect-error`-driven) tests asserting these hand-written types stay structurally\n * compatible with the real implementation — update both together when the real API changes.\n * `RevealWidgetTrackingProps` (and its arms) don't have this problem — they only reference\n * `UsageMetricsTracker`, so they're imported and re-exported directly from `./ui/components`\n * rather than hand-declared.\n *\n * `tracking`/`appIdentifier` (on `RevealWidgetProps`) plumb through to the real `RevealWidget`'s\n * usage-tracking seam, which reports to a dedicated, named `mixpanel-browser` instance *by\n * default* — not Fusion's own `@cognite/metrics`/Mixpanel setup, since `@cognite/reveal-widget`\n * is also consumed outside this monorepo. Pass `tracking: { disabled: true }` to opt out\n * entirely, or `tracking: { mixpanelToken }` (with `appIdentifier`) to report to your own\n * Mixpanel project instead.\n */\nexport const Default3DStyles: {\n Highlighted: {\n cad: NodeAppearance;\n pointcloud: NodeAppearance;\n image360: NodeAppearance;\n };\n} = {\n Highlighted: {\n cad: DefaultNodeAppearance.Highlighted,\n pointcloud: DefaultNodeAppearance.Highlighted,\n image360: DefaultNodeAppearance.Highlighted,\n },\n};\n\n/**\n * A narrow, external-facing view of a loaded 3D resource (CAD model, point cloud, image360\n * collection, or scene). This is a type-only narrowing — the actual object returned at runtime\n * by `addResource()`/`getModels()` is still the real `RevealDomainObject`/`SceneDomainObject`.\n * Only `.remove()` is published here to keep the exported type surface minimal.\n */\nexport type Reveal3DResourceHandle = {\n remove(): boolean;\n};\n\n/**\n * A scene that can be loaded for a location, and the (sub-)location it is\n * configured on.\n */\nexport type LocationSceneCandidate = {\n scene: DmsUniqueIdentifier;\n locationName: string;\n};\n\n/**\n * Outcome of `RevealWidgetController.addResourceByLocation`:\n * - `loaded`: the scene was added to the widget\n * - `selection-required`: the location has several scenes (its own and those of\n * its sub-locations); nothing was loaded, call again with the chosen scene\n * - `not-found`: no such location, or it has no scene\n */\nexport type AddResourceByLocationResult =\n | SceneLoadedForLocation\n | SceneSelectionRequiredForLocation\n | SceneNotFoundForLocation;\n\nexport type SceneLoadedForLocation = {\n status: 'loaded';\n scene: Reveal3DResourceHandle;\n};\n\nexport type SceneSelectionRequiredForLocation = {\n status: 'selection-required';\n candidates: LocationSceneCandidate[];\n};\n\nexport type SceneNotFoundForLocation = { status: 'not-found' };\n\n/**\n * An asset that is mapped to a loaded 3D model.\n */\nexport type MappedAsset = {\n name: string;\n description?: string;\n /** Pass to `styleByInstance` / `focusInstances` to highlight or zoom to the asset */\n instanceId: InstanceId;\n};\n\n/**\n * Options for `RevealWidgetAssets.searchMappedAssets`.\n */\nexport type SearchMappedAssetsOptions = {\n /**\n * Free-text search on the asset name and description. Not guaranteed to\n * return all matching assets.\n */\n query?: string;\n /** Maximum number of assets to return (default 100, maximum 1000) */\n limit?: number;\n};\n\n/**\n * Result of `RevealWidgetAssets.searchMappedAssets`.\n */\nexport type SearchMappedAssetsResult = {\n assets: MappedAsset[];\n /**\n * True if there may be more matching assets than were returned. Pagination is\n * not supported, so use `query` to narrow down the search.\n */\n hasMore: boolean;\n};\n\n/**\n * Search for the assets mapped to the models in the widget.\n */\nexport type RevealWidgetAssets = {\n /**\n * Search the core data model assets that are mapped to the visible CAD models,\n * point clouds and data model 360 image collections, including those of a\n * loaded scene. Only data modeling assets are searched, never classic assets,\n * so this is intended for data-modeling-only projects. Use the returned\n * `instanceId`s with `styleByInstance` and `focusInstances` to highlight an\n * asset and zoom to it.\n */\n searchMappedAssets(\n options?: SearchMappedAssetsOptions\n ): Promise<SearchMappedAssetsResult>;\n};\n\n/**\n * A position in the CDF coordinate system, i.e. the one the coordinates of\n * CDF 3D models and their assets are given in\n */\nexport type HtmlOverlayPosition = { x: number; y: number; z: number };\n\n/**\n * A handle to an HTML overlay added to the widget\n */\nexport type HtmlOverlayHandle = {\n /**\n * Removes the overlay's element from the widget. Does nothing if\n * it has already been removed.\n */\n remove(): void;\n};\n\n/**\n * Attaching HTML elements to positions in the 3D scene of the widget,\n * e.g. to show notifications.\n */\nexport type RevealWidgetHtmlOverlays = {\n /**\n * Attaches an HTML element to a position in the scene. The element follows the\n * position as the camera moves, and is hidden while the position is not in view.\n *\n * The widget sets `position: absolute` on the element, which the overlay requires.\n * Styling such as `transform: translate(-50%, -50%)` to center the element on the\n * position, and `pointer-events: none` to not interfere with camera navigation,\n * is up to the caller.\n *\n * ```\n * const overlay = controller.htmlOverlays.add(element, { x: 10, y: 20, z: 5 });\n *\n * // during cleanup:\n * overlay.remove();\n * ```\n *\n * @param element The element to attach. Adding the same element again moves it.\n * @param position The position in CDF coordinates\n */\n add(element: HTMLElement, position: HtmlOverlayPosition): HtmlOverlayHandle;\n /**\n * Removes all the overlays added to the widget\n */\n clear(): void;\n /**\n * Hides or shows all the overlays, including ones added later. They are visible by default.\n */\n setVisible(visible: boolean): void;\n};\n\nexport type RevealWidgetCameraController = {\n /**\n * Focus all visible models in the scene\n */\n focusCameraAll(): void;\n /**\n * Focus on a single given 3D model\n */\n focusModel(handle: Reveal3DResourceHandle): void;\n /**\n * Returns the state of the camera in the Reveal viewer\n */\n getCameraState(): Required<CameraState>;\n /**\n * Sets the state of the camera\n */\n setCameraState(cameraState: CameraState): void;\n enterNearby360Image(): Promise<void> | undefined;\n};\n\nexport type RevealWidgetController = {\n /**\n * Access the RevealWidgetCameraController for camera controls\n */\n readonly cameraController: RevealWidgetCameraController;\n /**\n * Access the RevealWidgetAssets for searching the assets mapped to the models\n */\n readonly assets: RevealWidgetAssets;\n /**\n * Access the RevealWidgetHtmlOverlays for attaching HTML elements to positions in the scene\n */\n readonly htmlOverlays: RevealWidgetHtmlOverlays;\n /**\n * Add a 3D resource (i.e. model or scene) to the widget.\n * Added resources can be removed by calling their `.remove` method.\n */\n addResource(resource: AllResourceIdentifier): Promise<Reveal3DResourceHandle>;\n /**\n * Load a scene from a location (matched by external ID or name). If the\n * location, including its sub-locations, has exactly one scene it is loaded.\n * If it has several, nothing is loaded and the candidates are returned so the\n * caller can ask the user to pick one, then call this method again with\n * `selectedScene`.\n */\n addResourceByLocation(\n location: string,\n selectedScene?: DmsUniqueIdentifier\n ): Promise<AddResourceByLocationResult>;\n /**\n * Get all models added to the RevealWidget\n */\n getModels(): Reveal3DResourceHandle[];\n /**\n * Get all models added to the RevealWidget that are visible\n */\n getVisibleModels(): Reveal3DResourceHandle[];\n /**\n * Style the provided instances with the associated styles in the given models, if\n * the instances are contextualized to the models\n */\n styleByInstance(\n instanceStylingGroups: InstanceStylingGroup[],\n handles: Reveal3DResourceHandle[]\n ): Promise<void>;\n /**\n * Moves the camera to show the provided instances in the visible models in the scene.\n */\n focusInstances(instances: InstanceId[]): Promise<void>;\n};\n\nexport type RevealWidgetProps = {\n /**\n * Defines the initialization options for the RevealWidget, including the SDK and data modeling status\n * The user can either specify these separately, or opt for the object\n * `{ inheritFromRevealContext: true }`, in which case the Widget will assume the existence of\n * a `RevealContext` mounted above it in the hierarchy.\n */\n viewerOptions:\n | (Pick<Cognite3DViewerOptions, 'sdk' | 'onLoading'> & {\n useCoreDm: boolean;\n })\n | {\n /**\n * Disables the RevealWidget's own RevealContext, relying on one defined in the application\n * layer instead.\n */\n inheritFromRevealContext: true;\n };\n /**\n * The widget uses this to set a reference to the widget controller.\n * The widget calls this with `undefined` when the component unmounts or this callback changes\n */\n setControllerRef?: (controller: RevealWidgetController | undefined) => void;\n /**\n * Reports which application is using the widget and which of its features are being triggered\n * (e.g. adding a resource, moving the camera). See `RevealWidgetTrackingProps` for the options.\n */\n tracking?: RevealWidgetTrackingProps;\n /** Identifies the host application */\n appIdentifier: string;\n};\n\nexport const RevealWidget: (\n props: PropsWithChildren<RevealWidgetProps>\n) => ReactElement = RevealWidgetComponent;\n"],"names":["DefaultNodeAppearance","RevealWidget","RevealWidgetComponent","Default3DStyles","Highlighted","cad","pointcloud","image360"],"mappings":"AAOA,SAASA,qBAAqB,QAAQ,kBAAkB;AA2BxD,SACEC,gBAAgBC,qBAAqB,QAEhC,2CAA2C;AAsClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BC,GACD,OAAO,MAAMC,kBAMT;IACFC,aAAa;QACXC,KAAKL,sBAAsBI,WAAW;QACtCE,YAAYN,sBAAsBI,WAAW;QAC7CG,UAAUP,sBAAsBI,WAAW;IAC7C;AACF,EAAE;AA4PF,OAAO,MAAMH,eAEOC,sBAAsB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cognite/reveal-widget",
3
- "version": "0.3.0",
3
+ "version": "1.48535.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -18,30 +18,35 @@
18
18
  "@base-ui/react": "^1.6.0",
19
19
  "@floating-ui/react": "^0.24.8",
20
20
  "@tabler/icons-react": "^3.35.0",
21
- "@tanstack/react-query": "^4.43.0",
21
+ "@tanstack/react-query": "^5.102.8",
22
22
  "dayjs": "^1.11.13",
23
23
  "lodash-es": "^4.18.1",
24
24
  "ml-matrix": "^6.12.1",
25
25
  "random-seed": "^0.3.0",
26
26
  "three": "0.184.0",
27
- "@cognite/reveal-components": "1.0.2",
28
- "@cognite/aura": "0.3.5"
27
+ "@cognite/reveal-components": "1.48535.0",
28
+ "@cognite/aura": "1.48535.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@cognite/reveal": "4.36.0",
32
- "@cognite/sdk": "^10.14.0",
32
+ "@cognite/sdk": "10.17.0",
33
33
  "@microsoft/api-extractor": "^7.58.12",
34
- "@nx/eslint-plugin": "22.7.8",
34
+ "@types/react": "18.3.14",
35
35
  "eslint-plugin-check-file": "^2.7.1",
36
36
  "react": "^18.3.1",
37
37
  "react-dom": "^18.3.1",
38
- "vite": "8.2.2",
38
+ "vite": "8.2.4",
39
39
  "vitest": "^4.1.10"
40
40
  },
41
41
  "peerDependencies": {
42
- "@cognite/reveal": "4.35.3",
43
- "@cognite/sdk": "^10.13.0",
42
+ "@cognite/reveal": "4.36.0",
43
+ "@cognite/sdk": "10.17.0",
44
44
  "react": "^18.3.1",
45
45
  "react-dom": "^18.3.1"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/cognitedata/infrastructure.git",
50
+ "directory": "lib/ts/shared/reveal-widget"
46
51
  }
47
52
  }