@itwin/presentation-components
Version:
React components based on iTwin.js Presentation library
69 lines • 3.08 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.useOptionalUnifiedSelectionContext = useOptionalUnifiedSelectionContext;
const react_1 = require("react");
/**
* A hook that can be used to acquire the unified selection context, coming from the
* optional `@itwin/unified-selection-react` peer dependency.
*
* @internal
*/
function useOptionalUnifiedSelectionContext() {
const [contextGetter, setContextGetter] = (0, react_1.useState)(undefined);
(0, react_1.useEffect)(() => {
void getUnifiedSelectionContextFn().then((fn) => setContextGetter(() => fn));
}, []);
// `contextGetter` internally calls `useContext`, so if we don't have it (yet), call `useContext` with a no-op
// context to avoid React complaints about conditional hooks usage.
// eslint-disable-next-line react-hooks/rules-of-hooks
return contextGetter ? contextGetter() : (0, react_1.useContext)(noopContext);
}
const noopContext = (0, react_1.createContext)(undefined);
async function getUnifiedSelectionContextFn() {
try {
const optionalPkg = await Promise.resolve().then(() => __importStar(require("@itwin/unified-selection-react")));
return optionalPkg.useUnifiedSelectionContext;
/* c8 ignore next 3 */
}
catch {
return undefined;
}
}
//# sourceMappingURL=UnifiedSelection.js.map