@myop/sdk 0.2.6 → 0.2.7
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 +67 -7
- package/dist/cjs/_IframeSDK.43696632.min.js +1 -0
- package/dist/cjs/{_IframeSDK.2793f0c2.js → _IframeSDK.65146759.js} +185 -33
- package/dist/cjs/_IframeSDK.65146759.js.map +7 -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.4a661403.js} +185 -33
- package/dist/cjs/_WebComponentSDK.4a661403.js.map +7 -0
- package/dist/cjs/_WebComponentSDK.5d90b79c.min.js +1 -0
- package/dist/cjs/{_hostSDK.71e17cf2.js → _hostSDK.933cfab5.js} +185 -33
- package/dist/cjs/_hostSDK.933cfab5.js.map +7 -0
- package/dist/cjs/_hostSDK.98520a3d.min.js +1 -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 +188 -35
- package/dist/cjs-bundled/myop_sdk.bundled.js.map +2 -2
- package/dist/cjs-bundled/myop_sdk.bundled.min.js +1 -1
- package/dist/module/Iframe/index.js +209 -60
- package/dist/module/Iframe/index.js.map +3 -3
- package/dist/module/SDK.js +211 -61
- 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/index.d.ts +1 -0
- package/dist/module/host/index.js +209 -60
- package/dist/module/host/index.js.map +3 -3
- package/dist/module/webcomponent/index.js +209 -60
- 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,7 @@ var WebcomponentLoader = class extends BaseMyopLoader {
|
|
|
1728
1805
|
};
|
|
1729
1806
|
|
|
1730
1807
|
// version:myop-sdk-version
|
|
1731
|
-
var myop_sdk_version_default = "0.2.
|
|
1808
|
+
var myop_sdk_version_default = "0.2.7";
|
|
1732
1809
|
|
|
1733
1810
|
// src/host/loaders/HTMLComponentLoader.ts
|
|
1734
1811
|
var seen2 = [];
|
|
@@ -1775,15 +1852,11 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
|
|
|
1775
1852
|
const uniqId = uuidv4();
|
|
1776
1853
|
const domId2 = "myop-comp-".concat(uniqId);
|
|
1777
1854
|
let IframeElement = document.createElement("iframe");
|
|
1855
|
+
IframeElement.id = domId2;
|
|
1856
|
+
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
1857
|
if (!container.querySelector('[id^="myop-comp-"]'))
|
|
1779
1858
|
container.innerHTML = "";
|
|
1780
|
-
if (options == null ? void 0 : options.hidden) {
|
|
1781
|
-
IframeElement.style.visibility = "hidden";
|
|
1782
|
-
}
|
|
1783
1859
|
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
1860
|
const doc = IframeElement.contentDocument || IframeElement.contentWindow.document;
|
|
1788
1861
|
doc.open();
|
|
1789
1862
|
let HTML2Render = loaderConfig.HTML;
|
|
@@ -1844,6 +1917,57 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
|
|
|
1844
1917
|
};
|
|
1845
1918
|
|
|
1846
1919
|
// src/helpers/CloudRepository.ts
|
|
1920
|
+
var convertV2VariantToComponentConfig = (config) => {
|
|
1921
|
+
return {
|
|
1922
|
+
instance: {
|
|
1923
|
+
id: "auto",
|
|
1924
|
+
componentId: config.componentId,
|
|
1925
|
+
componentName: config.name,
|
|
1926
|
+
skinSelector: {
|
|
1927
|
+
type: "Dedicated",
|
|
1928
|
+
skin: {
|
|
1929
|
+
id: "skin_auto_v2_converted"
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
},
|
|
1933
|
+
type: {
|
|
1934
|
+
id: config.id,
|
|
1935
|
+
name: config.name,
|
|
1936
|
+
description: config.description,
|
|
1937
|
+
props: [
|
|
1938
|
+
{
|
|
1939
|
+
id: "in_auto_v2_converted",
|
|
1940
|
+
name: "myop_init_interface",
|
|
1941
|
+
type: "any",
|
|
1942
|
+
behavior: {
|
|
1943
|
+
type: PropConfigBehaviorTypes.code
|
|
1944
|
+
}
|
|
1945
|
+
},
|
|
1946
|
+
{
|
|
1947
|
+
id: "out_auto_v2_converted",
|
|
1948
|
+
name: "myop_cta_handler",
|
|
1949
|
+
type: "any",
|
|
1950
|
+
behavior: {
|
|
1951
|
+
type: PropConfigBehaviorTypes.code
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
],
|
|
1955
|
+
refs: [],
|
|
1956
|
+
skins: [
|
|
1957
|
+
{
|
|
1958
|
+
id: "skin_auto_v2_converted",
|
|
1959
|
+
name: "auto_v2_converted",
|
|
1960
|
+
description: "",
|
|
1961
|
+
//TODO : handle empty :
|
|
1962
|
+
// @ts-ignore
|
|
1963
|
+
loader: config.consume_variant[0].loader
|
|
1964
|
+
}
|
|
1965
|
+
],
|
|
1966
|
+
defaultSkin: 0
|
|
1967
|
+
},
|
|
1968
|
+
name: config.name
|
|
1969
|
+
};
|
|
1970
|
+
};
|
|
1847
1971
|
var _CloudRepository = class _CloudRepository {
|
|
1848
1972
|
constructor(_baseUrl = "https://cloud.myop.dev") {
|
|
1849
1973
|
this._baseUrl = _baseUrl;
|
|
@@ -1851,34 +1975,62 @@ var _CloudRepository = class _CloudRepository {
|
|
|
1851
1975
|
__publicField(this, "variants", {});
|
|
1852
1976
|
// v1 cache
|
|
1853
1977
|
__publicField(this, "userFlows", {});
|
|
1978
|
+
__publicField(this, "_defaultEnv", "production");
|
|
1979
|
+
}
|
|
1980
|
+
/**
|
|
1981
|
+
* Set the default environment for this CloudRepository instance
|
|
1982
|
+
*/
|
|
1983
|
+
setEnvironment(env) {
|
|
1984
|
+
this._defaultEnv = env;
|
|
1985
|
+
}
|
|
1986
|
+
/**
|
|
1987
|
+
* Get the current default environment
|
|
1988
|
+
*/
|
|
1989
|
+
getDefaultEnvironment() {
|
|
1990
|
+
return this._defaultEnv;
|
|
1854
1991
|
}
|
|
1855
1992
|
// ============ V2 Methods (Default) ============
|
|
1856
1993
|
/**
|
|
1857
1994
|
* Check if a component is already cached/preloaded (v2)
|
|
1858
1995
|
*/
|
|
1859
|
-
isPreloaded(componentId) {
|
|
1860
|
-
|
|
1996
|
+
isPreloaded(componentId, env, preview) {
|
|
1997
|
+
const cacheKey = "".concat(componentId, ":").concat(env || this._defaultEnv, ":").concat(preview ? "preview" : "live");
|
|
1998
|
+
return cacheKey in this.variants;
|
|
1861
1999
|
}
|
|
1862
2000
|
/**
|
|
1863
|
-
* Fetch a v2 component
|
|
2001
|
+
* Fetch a v2 component config
|
|
1864
2002
|
*/
|
|
1865
|
-
async fetchComponentV2(componentId, environmentIdentifier) {
|
|
1866
|
-
|
|
1867
|
-
|
|
2003
|
+
async fetchComponentV2(componentId, environmentIdentifier, preview) {
|
|
2004
|
+
const env = environmentIdentifier || this._defaultEnv;
|
|
2005
|
+
const cacheKey = "".concat(componentId, ":").concat(env, ":").concat(preview ? "preview" : "live");
|
|
2006
|
+
if (!this.variants[cacheKey]) {
|
|
2007
|
+
this.variants[cacheKey] = new Promise(
|
|
1868
2008
|
async (resolve, reject) => {
|
|
1869
2009
|
try {
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
2010
|
+
let url = "".concat(this._baseUrl, "/consume?id=").concat(componentId, "&env=").concat(env);
|
|
2011
|
+
if (preview) {
|
|
2012
|
+
url += "&preview=true";
|
|
2013
|
+
}
|
|
2014
|
+
const res = await fetch(url);
|
|
1873
2015
|
const json = await res.json();
|
|
1874
|
-
|
|
2016
|
+
const variant = json.item;
|
|
2017
|
+
if (!variant) {
|
|
2018
|
+
reject(new Error('Component "'.concat(componentId, '" not found')));
|
|
2019
|
+
return;
|
|
2020
|
+
}
|
|
2021
|
+
if (!variant.consume_variant || !variant.consume_variant.length) {
|
|
2022
|
+
reject(new Error('Component "'.concat(componentId, '" has no implementation for environment "').concat(env, '"')));
|
|
2023
|
+
return;
|
|
2024
|
+
}
|
|
2025
|
+
const componentConfig = convertV2VariantToComponentConfig(variant);
|
|
2026
|
+
resolve(componentConfig);
|
|
1875
2027
|
} catch (e) {
|
|
1876
2028
|
reject(e);
|
|
1877
2029
|
}
|
|
1878
2030
|
}
|
|
1879
2031
|
);
|
|
1880
2032
|
}
|
|
1881
|
-
return await this.variants[
|
|
2033
|
+
return await this.variants[cacheKey];
|
|
1882
2034
|
}
|
|
1883
2035
|
// ============ V1 Methods (Legacy) ============
|
|
1884
2036
|
/**
|