@myop/sdk 0.2.6 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/bundled-declarations.d.ts +92 -7
- package/dist/cjs/{_IframeSDK.2793f0c2.js → _IframeSDK.3a01f95a.js} +192 -34
- package/dist/cjs/_IframeSDK.3a01f95a.js.map +7 -0
- package/dist/cjs/_IframeSDK.75aeb332.min.js +1 -0
- package/dist/cjs/{_MyopHelpers.7baba8b8.js → _MyopHelpers.02c01d3a.js} +96 -11
- package/dist/cjs/{_MyopHelpers.7baba8b8.js.map → _MyopHelpers.02c01d3a.js.map} +3 -3
- package/dist/cjs/_MyopHelpers.abd584e8.min.js +1 -0
- package/dist/cjs/{_WebComponentSDK.ba6c3d1b.js → _WebComponentSDK.abdb86a3.js} +192 -34
- package/dist/cjs/_WebComponentSDK.abdb86a3.js.map +7 -0
- package/dist/cjs/_WebComponentSDK.e345ed2a.min.js +1 -0
- package/dist/cjs/_hostSDK.881787f6.min.js +1 -0
- package/dist/cjs/{_hostSDK.71e17cf2.js → _hostSDK.9dbd966e.js} +192 -34
- package/dist/cjs/_hostSDK.9dbd966e.js.map +7 -0
- package/dist/cjs/myop_sdk.js +14 -14
- package/dist/cjs/myop_sdk.js.map +1 -1
- package/dist/cjs/myop_sdk.min.js +1 -1
- package/dist/cjs-bundled/myop_sdk.bundled.js +202 -36
- package/dist/cjs-bundled/myop_sdk.bundled.js.map +3 -3
- package/dist/cjs-bundled/myop_sdk.bundled.min.js +1 -1
- package/dist/module/Iframe/index.js +224 -69
- package/dist/module/Iframe/index.js.map +3 -3
- package/dist/module/SDK.js +226 -70
- package/dist/module/SDK.js.map +2 -2
- package/dist/module/helpers/CloudRepository.d.ts +15 -6
- package/dist/module/helpers/index.js +97 -12
- package/dist/module/helpers/index.js.map +3 -3
- package/dist/module/host/components/IMyopComponent.d.ts +43 -0
- package/dist/module/host/components/myopIframeComponent.d.ts +8 -1
- package/dist/module/host/components/myopRefComponent.d.ts +2 -2
- package/dist/module/host/embeddedSDK.d.ts +23 -0
- package/dist/module/host/index.d.ts +1 -0
- package/dist/module/host/index.js +224 -69
- package/dist/module/host/index.js.map +3 -3
- package/dist/module/webcomponent/index.js +224 -69
- package/dist/module/webcomponent/index.js.map +3 -3
- package/package.json +1 -1
- package/dist/cjs/_IframeSDK.2793f0c2.js.map +0 -7
- package/dist/cjs/_IframeSDK.fb84c8eb.min.js +0 -1
- package/dist/cjs/_MyopHelpers.3d50ac48.min.js +0 -1
- package/dist/cjs/_WebComponentSDK.0fee50b6.min.js +0 -1
- package/dist/cjs/_WebComponentSDK.ba6c3d1b.js.map +0 -7
- package/dist/cjs/_hostSDK.159c1adb.min.js +0 -1
- package/dist/cjs/_hostSDK.71e17cf2.js.map +0 -7
package/README.md
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
13
|
<p align="center">
|
|
14
|
-
<a href="https://www.npmjs.com/package/@myop/sdk"><img src="https://img.shields.io/npm/v/@myop/sdk.svg?style=flat-square" alt="npm version"
|
|
15
|
-
<a href="https://www.npmjs.com/package/@myop/sdk"><img src="https://img.shields.io/npm/dm/@myop/sdk.svg?style=flat-square" alt="npm downloads"
|
|
16
|
-
<a href="https://myop.dev/discord"><img src="https://img.shields.io/badge/Discord-Join%20Us-7289da?style=flat-square&logo=discord&logoColor=white" alt="Discord"
|
|
14
|
+
<a href="https://www.npmjs.com/package/@myop/sdk"><img src="https://img.shields.io/npm/v/@myop/sdk.svg?style=flat-square" alt="npm version" /></a>
|
|
15
|
+
<a href="https://www.npmjs.com/package/@myop/sdk"><img src="https://img.shields.io/npm/dm/@myop/sdk.svg?style=flat-square" alt="npm downloads" /></a>
|
|
16
|
+
<a href="https://myop.dev/discord"><img src="https://img.shields.io/badge/Discord-Join%20Us-7289da?style=flat-square&logo=discord&logoColor=white" alt="Discord" /></a>
|
|
17
17
|
</p>
|
|
18
18
|
|
|
19
19
|
<p align="center">
|
|
@@ -576,6 +576,7 @@ declare module "@myop/sdk/host" {
|
|
|
576
576
|
export * from "@myop/sdk/host/components/IMyopComponent";
|
|
577
577
|
export * from "@myop/sdk/host/loaders/IMyopLoader";
|
|
578
578
|
export * from "@myop/sdk/host/componentCore";
|
|
579
|
+
export type { CleanupHandler } from "@myop/sdk/common";
|
|
579
580
|
}
|
|
580
581
|
declare module "@myop/sdk/messages/BaseMessage" {
|
|
581
582
|
import { MyopMessageKey } from "@myop/sdk/common/MyopMessages";
|
|
@@ -914,6 +915,42 @@ declare module "@myop/sdk/host/components/IMyopComponent" {
|
|
|
914
915
|
import { BaseMyopMessage, Ref } from "@myop/sdk/messages";
|
|
915
916
|
import { CleanupHandler, IComponentDefinitionConfig } from "@myop/sdk/common";
|
|
916
917
|
import { loaderOptions } from "@myop/sdk/host/hostSDK";
|
|
918
|
+
/**
|
|
919
|
+
* Result returned by observeAutoSize callback
|
|
920
|
+
*/
|
|
921
|
+
export interface AutoSizeResult {
|
|
922
|
+
/** Current width (from content) */
|
|
923
|
+
width: number;
|
|
924
|
+
/** Current height (from content) */
|
|
925
|
+
height: number;
|
|
926
|
+
/** Whether width is being auto-sized */
|
|
927
|
+
autoSizingWidth: boolean;
|
|
928
|
+
/** Whether height is being auto-sized */
|
|
929
|
+
autoSizingHeight: boolean;
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Options for observeAutoSize method
|
|
933
|
+
*/
|
|
934
|
+
export interface AutoSizeOptions {
|
|
935
|
+
/** Callback called with size info whenever size changes */
|
|
936
|
+
onSizeChange?: (result: AutoSizeResult) => void;
|
|
937
|
+
/** Minimum width constraint */
|
|
938
|
+
minWidth?: number | string;
|
|
939
|
+
/** Maximum width constraint */
|
|
940
|
+
maxWidth?: number | string;
|
|
941
|
+
/** Minimum height constraint */
|
|
942
|
+
minHeight?: number | string;
|
|
943
|
+
/** Maximum height constraint */
|
|
944
|
+
maxHeight?: number | string;
|
|
945
|
+
/** Explicit width set by host - if defined, don't auto-size width */
|
|
946
|
+
explicitWidth?: string | number;
|
|
947
|
+
/** Explicit height set by host - if defined, don't auto-size height */
|
|
948
|
+
explicitHeight?: string | number;
|
|
949
|
+
/** Force auto-size even if container has dimensions */
|
|
950
|
+
forceAutoSize?: boolean;
|
|
951
|
+
/** Min height used by loader to detect collapse (default: 50) */
|
|
952
|
+
loaderMinHeight?: number;
|
|
953
|
+
}
|
|
917
954
|
type RefTypes = {
|
|
918
955
|
[key: string]: IMyopComponent | Ref;
|
|
919
956
|
};
|
|
@@ -934,6 +971,13 @@ declare module "@myop/sdk/host/components/IMyopComponent" {
|
|
|
934
971
|
hide(): void;
|
|
935
972
|
show(): void;
|
|
936
973
|
inspect(): void;
|
|
974
|
+
/**
|
|
975
|
+
* Observes the iframe content size and automatically syncs it to the iframe element.
|
|
976
|
+
* Only available for iframe-based components. Uses direct contentDocument access.
|
|
977
|
+
* @param options - Configuration options including size change callback and min/max constraints
|
|
978
|
+
* @returns Cleanup function to stop observing
|
|
979
|
+
*/
|
|
980
|
+
observeAutoSize?: (options?: AutoSizeOptions) => CleanupHandler;
|
|
937
981
|
parent?: IMyopComponent;
|
|
938
982
|
props: P;
|
|
939
983
|
refs: R;
|
|
@@ -983,7 +1027,7 @@ declare module "@myop/sdk/host/loaders/IMyopLoader" {
|
|
|
983
1027
|
}
|
|
984
1028
|
}
|
|
985
1029
|
declare module "@myop/sdk/host/components/myopIframeComponent" {
|
|
986
|
-
import { BaseMyopComponent } from "@myop/sdk/host/components/IMyopComponent";
|
|
1030
|
+
import { AutoSizeOptions, BaseMyopComponent } from "@myop/sdk/host/components/IMyopComponent";
|
|
987
1031
|
import { BaseMyopMessage } from "@myop/sdk/messages";
|
|
988
1032
|
import { CleanupHandler, IComponentDefinitionConfig, ISkinConfig } from "@myop/sdk/common";
|
|
989
1033
|
import { loaderOptions } from "@myop/sdk/host/hostSDK";
|
|
@@ -998,6 +1042,13 @@ declare module "@myop/sdk/host/components/myopIframeComponent" {
|
|
|
998
1042
|
show(): void;
|
|
999
1043
|
setHeightBasedOnDocumentElement: () => void;
|
|
1000
1044
|
observeSizeBasedOnDocumentElement: () => CleanupHandler;
|
|
1045
|
+
/**
|
|
1046
|
+
* Observes the iframe content size and automatically syncs it to the iframe element.
|
|
1047
|
+
* Uses direct contentDocument access (same-origin only) for accurate measurements.
|
|
1048
|
+
* @param options - Configuration options including size change callback and min/max constraints
|
|
1049
|
+
* @returns Cleanup function to stop observing
|
|
1050
|
+
*/
|
|
1051
|
+
observeAutoSize: (options?: AutoSizeOptions) => CleanupHandler;
|
|
1001
1052
|
setSizeBasedOnDocumentElement: () => void;
|
|
1002
1053
|
setHeightBasedOnScrollHeight: () => void;
|
|
1003
1054
|
send: (message: BaseMyopMessage) => CleanupHandler;
|
|
@@ -1369,6 +1420,31 @@ declare module "@myop/sdk/webcomponent/WebComponentSDK" {
|
|
|
1369
1420
|
declare module "@myop/sdk/webcomponent" {
|
|
1370
1421
|
export * from "@myop/sdk/webcomponent/WebComponentSDK";
|
|
1371
1422
|
}
|
|
1423
|
+
declare module "@myop/sdk/host/embeddedSDK" {
|
|
1424
|
+
/**
|
|
1425
|
+
* Embedded SDK Content Module
|
|
1426
|
+
*
|
|
1427
|
+
* This module provides the embedded SDK content for npm package users.
|
|
1428
|
+
* The actual content is generated at build time by scripts/build-embedded-sdk.js
|
|
1429
|
+
*
|
|
1430
|
+
* For development, this file exports placeholders.
|
|
1431
|
+
* After build, the dist/module/embeddedSDK.js will contain the actual SDK content.
|
|
1432
|
+
*
|
|
1433
|
+
* Usage in HTMLComponentLoader:
|
|
1434
|
+
* - If HAS_EMBEDDED_SDK is true, inject SDK inline: <script>${EMBEDDED_SDK_CONTENT}</script>
|
|
1435
|
+
* - If HAS_EMBEDDED_SDK is false, fall back to CDN: <script src="${url}"></script>
|
|
1436
|
+
*/
|
|
1437
|
+
/**
|
|
1438
|
+
* The embedded SDK content as a minified JavaScript string.
|
|
1439
|
+
* This placeholder will be replaced with actual content in the build output.
|
|
1440
|
+
*/
|
|
1441
|
+
export const EMBEDDED_SDK_CONTENT: string;
|
|
1442
|
+
/**
|
|
1443
|
+
* Flag indicating whether embedded SDK content is available.
|
|
1444
|
+
* This is false in development, true in the built module.
|
|
1445
|
+
*/
|
|
1446
|
+
export const HAS_EMBEDDED_SDK: boolean;
|
|
1447
|
+
}
|
|
1372
1448
|
declare module "@myop/sdk/host/loaders/HTMLComponentLoader" {
|
|
1373
1449
|
import { MyopWebComponent } from "@myop/sdk/host/components/myopWebcomponent";
|
|
1374
1450
|
import { BaseMyopLoader } from "@myop/sdk/host/loaders/IMyopLoader";
|
|
@@ -1436,7 +1512,7 @@ declare module "@myop/sdk/helpers/configBuilder" {
|
|
|
1436
1512
|
}
|
|
1437
1513
|
}
|
|
1438
1514
|
declare module "@myop/sdk/helpers/CloudRepository" {
|
|
1439
|
-
import {
|
|
1515
|
+
import { IComponentConfig, IUserFlow } from "@myop/sdk/common";
|
|
1440
1516
|
/**
|
|
1441
1517
|
* CloudRepository - Unified cloud data access layer for Myop components
|
|
1442
1518
|
*
|
|
@@ -1449,26 +1525,35 @@ declare module "@myop/sdk/helpers/CloudRepository" {
|
|
|
1449
1525
|
static Main: CloudRepository;
|
|
1450
1526
|
private variants;
|
|
1451
1527
|
private userFlows;
|
|
1528
|
+
private _defaultEnv;
|
|
1452
1529
|
constructor(_baseUrl?: string);
|
|
1530
|
+
/**
|
|
1531
|
+
* Set the default environment for this CloudRepository instance
|
|
1532
|
+
*/
|
|
1533
|
+
setEnvironment(env: string): void;
|
|
1534
|
+
/**
|
|
1535
|
+
* Get the current default environment
|
|
1536
|
+
*/
|
|
1537
|
+
getDefaultEnvironment(): string;
|
|
1453
1538
|
/**
|
|
1454
1539
|
* Check if a component is already cached/preloaded (v2)
|
|
1455
1540
|
*/
|
|
1456
|
-
isPreloaded(componentId: string): boolean;
|
|
1541
|
+
isPreloaded(componentId: string, env?: string, preview?: boolean): boolean;
|
|
1457
1542
|
/**
|
|
1458
|
-
* Fetch a v2 component
|
|
1543
|
+
* Fetch a v2 component config
|
|
1459
1544
|
*/
|
|
1460
|
-
fetchComponentV2(componentId: string, environmentIdentifier?: string): Promise<
|
|
1545
|
+
fetchComponentV2(componentId: string, environmentIdentifier?: string, preview?: boolean): Promise<IComponentConfig>;
|
|
1461
1546
|
/**
|
|
1462
1547
|
* Fetch a v1 component from a flow
|
|
1463
1548
|
*/
|
|
1464
|
-
fetchComponentV1(componentId: string, flowId?: string): Promise<
|
|
1549
|
+
fetchComponentV1(componentId: string, flowId?: string): Promise<IComponentConfig>;
|
|
1465
1550
|
fetchAutoFlow(componentId: string): Promise<IUserFlow>;
|
|
1466
1551
|
fetchFlow(flowId: string): Promise<IUserFlow>;
|
|
1467
1552
|
/**
|
|
1468
1553
|
* @deprecated Use fetchComponentV2 or fetchComponentV1 explicitly
|
|
1469
1554
|
* Defaults to v1 behavior for backward compatibility with existing code
|
|
1470
1555
|
*/
|
|
1471
|
-
fetchComponent(componentId: string, flowId?: string): Promise<
|
|
1556
|
+
fetchComponent(componentId: string, flowId?: string): Promise<IComponentConfig>;
|
|
1472
1557
|
}
|
|
1473
1558
|
/**
|
|
1474
1559
|
* @deprecated Use CloudRepository instead
|
|
@@ -1467,6 +1467,83 @@ var MyopIframeComponent = class extends BaseMyopComponent {
|
|
|
1467
1467
|
}));
|
|
1468
1468
|
return cleanupHandler;
|
|
1469
1469
|
});
|
|
1470
|
+
/**
|
|
1471
|
+
* Observes the iframe content size and automatically syncs it to the iframe element.
|
|
1472
|
+
* Uses direct contentDocument access (same-origin only) for accurate measurements.
|
|
1473
|
+
* @param options - Configuration options including size change callback and min/max constraints
|
|
1474
|
+
* @returns Cleanup function to stop observing
|
|
1475
|
+
*/
|
|
1476
|
+
__publicField(this, "observeAutoSize", (options) => {
|
|
1477
|
+
var _a;
|
|
1478
|
+
const iframe = this.IframeElement;
|
|
1479
|
+
const doc = iframe.contentDocument;
|
|
1480
|
+
if (!doc) {
|
|
1481
|
+
console.warn("[MyopIframeComponent] Cannot observe auto size: contentDocument not accessible");
|
|
1482
|
+
return () => {
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
const clamp = (value, min, max) => {
|
|
1486
|
+
if (min !== void 0 && value < min) return min;
|
|
1487
|
+
if (max !== void 0 && value > max) return max;
|
|
1488
|
+
return value;
|
|
1489
|
+
};
|
|
1490
|
+
const parseSize = (value) => {
|
|
1491
|
+
if (value === void 0) return void 0;
|
|
1492
|
+
if (typeof value === "number") return value;
|
|
1493
|
+
const parsed = parseFloat(value);
|
|
1494
|
+
return isNaN(parsed) ? void 0 : parsed;
|
|
1495
|
+
};
|
|
1496
|
+
const minWidth = parseSize(options == null ? void 0 : options.minWidth);
|
|
1497
|
+
const maxWidth = parseSize(options == null ? void 0 : options.maxWidth);
|
|
1498
|
+
const minHeight = parseSize(options == null ? void 0 : options.minHeight);
|
|
1499
|
+
const maxHeight = parseSize(options == null ? void 0 : options.maxHeight);
|
|
1500
|
+
const loaderMinHeight = (_a = options == null ? void 0 : options.loaderMinHeight) != null ? _a : 50;
|
|
1501
|
+
const hasExplicitWidth = (options == null ? void 0 : options.explicitWidth) !== void 0;
|
|
1502
|
+
const hasExplicitHeight = (options == null ? void 0 : options.explicitHeight) !== void 0;
|
|
1503
|
+
const containerRect = this.container.getBoundingClientRect();
|
|
1504
|
+
const collapsedWidth = containerRect.width === 0;
|
|
1505
|
+
const collapsedHeight = containerRect.height === 0 || containerRect.height === loaderMinHeight;
|
|
1506
|
+
const shouldAutoWidth = (options == null ? void 0 : options.forceAutoSize) ? !hasExplicitWidth : collapsedWidth && !hasExplicitWidth;
|
|
1507
|
+
const shouldAutoHeight = (options == null ? void 0 : options.forceAutoSize) ? !hasExplicitHeight : collapsedHeight && !hasExplicitHeight;
|
|
1508
|
+
if (!shouldAutoWidth && !shouldAutoHeight) {
|
|
1509
|
+
return () => {
|
|
1510
|
+
};
|
|
1511
|
+
}
|
|
1512
|
+
const updateSize = () => {
|
|
1513
|
+
var _a2;
|
|
1514
|
+
const contentDoc = iframe.contentDocument;
|
|
1515
|
+
if (contentDoc) {
|
|
1516
|
+
const rect = contentDoc.documentElement.getBoundingClientRect();
|
|
1517
|
+
const contentWidth = Math.ceil(rect.width);
|
|
1518
|
+
const contentHeight = Math.ceil(rect.height);
|
|
1519
|
+
const width = clamp(contentWidth, minWidth, maxWidth);
|
|
1520
|
+
const height = clamp(contentHeight, minHeight, maxHeight);
|
|
1521
|
+
if (shouldAutoWidth) {
|
|
1522
|
+
iframe.style.width = "".concat(width, "px");
|
|
1523
|
+
}
|
|
1524
|
+
if (shouldAutoHeight) {
|
|
1525
|
+
iframe.style.height = "".concat(height, "px");
|
|
1526
|
+
}
|
|
1527
|
+
const isWidthConstrained = shouldAutoWidth && maxWidth !== void 0 && contentWidth > maxWidth;
|
|
1528
|
+
const isHeightConstrained = shouldAutoHeight && maxHeight !== void 0 && contentHeight > maxHeight;
|
|
1529
|
+
contentDoc.documentElement.style.overflowX = isWidthConstrained ? "auto" : "hidden";
|
|
1530
|
+
contentDoc.documentElement.style.overflowY = isHeightConstrained ? "auto" : "hidden";
|
|
1531
|
+
(_a2 = options == null ? void 0 : options.onSizeChange) == null ? void 0 : _a2.call(options, {
|
|
1532
|
+
width,
|
|
1533
|
+
height,
|
|
1534
|
+
autoSizingWidth: shouldAutoWidth,
|
|
1535
|
+
autoSizingHeight: shouldAutoHeight
|
|
1536
|
+
});
|
|
1537
|
+
}
|
|
1538
|
+
};
|
|
1539
|
+
updateSize();
|
|
1540
|
+
const resizeObserver = new ResizeObserver(updateSize);
|
|
1541
|
+
resizeObserver.observe(doc.body);
|
|
1542
|
+
resizeObserver.observe(doc.documentElement);
|
|
1543
|
+
return () => {
|
|
1544
|
+
resizeObserver.disconnect();
|
|
1545
|
+
};
|
|
1546
|
+
});
|
|
1470
1547
|
__publicField(this, "setSizeBasedOnDocumentElement", () => {
|
|
1471
1548
|
const cleanupHandler = this.send(new ExecuteScriptMessage(() => {
|
|
1472
1549
|
const { height, width } = document.documentElement.getBoundingClientRect();
|
|
@@ -1597,25 +1674,25 @@ var MyopIframeLoader = class extends BaseMyopLoader {
|
|
|
1597
1674
|
const uniqId = uuidv4();
|
|
1598
1675
|
const domId = "myop-comp-".concat(uniqId);
|
|
1599
1676
|
IframeElement = document.createElement("iframe");
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1677
|
+
IframeElement.id = domId;
|
|
1678
|
+
const iframeStyles = "\n padding: 0;\n margin: 0;\n position: absolute;\n inset: 0;\n height: ".concat(typedLoaderConfig.autoHeight || !typedLoaderConfig.height ? "100%" : typedLoaderConfig.height, ";\n width: 100%;\n overflow: hidden;\n border: none;\n opacity: ").concat((options == null ? void 0 : options.hidden) ? "0" : "1", ";\n pointer-events: ").concat((options == null ? void 0 : options.hidden) ? "none" : "all", ";\n ");
|
|
1679
|
+
IframeElement.style.cssText = iframeStyles;
|
|
1680
|
+
if (options == null ? void 0 : options.elementAttributes) {
|
|
1681
|
+
Object.entries(options.elementAttributes).forEach(([key, value]) => {
|
|
1682
|
+
if (value === "" || value === null || value === void 0) {
|
|
1683
|
+
IframeElement.setAttribute(key, "");
|
|
1684
|
+
} else {
|
|
1685
|
+
IframeElement.setAttribute(key, String(value));
|
|
1686
|
+
}
|
|
1687
|
+
});
|
|
1604
1688
|
}
|
|
1605
|
-
IframeElement = this.appendChild(container, IframeElement, options);
|
|
1606
1689
|
let url2load = skin.loader.url;
|
|
1607
1690
|
if (options == null ? void 0 : options._hasParent)
|
|
1608
1691
|
url2load = addQueryParam(url2load, "_myop-comp", uniqId);
|
|
1609
|
-
|
|
1610
|
-
if (
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
return key;
|
|
1614
|
-
}
|
|
1615
|
-
return "".concat(key, '="').concat(String(value), '"');
|
|
1616
|
-
}).join(" ");
|
|
1617
|
-
IframeElement.outerHTML = '<iframe \n id="'.concat(domId, '"\n style="\n padding: 0;\n margin: 0;\n height: ').concat(typedLoaderConfig.autoHeight || !typedLoaderConfig.height ? "" : typedLoaderConfig.height, "; \n width : 100%;\n overflow: hidden;\n border: none;\n opacity: ").concat((options == null ? void 0 : options.hidden) ? "0" : "1", ";\n position: ").concat((options == null ? void 0 : options.hidden) ? "absolute" : "static", ";\n pointer-events: ").concat((options == null ? void 0 : options.hidden) ? "none" : "all", ';\n "\n src="').concat(url2load, '"\n ').concat(elementAttributesString, "\n ></iframe>");
|
|
1618
|
-
IframeElement = container.querySelector("#".concat(domId));
|
|
1692
|
+
IframeElement.src = url2load;
|
|
1693
|
+
if (!container.querySelector('[id^="myop-comp-"]'))
|
|
1694
|
+
container.innerHTML = "";
|
|
1695
|
+
IframeElement = this.appendChild(container, IframeElement, options);
|
|
1619
1696
|
}
|
|
1620
1697
|
return new MyopIframeComponent(componentDefinition, skin, container, IframeElement, options);
|
|
1621
1698
|
});
|
|
@@ -1731,7 +1808,7 @@ var WebcomponentLoader = class extends BaseMyopLoader {
|
|
|
1731
1808
|
};
|
|
1732
1809
|
|
|
1733
1810
|
// version:myop-sdk-version
|
|
1734
|
-
var myop_sdk_version_default = "0.
|
|
1811
|
+
var myop_sdk_version_default = "0.3.8";
|
|
1735
1812
|
|
|
1736
1813
|
// src/webcomponent/messageHandlers/BaseWebComponentMessageHandler.ts
|
|
1737
1814
|
var BaseWebComponentMessageHandler = class extends BaseContextMessageHandler {
|
|
@@ -2056,6 +2133,10 @@ var WebComponentSDK = class extends BaseMyopSDK {
|
|
|
2056
2133
|
};
|
|
2057
2134
|
defineDynamicImport("WebComponentSDK", WebComponentSDK);
|
|
2058
2135
|
|
|
2136
|
+
// src/host/embeddedSDK.ts
|
|
2137
|
+
var EMBEDDED_SDK_CONTENT = "";
|
|
2138
|
+
var HAS_EMBEDDED_SDK = false;
|
|
2139
|
+
|
|
2059
2140
|
// src/host/loaders/HTMLComponentLoader.ts
|
|
2060
2141
|
var seen2 = [];
|
|
2061
2142
|
var sdk;
|
|
@@ -2101,15 +2182,11 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
|
|
|
2101
2182
|
const uniqId = uuidv4();
|
|
2102
2183
|
const domId2 = "myop-comp-".concat(uniqId);
|
|
2103
2184
|
let IframeElement = document.createElement("iframe");
|
|
2185
|
+
IframeElement.id = domId2;
|
|
2186
|
+
IframeElement.style.cssText = "\n display: block;\n padding: 0;\n margin: 0;\n position: absolute;\n inset: 0;\n overflow: hidden;\n border: none;\n opacity: ".concat((options == null ? void 0 : options.hidden) ? "0" : "1", ";\n width: 100%;\n height: 100%;\n pointer-events: ").concat((options == null ? void 0 : options.hidden) ? "none" : "all", ";\n ");
|
|
2104
2187
|
if (!container.querySelector('[id^="myop-comp-"]'))
|
|
2105
2188
|
container.innerHTML = "";
|
|
2106
|
-
if (options == null ? void 0 : options.hidden) {
|
|
2107
|
-
IframeElement.style.visibility = "hidden";
|
|
2108
|
-
}
|
|
2109
2189
|
IframeElement = this.appendChild(container, IframeElement, options);
|
|
2110
|
-
IframeElement.id = domId2;
|
|
2111
|
-
IframeElement.setAttribute("style", "\n display: block;\n padding: 0;\n margin: 0;\n overflow: hidden;\n border: none;\n opacity: ".concat((options == null ? void 0 : options.hidden) ? "0" : "1", ";\n width: 100%;\n height: 100%;\n position: ").concat((options == null ? void 0 : options.hidden) ? "absolute" : "static", ";\n pointer-events: ").concat((options == null ? void 0 : options.hidden) ? "none" : "all", ";\n "));
|
|
2112
|
-
container.appendChild(IframeElement);
|
|
2113
2190
|
const doc = IframeElement.contentDocument || IframeElement.contentWindow.document;
|
|
2114
2191
|
doc.open();
|
|
2115
2192
|
let HTML2Render = loaderConfig.HTML;
|
|
@@ -2127,7 +2204,9 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
|
|
|
2127
2204
|
HTML2Render = _doc.documentElement.outerHTML;
|
|
2128
2205
|
}
|
|
2129
2206
|
doc.writeln(HTML2Render);
|
|
2130
|
-
|
|
2207
|
+
const sdkScript = HAS_EMBEDDED_SDK ? "<script>".concat(EMBEDDED_SDK_CONTENT, "<\/script>") : '<script src="'.concat(window.myop.__ROOT_SDK_PUBLIC_URL__, '"><\/script>');
|
|
2208
|
+
const initScript = HAS_EMBEDDED_SDK ? "<script>\n const __myop_init = async () => {\n const iframeModule = await MyopSDK.getIframeModule();\n const IframeSDK = iframeModule.IframeSDK;\n const sdk = new IframeSDK();\n sdk.init();\n }\n __myop_init().then();\n <\/script>" : "<script>\n window.__federation__.__public_path__ = window.__federation__.__public_path__;\n const __myop_init = async () => {\n const {IframeSDK} = (await window.myop.rootSDK.getIframeModule());\n const sdk = new IframeSDK();\n sdk.init();\n }\n __myop_init().then();\n <\/script>";
|
|
2209
|
+
doc.writeln("".concat(sdkScript).concat(initScript));
|
|
2131
2210
|
doc.close();
|
|
2132
2211
|
const comp = new MyopIframeComponent(componentDefinition, skin, container, IframeElement, options);
|
|
2133
2212
|
if (loaderConfig.autoHeight) {
|
|
@@ -2170,6 +2249,57 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
|
|
|
2170
2249
|
};
|
|
2171
2250
|
|
|
2172
2251
|
// src/helpers/CloudRepository.ts
|
|
2252
|
+
var convertV2VariantToComponentConfig = (config) => {
|
|
2253
|
+
return {
|
|
2254
|
+
instance: {
|
|
2255
|
+
id: "auto",
|
|
2256
|
+
componentId: config.componentId,
|
|
2257
|
+
componentName: config.name,
|
|
2258
|
+
skinSelector: {
|
|
2259
|
+
type: "Dedicated",
|
|
2260
|
+
skin: {
|
|
2261
|
+
id: "skin_auto_v2_converted"
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
},
|
|
2265
|
+
type: {
|
|
2266
|
+
id: config.id,
|
|
2267
|
+
name: config.name,
|
|
2268
|
+
description: config.description,
|
|
2269
|
+
props: [
|
|
2270
|
+
{
|
|
2271
|
+
id: "in_auto_v2_converted",
|
|
2272
|
+
name: "myop_init_interface",
|
|
2273
|
+
type: "any",
|
|
2274
|
+
behavior: {
|
|
2275
|
+
type: PropConfigBehaviorTypes.code
|
|
2276
|
+
}
|
|
2277
|
+
},
|
|
2278
|
+
{
|
|
2279
|
+
id: "out_auto_v2_converted",
|
|
2280
|
+
name: "myop_cta_handler",
|
|
2281
|
+
type: "any",
|
|
2282
|
+
behavior: {
|
|
2283
|
+
type: PropConfigBehaviorTypes.code
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
],
|
|
2287
|
+
refs: [],
|
|
2288
|
+
skins: [
|
|
2289
|
+
{
|
|
2290
|
+
id: "skin_auto_v2_converted",
|
|
2291
|
+
name: "auto_v2_converted",
|
|
2292
|
+
description: "",
|
|
2293
|
+
//TODO : handle empty :
|
|
2294
|
+
// @ts-ignore
|
|
2295
|
+
loader: config.consume_variant[0].loader
|
|
2296
|
+
}
|
|
2297
|
+
],
|
|
2298
|
+
defaultSkin: 0
|
|
2299
|
+
},
|
|
2300
|
+
name: config.name
|
|
2301
|
+
};
|
|
2302
|
+
};
|
|
2173
2303
|
var _CloudRepository = class _CloudRepository {
|
|
2174
2304
|
constructor(_baseUrl = "https://cloud.myop.dev") {
|
|
2175
2305
|
this._baseUrl = _baseUrl;
|
|
@@ -2177,34 +2307,62 @@ var _CloudRepository = class _CloudRepository {
|
|
|
2177
2307
|
__publicField(this, "variants", {});
|
|
2178
2308
|
// v1 cache
|
|
2179
2309
|
__publicField(this, "userFlows", {});
|
|
2310
|
+
__publicField(this, "_defaultEnv", "production");
|
|
2311
|
+
}
|
|
2312
|
+
/**
|
|
2313
|
+
* Set the default environment for this CloudRepository instance
|
|
2314
|
+
*/
|
|
2315
|
+
setEnvironment(env) {
|
|
2316
|
+
this._defaultEnv = env;
|
|
2317
|
+
}
|
|
2318
|
+
/**
|
|
2319
|
+
* Get the current default environment
|
|
2320
|
+
*/
|
|
2321
|
+
getDefaultEnvironment() {
|
|
2322
|
+
return this._defaultEnv;
|
|
2180
2323
|
}
|
|
2181
2324
|
// ============ V2 Methods (Default) ============
|
|
2182
2325
|
/**
|
|
2183
2326
|
* Check if a component is already cached/preloaded (v2)
|
|
2184
2327
|
*/
|
|
2185
|
-
isPreloaded(componentId) {
|
|
2186
|
-
|
|
2328
|
+
isPreloaded(componentId, env, preview) {
|
|
2329
|
+
const cacheKey = "".concat(componentId, ":").concat(env || this._defaultEnv, ":").concat(preview ? "preview" : "live");
|
|
2330
|
+
return cacheKey in this.variants;
|
|
2187
2331
|
}
|
|
2188
2332
|
/**
|
|
2189
|
-
* Fetch a v2 component
|
|
2333
|
+
* Fetch a v2 component config
|
|
2190
2334
|
*/
|
|
2191
|
-
async fetchComponentV2(componentId, environmentIdentifier) {
|
|
2192
|
-
|
|
2193
|
-
|
|
2335
|
+
async fetchComponentV2(componentId, environmentIdentifier, preview) {
|
|
2336
|
+
const env = environmentIdentifier || this._defaultEnv;
|
|
2337
|
+
const cacheKey = "".concat(componentId, ":").concat(env, ":").concat(preview ? "preview" : "live");
|
|
2338
|
+
if (!this.variants[cacheKey]) {
|
|
2339
|
+
this.variants[cacheKey] = new Promise(
|
|
2194
2340
|
async (resolve, reject) => {
|
|
2195
2341
|
try {
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2342
|
+
let url = "".concat(this._baseUrl, "/consume?id=").concat(componentId, "&env=").concat(env);
|
|
2343
|
+
if (preview) {
|
|
2344
|
+
url += "&preview=true";
|
|
2345
|
+
}
|
|
2346
|
+
const res = await fetch(url);
|
|
2199
2347
|
const json = await res.json();
|
|
2200
|
-
|
|
2348
|
+
const variant = json.item;
|
|
2349
|
+
if (!variant) {
|
|
2350
|
+
reject(new Error('Component "'.concat(componentId, '" not found')));
|
|
2351
|
+
return;
|
|
2352
|
+
}
|
|
2353
|
+
if (!variant.consume_variant || !variant.consume_variant.length) {
|
|
2354
|
+
reject(new Error('Component "'.concat(componentId, '" has no implementation for environment "').concat(env, '"')));
|
|
2355
|
+
return;
|
|
2356
|
+
}
|
|
2357
|
+
const componentConfig = convertV2VariantToComponentConfig(variant);
|
|
2358
|
+
resolve(componentConfig);
|
|
2201
2359
|
} catch (e) {
|
|
2202
2360
|
reject(e);
|
|
2203
2361
|
}
|
|
2204
2362
|
}
|
|
2205
2363
|
);
|
|
2206
2364
|
}
|
|
2207
|
-
return await this.variants[
|
|
2365
|
+
return await this.variants[cacheKey];
|
|
2208
2366
|
}
|
|
2209
2367
|
// ============ V1 Methods (Legacy) ============
|
|
2210
2368
|
/**
|