UNPKG

apiconnect-explorer

Version:

- [Getting Started](#getting-started) - [Configuration](#configuration) * [Required](#required) * [Optional](#optional) - [Usage in React](#usage-in-react) - [Usage outside of React](#usage-outside-of-react) - [Detailed description of options](#detail

1 lines 1.73 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=h;var a=require("react"),b="apiConnectExplorer.theme",c=["theme-white","theme-g10","theme-g90","theme-g100"];function d(){try{var a=window.apiConnectExplorer&&window.apiConnectExplorer.attachPoint;if(a)if("string"==typeof a){var b=document.querySelector(a)||document.getElementById(a.replace(/^#/,""));if(b)return b}else if(a instanceof HTMLElement)return a}catch(a){console.error("Error getting attachPoint for ThemeSync:",a)}return document.querySelector("apiconnect-explorer")||document.getElementById("apiconnect-explorer")||document.querySelector(".apiconnect-explorer-root")}function f(a){try{var b=d();if(!b)return;c.forEach(function(a){return b.classList.remove(a)}),a&&"white"!==a&&"g10"!==a?("g90"===a||"g100"===a)&&b.classList.add("theme-g90"):b.classList.add("theme-white")}catch(a){console.error("Error applying theme class to root:",a)}}function g(a){try{window.apiConnectExplorer=window.apiConnectExplorer||{},window.apiConnectExplorer.options=window.apiConnectExplorer.options||{},window.apiConnectExplorer.options.theme=a}catch(a){}}function h(){return(0,a.useEffect)(function(){function a(a){if(a.key===b){var c=a.newValue;g(c),f(c)}}function c(a){var b,c,d=(null===a||void 0===a||null===(b=a.detail)||void 0===b?void 0:b.theme)||(null===(c=window.apiConnectExplorer)||void 0===c||null===(c=c.options)||void 0===c?void 0:c.theme);d&&(g(d),f(d))}try{var d=localStorage.getItem(b);d&&(g(d),f(d))}catch(a){}return window.addEventListener("storage",a),window.addEventListener("apiConnectExplorerUpdate",c),function(){window.removeEventListener("storage",a),window.removeEventListener("apiConnectExplorerUpdate",c)}},[]),null}