| 75 | const OPENUI5_POLLING_INTERVAL = 100; |
| 76 | |
| 77 | class OpenUI5Support { |
| 78 | static enablePolling = false; // set to true for old OpenUI5 versions |
| 79 | |
| 80 | static isAtLeastVersion(minor: number) { |
| 81 | if (!window.sap.ui!.version) { |
| 82 | return true; // sap.ui.version will be removed in newer OpenUI5 versions |
| 83 | } |
| 84 | const version = window.sap.ui!.version as string; |
| 85 | const parts = version.split("."); |
| 86 | if (!parts || parts.length < 2) { |
| 87 | return false; |
| 88 | } |
| 89 | return parseInt(parts[0]) > 1 || parseInt(parts[1]) >= minor; |
| 90 | } |
| 91 | |
| 92 | static isOpenUI5Detected() { |
| 93 | return typeof window.sap?.ui?.require === "function"; |
| 94 | } |
| 95 | |
| 96 | static initPromise?: Promise<void>; |
| 97 | |
| 98 | /** |
| 99 | * Important - if OpenUI5 is loaded after UI5 Web Components, configuration is not synchronized and it's up to the app to initialize OpenUI5 with the same settings as UI5 Web Components for consistency. |
| 100 | */ |
| 101 | static OpenUI5DelayedInit = async () => { |
| 102 | OpenUI5Support.init(); // This ensures patchPopover and patchPatcher are called; and from this point OpenUI5 CSS vars start being detected |
| 103 | await secondaryBoot(); // Re-run the parts of boot that were skipped due to OpenUI5 not having been loaded |
| 104 | } |
| 105 | |
| 106 | static awaitForOpenUI5() { |
| 107 | if (OpenUI5Support.enablePolling) { |
| 108 | const interval = setInterval(() => { |
| 109 | if (OpenUI5Support.isOpenUI5Detected()) { |
| 110 | clearInterval(interval); |
| 111 | OpenUI5Support.OpenUI5DelayedInit(); |
| 112 | } |
| 113 | }, OPENUI5_POLLING_INTERVAL); |
| 114 | } else { |
| 115 | document.addEventListener("sap-ui-core-ready", () => { |
| 116 | OpenUI5Support.OpenUI5DelayedInit(); |
| 117 | }); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | static init() { |
| 122 | if (!OpenUI5Support.isOpenUI5Detected()) { |
| 123 | return OpenUI5Support.awaitForOpenUI5(); |
| 124 | } |
| 125 | |
| 126 | if (!OpenUI5Support.initPromise) { |
| 127 | OpenUI5Support.initPromise = new Promise<void>(resolve => { |
| 128 | window.sap.ui.require(["sap/ui/core/Core"], async (Core: OpenUI5Core) => { |
| 129 | const callback = () => { |
| 130 | let deps: Array<string> = ["sap/ui/core/Popup", "sap/m/Dialog", "sap/ui/core/Patcher", "sap/ui/core/LocaleData"]; |
| 131 | if (OpenUI5Support.isAtLeastVersion(116)) { // for versions since 1.116.0 and onward, use the modular core |
| 132 | deps = [ |
| 133 | ...deps, |
| 134 | "sap/base/i18n/Formatting", |
nothing calls this directly
no test coverage detected
searching dependent graphs…