@pexip-engage-public/plugin-instance
Advanced tools
Comparing version 1.0.50-canary-20230921163157 to 1.0.50-canary-20230921191855
# @pexip-engage-public/plugin-instance | ||
## 1.0.50-canary-20230921163157 | ||
## 1.0.50-canary-20230921191855 | ||
@@ -9,3 +9,3 @@ ### Patch Changes | ||
- Updated dependencies [9f86bbf] | ||
- @pexip-engage-public/plugin-events@1.0.27-canary-20230921163157 | ||
- @pexip-engage-public/plugin-events@1.0.27-canary-20230921191855 | ||
@@ -12,0 +12,0 @@ ## 1.0.49 |
{ | ||
"name": "@pexip-engage-public/plugin-instance", | ||
"version": "1.0.50-canary-20230921163157", | ||
"version": "1.0.50-canary-20230921191855", | ||
"homepage": "https://github.com/skedify/frontend-mono/tree/develop/apps/plugin-remix/packages/plugin-instance#readme", | ||
@@ -37,3 +37,3 @@ "bugs": { | ||
"@pexip-engage-public/plugin-configuration-parser": "1.1.20", | ||
"@pexip-engage-public/plugin-events": "1.0.27-canary-20230921163157", | ||
"@pexip-engage-public/plugin-events": "1.0.27-canary-20230921191855", | ||
"@pexip-engage-public/plugin-state": "1.1.7", | ||
@@ -40,0 +40,0 @@ "@pexip-engage-public/plugin-utils": "1.0.10" |
@@ -36,3 +36,7 @@ import { | ||
const FRAME_IDENTIFIER = "pexip-engage-plugin-frame"; | ||
window.customElements.define(FRAME_IDENTIFIER, PexipEngagePluginFrame); | ||
if (!window.customElements.get(FRAME_IDENTIFIER)) { | ||
window.customElements.define(FRAME_IDENTIFIER, PexipEngagePluginFrame); | ||
} | ||
export class PluginInstance { | ||
@@ -414,2 +418,33 @@ #instance: IFrameComponent; | ||
static awaitFirstInstance = async () => { | ||
const instance = PluginInstance.getInstance(0); | ||
if (instance) return instance; | ||
return new Promise<PluginInstance>((resolve, reject) => { | ||
function listener(event: Event) { | ||
if (event instanceof CustomEvent) { | ||
if (event.detail.type === PluginInstance.EVENT_CREATION) { | ||
document.removeEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, listener); | ||
return resolve(event.detail.instance); | ||
} else if ( | ||
event.detail.type === PluginInstance.EVENT_MISCONFIGURED || | ||
event.detail.type === PluginInstance.EVENT_ERROR | ||
) { | ||
document.removeEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, listener); | ||
const errorMessage = | ||
typeof event.detail.subtype === "string" | ||
? `${event.detail.type}: ${event.detail.subtype}` | ||
: event.detail.type; | ||
return reject(errorMessage); | ||
} | ||
} | ||
} | ||
document.addEventListener(PEXIP_ENGAGE_PLUGIN_EVENT, listener); | ||
}); | ||
}; | ||
static get count() { | ||
@@ -416,0 +451,0 @@ return PluginInstance.#instances.length; |
@@ -121,2 +121,3 @@ import { parsePluginConfiguration } from "@pexip-engage-public/plugin-configuration-parser"; | ||
static getInstance: (num: unknown) => PluginInstance | undefined; | ||
static awaitFirstInstance: () => Promise<PluginInstance>; | ||
static get count(): number; | ||
@@ -123,0 +124,0 @@ /** @deprecated */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
101586
1424