UNPKG

@itwin/presentation-components

Version:

React components based on iTwin.js Presentation library

67 lines 3.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NavigationPropertyTargetEditor = exports.NavigationPropertyEditor = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ const react_1 = require("react"); const components_react_1 = require("@itwin/components-react"); const NavigationPropertyTargetSelector_js_1 = require("../inputs/NavigationPropertyTargetSelector.js"); const NavigationPropertyEditorContext_js_1 = require("./NavigationPropertyEditorContext.js"); /** * Editor for navigation properties. * * **Note:** Should be used inside [[navigationPropertyEditorContext]]. * @internal */ class NavigationPropertyEditor extends components_react_1.PropertyEditorBase { /* c8 ignore start */ get containerHandlesEnter() { return false; } get reactNode() { return (0, jsx_runtime_1.jsx)(NavigationPropertyTargetEditor, {}); } } exports.NavigationPropertyEditor = NavigationPropertyEditor; /** * Component that renders navigation property target selector for navigation property value editing. * * **Note:** Should be used inside [[navigationPropertyEditorContext]]. * @internal */ class NavigationPropertyTargetEditor extends react_1.PureComponent { _ref = (0, react_1.createRef)(); /* c8 ignore start */ async getPropertyValue() { return this._ref.current?.getValue(); } get htmlElement() { return this._ref.current?.htmlElement ?? null; } get hasFocus() { if (!this._ref.current?.htmlElement || !document.activeElement) { return false; } return this._ref.current.htmlElement.contains(document.activeElement); } /* c8 ignore end */ render() { return (0, jsx_runtime_1.jsx)(NavigationPropertyTargetEditorInner, { ref: this._ref, ...this.props }); } } exports.NavigationPropertyTargetEditor = NavigationPropertyTargetEditor; const NavigationPropertyTargetEditorInner = (0, react_1.forwardRef)((props, ref) => { const context = (0, NavigationPropertyEditorContext_js_1.useNavigationPropertyEditorContext)(); if (!props.propertyRecord) { return null; } if (!context) { return (0, jsx_runtime_1.jsx)(NavigationPropertyTargetSelector_js_1.ReadonlyNavigationPropertyTarget, { record: props.propertyRecord }); } return ((0, jsx_runtime_1.jsx)(NavigationPropertyTargetSelector_js_1.NavigationPropertyTargetSelector, { ...props, ref: ref, imodel: context.imodel, getNavigationPropertyInfo: context.getNavigationPropertyInfo, propertyRecord: props.propertyRecord })); }); NavigationPropertyTargetEditorInner.displayName = "NavigationPropertyTargetEditorInner"; //# sourceMappingURL=NavigationPropertyEditor.js.map