@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
|
@@ -1469,6 +1469,83 @@ var MyopIframeComponent = class extends BaseMyopComponent {
|
|
|
1469
1469
|
}));
|
|
1470
1470
|
return cleanupHandler;
|
|
1471
1471
|
});
|
|
1472
|
+
/**
|
|
1473
|
+
* Observes the iframe content size and automatically syncs it to the iframe element.
|
|
1474
|
+
* Uses direct contentDocument access (same-origin only) for accurate measurements.
|
|
1475
|
+
* @param options - Configuration options including size change callback and min/max constraints
|
|
1476
|
+
* @returns Cleanup function to stop observing
|
|
1477
|
+
*/
|
|
1478
|
+
__publicField(this, "observeAutoSize", (options) => {
|
|
1479
|
+
var _a;
|
|
1480
|
+
const iframe = this.IframeElement;
|
|
1481
|
+
const doc = iframe.contentDocument;
|
|
1482
|
+
if (!doc) {
|
|
1483
|
+
console.warn("[MyopIframeComponent] Cannot observe auto size: contentDocument not accessible");
|
|
1484
|
+
return () => {
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
const clamp = (value, min, max) => {
|
|
1488
|
+
if (min !== void 0 && value < min) return min;
|
|
1489
|
+
if (max !== void 0 && value > max) return max;
|
|
1490
|
+
return value;
|
|
1491
|
+
};
|
|
1492
|
+
const parseSize = (value) => {
|
|
1493
|
+
if (value === void 0) return void 0;
|
|
1494
|
+
if (typeof value === "number") return value;
|
|
1495
|
+
const parsed = parseFloat(value);
|
|
1496
|
+
return isNaN(parsed) ? void 0 : parsed;
|
|
1497
|
+
};
|
|
1498
|
+
const minWidth = parseSize(options == null ? void 0 : options.minWidth);
|
|
1499
|
+
const maxWidth = parseSize(options == null ? void 0 : options.maxWidth);
|
|
1500
|
+
const minHeight = parseSize(options == null ? void 0 : options.minHeight);
|
|
1501
|
+
const maxHeight = parseSize(options == null ? void 0 : options.maxHeight);
|
|
1502
|
+
const loaderMinHeight = (_a = options == null ? void 0 : options.loaderMinHeight) != null ? _a : 50;
|
|
1503
|
+
const hasExplicitWidth = (options == null ? void 0 : options.explicitWidth) !== void 0;
|
|
1504
|
+
const hasExplicitHeight = (options == null ? void 0 : options.explicitHeight) !== void 0;
|
|
1505
|
+
const containerRect = this.container.getBoundingClientRect();
|
|
1506
|
+
const collapsedWidth = containerRect.width === 0;
|
|
1507
|
+
const collapsedHeight = containerRect.height === 0 || containerRect.height === loaderMinHeight;
|
|
1508
|
+
const shouldAutoWidth = (options == null ? void 0 : options.forceAutoSize) ? !hasExplicitWidth : collapsedWidth && !hasExplicitWidth;
|
|
1509
|
+
const shouldAutoHeight = (options == null ? void 0 : options.forceAutoSize) ? !hasExplicitHeight : collapsedHeight && !hasExplicitHeight;
|
|
1510
|
+
if (!shouldAutoWidth && !shouldAutoHeight) {
|
|
1511
|
+
return () => {
|
|
1512
|
+
};
|
|
1513
|
+
}
|
|
1514
|
+
const updateSize = () => {
|
|
1515
|
+
var _a2;
|
|
1516
|
+
const contentDoc = iframe.contentDocument;
|
|
1517
|
+
if (contentDoc) {
|
|
1518
|
+
const rect = contentDoc.documentElement.getBoundingClientRect();
|
|
1519
|
+
const contentWidth = Math.ceil(rect.width);
|
|
1520
|
+
const contentHeight = Math.ceil(rect.height);
|
|
1521
|
+
const width = clamp(contentWidth, minWidth, maxWidth);
|
|
1522
|
+
const height = clamp(contentHeight, minHeight, maxHeight);
|
|
1523
|
+
if (shouldAutoWidth) {
|
|
1524
|
+
iframe.style.width = "".concat(width, "px");
|
|
1525
|
+
}
|
|
1526
|
+
if (shouldAutoHeight) {
|
|
1527
|
+
iframe.style.height = "".concat(height, "px");
|
|
1528
|
+
}
|
|
1529
|
+
const isWidthConstrained = shouldAutoWidth && maxWidth !== void 0 && contentWidth > maxWidth;
|
|
1530
|
+
const isHeightConstrained = shouldAutoHeight && maxHeight !== void 0 && contentHeight > maxHeight;
|
|
1531
|
+
contentDoc.documentElement.style.overflowX = isWidthConstrained ? "auto" : "hidden";
|
|
1532
|
+
contentDoc.documentElement.style.overflowY = isHeightConstrained ? "auto" : "hidden";
|
|
1533
|
+
(_a2 = options == null ? void 0 : options.onSizeChange) == null ? void 0 : _a2.call(options, {
|
|
1534
|
+
width,
|
|
1535
|
+
height,
|
|
1536
|
+
autoSizingWidth: shouldAutoWidth,
|
|
1537
|
+
autoSizingHeight: shouldAutoHeight
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
};
|
|
1541
|
+
updateSize();
|
|
1542
|
+
const resizeObserver = new ResizeObserver(updateSize);
|
|
1543
|
+
resizeObserver.observe(doc.body);
|
|
1544
|
+
resizeObserver.observe(doc.documentElement);
|
|
1545
|
+
return () => {
|
|
1546
|
+
resizeObserver.disconnect();
|
|
1547
|
+
};
|
|
1548
|
+
});
|
|
1472
1549
|
__publicField(this, "setSizeBasedOnDocumentElement", () => {
|
|
1473
1550
|
const cleanupHandler = this.send(new ExecuteScriptMessage(() => {
|
|
1474
1551
|
const { height, width } = document.documentElement.getBoundingClientRect();
|
|
@@ -1599,25 +1676,25 @@ var MyopIframeLoader = class extends BaseMyopLoader {
|
|
|
1599
1676
|
const uniqId = uuidv4();
|
|
1600
1677
|
const domId = "myop-comp-".concat(uniqId);
|
|
1601
1678
|
IframeElement = document.createElement("iframe");
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1679
|
+
IframeElement.id = domId;
|
|
1680
|
+
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 ");
|
|
1681
|
+
IframeElement.style.cssText = iframeStyles;
|
|
1682
|
+
if (options == null ? void 0 : options.elementAttributes) {
|
|
1683
|
+
Object.entries(options.elementAttributes).forEach(([key, value]) => {
|
|
1684
|
+
if (value === "" || value === null || value === void 0) {
|
|
1685
|
+
IframeElement.setAttribute(key, "");
|
|
1686
|
+
} else {
|
|
1687
|
+
IframeElement.setAttribute(key, String(value));
|
|
1688
|
+
}
|
|
1689
|
+
});
|
|
1606
1690
|
}
|
|
1607
|
-
IframeElement = this.appendChild(container, IframeElement, options);
|
|
1608
1691
|
let url2load = skin.loader.url;
|
|
1609
1692
|
if (options == null ? void 0 : options._hasParent)
|
|
1610
1693
|
url2load = addQueryParam(url2load, "_myop-comp", uniqId);
|
|
1611
|
-
|
|
1612
|
-
if (
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
return key;
|
|
1616
|
-
}
|
|
1617
|
-
return "".concat(key, '="').concat(String(value), '"');
|
|
1618
|
-
}).join(" ");
|
|
1619
|
-
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>");
|
|
1620
|
-
IframeElement = container.querySelector("#".concat(domId));
|
|
1694
|
+
IframeElement.src = url2load;
|
|
1695
|
+
if (!container.querySelector('[id^="myop-comp-"]'))
|
|
1696
|
+
container.innerHTML = "";
|
|
1697
|
+
IframeElement = this.appendChild(container, IframeElement, options);
|
|
1621
1698
|
}
|
|
1622
1699
|
return new MyopIframeComponent(componentDefinition, skin, container, IframeElement, options);
|
|
1623
1700
|
});
|
|
@@ -1728,7 +1805,11 @@ var WebcomponentLoader = class extends BaseMyopLoader {
|
|
|
1728
1805
|
};
|
|
1729
1806
|
|
|
1730
1807
|
// version:myop-sdk-version
|
|
1731
|
-
var myop_sdk_version_default = "0.
|
|
1808
|
+
var myop_sdk_version_default = "0.3.8";
|
|
1809
|
+
|
|
1810
|
+
// src/host/embeddedSDK.ts
|
|
1811
|
+
var EMBEDDED_SDK_CONTENT = "";
|
|
1812
|
+
var HAS_EMBEDDED_SDK = false;
|
|
1732
1813
|
|
|
1733
1814
|
// src/host/loaders/HTMLComponentLoader.ts
|
|
1734
1815
|
var seen2 = [];
|
|
@@ -1775,15 +1856,11 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
|
|
|
1775
1856
|
const uniqId = uuidv4();
|
|
1776
1857
|
const domId2 = "myop-comp-".concat(uniqId);
|
|
1777
1858
|
let IframeElement = document.createElement("iframe");
|
|
1859
|
+
IframeElement.id = domId2;
|
|
1860
|
+
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 ");
|
|
1778
1861
|
if (!container.querySelector('[id^="myop-comp-"]'))
|
|
1779
1862
|
container.innerHTML = "";
|
|
1780
|
-
if (options == null ? void 0 : options.hidden) {
|
|
1781
|
-
IframeElement.style.visibility = "hidden";
|
|
1782
|
-
}
|
|
1783
1863
|
IframeElement = this.appendChild(container, IframeElement, options);
|
|
1784
|
-
IframeElement.id = domId2;
|
|
1785
|
-
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 "));
|
|
1786
|
-
container.appendChild(IframeElement);
|
|
1787
1864
|
const doc = IframeElement.contentDocument || IframeElement.contentWindow.document;
|
|
1788
1865
|
doc.open();
|
|
1789
1866
|
let HTML2Render = loaderConfig.HTML;
|
|
@@ -1801,7 +1878,9 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
|
|
|
1801
1878
|
HTML2Render = _doc.documentElement.outerHTML;
|
|
1802
1879
|
}
|
|
1803
1880
|
doc.writeln(HTML2Render);
|
|
1804
|
-
|
|
1881
|
+
const sdkScript = HAS_EMBEDDED_SDK ? "<script>".concat(EMBEDDED_SDK_CONTENT, "<\/script>") : '<script src="'.concat(window.myop.__ROOT_SDK_PUBLIC_URL__, '"><\/script>');
|
|
1882
|
+
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>";
|
|
1883
|
+
doc.writeln("".concat(sdkScript).concat(initScript));
|
|
1805
1884
|
doc.close();
|
|
1806
1885
|
const comp = new MyopIframeComponent(componentDefinition, skin, container, IframeElement, options);
|
|
1807
1886
|
if (loaderConfig.autoHeight) {
|
|
@@ -1844,6 +1923,57 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
|
|
|
1844
1923
|
};
|
|
1845
1924
|
|
|
1846
1925
|
// src/helpers/CloudRepository.ts
|
|
1926
|
+
var convertV2VariantToComponentConfig = (config) => {
|
|
1927
|
+
return {
|
|
1928
|
+
instance: {
|
|
1929
|
+
id: "auto",
|
|
1930
|
+
componentId: config.componentId,
|
|
1931
|
+
componentName: config.name,
|
|
1932
|
+
skinSelector: {
|
|
1933
|
+
type: "Dedicated",
|
|
1934
|
+
skin: {
|
|
1935
|
+
id: "skin_auto_v2_converted"
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
},
|
|
1939
|
+
type: {
|
|
1940
|
+
id: config.id,
|
|
1941
|
+
name: config.name,
|
|
1942
|
+
description: config.description,
|
|
1943
|
+
props: [
|
|
1944
|
+
{
|
|
1945
|
+
id: "in_auto_v2_converted",
|
|
1946
|
+
name: "myop_init_interface",
|
|
1947
|
+
type: "any",
|
|
1948
|
+
behavior: {
|
|
1949
|
+
type: PropConfigBehaviorTypes.code
|
|
1950
|
+
}
|
|
1951
|
+
},
|
|
1952
|
+
{
|
|
1953
|
+
id: "out_auto_v2_converted",
|
|
1954
|
+
name: "myop_cta_handler",
|
|
1955
|
+
type: "any",
|
|
1956
|
+
behavior: {
|
|
1957
|
+
type: PropConfigBehaviorTypes.code
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
],
|
|
1961
|
+
refs: [],
|
|
1962
|
+
skins: [
|
|
1963
|
+
{
|
|
1964
|
+
id: "skin_auto_v2_converted",
|
|
1965
|
+
name: "auto_v2_converted",
|
|
1966
|
+
description: "",
|
|
1967
|
+
//TODO : handle empty :
|
|
1968
|
+
// @ts-ignore
|
|
1969
|
+
loader: config.consume_variant[0].loader
|
|
1970
|
+
}
|
|
1971
|
+
],
|
|
1972
|
+
defaultSkin: 0
|
|
1973
|
+
},
|
|
1974
|
+
name: config.name
|
|
1975
|
+
};
|
|
1976
|
+
};
|
|
1847
1977
|
var _CloudRepository = class _CloudRepository {
|
|
1848
1978
|
constructor(_baseUrl = "https://cloud.myop.dev") {
|
|
1849
1979
|
this._baseUrl = _baseUrl;
|
|
@@ -1851,34 +1981,62 @@ var _CloudRepository = class _CloudRepository {
|
|
|
1851
1981
|
__publicField(this, "variants", {});
|
|
1852
1982
|
// v1 cache
|
|
1853
1983
|
__publicField(this, "userFlows", {});
|
|
1984
|
+
__publicField(this, "_defaultEnv", "production");
|
|
1985
|
+
}
|
|
1986
|
+
/**
|
|
1987
|
+
* Set the default environment for this CloudRepository instance
|
|
1988
|
+
*/
|
|
1989
|
+
setEnvironment(env) {
|
|
1990
|
+
this._defaultEnv = env;
|
|
1991
|
+
}
|
|
1992
|
+
/**
|
|
1993
|
+
* Get the current default environment
|
|
1994
|
+
*/
|
|
1995
|
+
getDefaultEnvironment() {
|
|
1996
|
+
return this._defaultEnv;
|
|
1854
1997
|
}
|
|
1855
1998
|
// ============ V2 Methods (Default) ============
|
|
1856
1999
|
/**
|
|
1857
2000
|
* Check if a component is already cached/preloaded (v2)
|
|
1858
2001
|
*/
|
|
1859
|
-
isPreloaded(componentId) {
|
|
1860
|
-
|
|
2002
|
+
isPreloaded(componentId, env, preview) {
|
|
2003
|
+
const cacheKey = "".concat(componentId, ":").concat(env || this._defaultEnv, ":").concat(preview ? "preview" : "live");
|
|
2004
|
+
return cacheKey in this.variants;
|
|
1861
2005
|
}
|
|
1862
2006
|
/**
|
|
1863
|
-
* Fetch a v2 component
|
|
2007
|
+
* Fetch a v2 component config
|
|
1864
2008
|
*/
|
|
1865
|
-
async fetchComponentV2(componentId, environmentIdentifier) {
|
|
1866
|
-
|
|
1867
|
-
|
|
2009
|
+
async fetchComponentV2(componentId, environmentIdentifier, preview) {
|
|
2010
|
+
const env = environmentIdentifier || this._defaultEnv;
|
|
2011
|
+
const cacheKey = "".concat(componentId, ":").concat(env, ":").concat(preview ? "preview" : "live");
|
|
2012
|
+
if (!this.variants[cacheKey]) {
|
|
2013
|
+
this.variants[cacheKey] = new Promise(
|
|
1868
2014
|
async (resolve, reject) => {
|
|
1869
2015
|
try {
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
2016
|
+
let url = "".concat(this._baseUrl, "/consume?id=").concat(componentId, "&env=").concat(env);
|
|
2017
|
+
if (preview) {
|
|
2018
|
+
url += "&preview=true";
|
|
2019
|
+
}
|
|
2020
|
+
const res = await fetch(url);
|
|
1873
2021
|
const json = await res.json();
|
|
1874
|
-
|
|
2022
|
+
const variant = json.item;
|
|
2023
|
+
if (!variant) {
|
|
2024
|
+
reject(new Error('Component "'.concat(componentId, '" not found')));
|
|
2025
|
+
return;
|
|
2026
|
+
}
|
|
2027
|
+
if (!variant.consume_variant || !variant.consume_variant.length) {
|
|
2028
|
+
reject(new Error('Component "'.concat(componentId, '" has no implementation for environment "').concat(env, '"')));
|
|
2029
|
+
return;
|
|
2030
|
+
}
|
|
2031
|
+
const componentConfig = convertV2VariantToComponentConfig(variant);
|
|
2032
|
+
resolve(componentConfig);
|
|
1875
2033
|
} catch (e) {
|
|
1876
2034
|
reject(e);
|
|
1877
2035
|
}
|
|
1878
2036
|
}
|
|
1879
2037
|
);
|
|
1880
2038
|
}
|
|
1881
|
-
return await this.variants[
|
|
2039
|
+
return await this.variants[cacheKey];
|
|
1882
2040
|
}
|
|
1883
2041
|
// ============ V1 Methods (Legacy) ============
|
|
1884
2042
|
/**
|