/
ContentControl.tsx
127 lines (110 loc) · 3.8 KB
/
ContentControl.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module ContentView
*/
import * as React from "react";
import type { Id64String } from "@itwin/core-bentley";
import type {
IModelConnection,
ScreenViewport,
ViewState,
} from "@itwin/core-frontend";
import { UiEvent } from "@itwin/appui-abstract";
import {
ConfigurableCreateInfo,
ConfigurableUiControl,
ConfigurableUiControlType,
} from "../configurableui/ConfigurableUiControl";
/** ControlControl Activated Event Args interface.
* @public
*/
export interface ContentControlActivatedEventArgs {
activeContentControl: ContentControl;
oldContentControl?: ContentControl;
}
/** ContentControl Activated Event class.
* @public
*/
// eslint-disable-next-line deprecation/deprecation
export class ContentControlActivatedEvent extends UiEvent<ContentControlActivatedEventArgs> {}
/** Interface to be implemented when the ContentControl supports ViewSelector changes
* @public
*/
export interface SupportsViewSelectorChange {
/** Returns true if this control supports reacting to ViewSelector changes. */
supportsViewSelectorChange: boolean;
/** Process a ViewSelector change. */
processViewSelectorChange(
iModel: IModelConnection,
viewDefinitionId: Id64String,
viewState: ViewState,
name: string
): Promise<void>;
}
/** The base class for Frontstage content controls.
* @public
*/
export class ContentControl extends ConfigurableUiControl {
protected _reactNode: React.ReactNode;
private _keyAdded = false;
/** Creates an instance of ContentControl.
* @param info An object that the subclass must pass to this base class.
* @param options Options provided via the applicationData in a [[ContentProps]].
*/
constructor(info: ConfigurableCreateInfo, options: any) {
super(info, options);
}
/** Called when this ContentControl is activated */
public onActivated(): void {}
/** Called when this ContentControl is deactivated */
public onDeactivated(): void {}
/** Gets the type of ConfigurableUiControl, which is 'Content' in this case */
public getType(): ConfigurableUiControlType {
return ConfigurableUiControlType.Content;
}
/** Returns true if this control is a Viewport control. */
public get isViewport(): boolean {
return false;
}
/** Returns the ScreenViewport if isViewport is true */
public get viewport(): ScreenViewport | undefined {
return undefined;
}
protected getKeyedReactNode(): React.ReactNode {
if (!this._keyAdded && React.isValidElement(this._reactNode)) {
// istanbul ignore else
if (!(this._reactNode as React.ReactElement<any>).key) {
const additionalProps: any = { key: this.uniqueId };
this._reactNode = React.cloneElement(this._reactNode, additionalProps);
}
this._keyAdded = true;
}
return this._reactNode;
}
protected getReactNode(): React.ReactNode {
return this.getKeyedReactNode();
}
/** The React node associated with this control. */
public get reactNode(): React.ReactNode {
return this.getReactNode();
}
public set reactNode(r: React.ReactNode) {
this._reactNode = r;
}
/** Get the NavigationAidControl associated with this ContentControl */
public get navigationAidControl(): string {
return "";
}
}
/**
* @beta
*/
export class FloatingContentControl extends ContentControl {
constructor(uniqueId: string, name: string, node: React.ReactNode) {
super(new ConfigurableCreateInfo(name, uniqueId, name), undefined);
this._reactNode = node;
}
}