@myop/sdk 0.3.14 → 0.3.16

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.
Files changed (36) hide show
  1. package/dist/bundled-declarations.d.ts +64 -1
  2. package/dist/cjs/{_IframeSDK.fe91981e.js → _IframeSDK.0e315746.js} +217 -1
  3. package/dist/cjs/_IframeSDK.0e315746.js.map +7 -0
  4. package/dist/cjs/_IframeSDK.5d5802e4.min.js +1 -0
  5. package/dist/cjs/{_WebComponentSDK.eb8de391.js → _WebComponentSDK.6f1a3255.js} +217 -1
  6. package/dist/cjs/_WebComponentSDK.6f1a3255.js.map +7 -0
  7. package/dist/cjs/_WebComponentSDK.cc56ccfd.min.js +1 -0
  8. package/dist/cjs/_hostSDK.581f1f0b.min.js +1 -0
  9. package/dist/cjs/{_hostSDK.40194c35.js → _hostSDK.fd5d5514.js} +217 -1
  10. package/dist/cjs/_hostSDK.fd5d5514.js.map +7 -0
  11. package/dist/cjs/myop_sdk.js +11 -11
  12. package/dist/cjs/myop_sdk.js.map +1 -1
  13. package/dist/cjs/myop_sdk.min.js +1 -1
  14. package/dist/cjs-bundled/myop_sdk.bundled.js +229 -3
  15. package/dist/cjs-bundled/myop_sdk.bundled.js.map +4 -4
  16. package/dist/cjs-bundled/myop_sdk.bundled.min.js +1 -1
  17. package/dist/module/Iframe/index.js +220 -2
  18. package/dist/module/Iframe/index.js.map +3 -3
  19. package/dist/module/SDK.js +231 -3
  20. package/dist/module/SDK.js.map +4 -4
  21. package/dist/module/embeddedSDK.js +1 -1
  22. package/dist/module/host/components/myopExtractedWebComponent.d.ts +43 -0
  23. package/dist/module/host/embeddedSDK.js +1 -1
  24. package/dist/module/host/index.d.ts +1 -0
  25. package/dist/module/host/index.js +221 -2
  26. package/dist/module/host/index.js.map +3 -3
  27. package/dist/module/host/loaders/HTMLComponentLoader.d.ts +18 -1
  28. package/dist/module/webcomponent/index.js +220 -2
  29. package/dist/module/webcomponent/index.js.map +3 -3
  30. package/package.json +1 -1
  31. package/dist/cjs/_IframeSDK.6575ebb7.min.js +0 -1
  32. package/dist/cjs/_IframeSDK.fe91981e.js.map +0 -7
  33. package/dist/cjs/_WebComponentSDK.384a170a.min.js +0 -1
  34. package/dist/cjs/_WebComponentSDK.eb8de391.js.map +0 -7
  35. package/dist/cjs/_hostSDK.40194c35.js.map +0 -7
  36. package/dist/cjs/_hostSDK.994f6668.min.js +0 -1
@@ -571,6 +571,51 @@ declare module "@myop/sdk/host/componentCore" {
571
571
  [K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<R> : T[K];
572
572
  };
573
573
  }
574
+ declare module "@myop/sdk/host/components/myopExtractedWebComponent" {
575
+ import { BaseMyopComponent } from "@myop/sdk/host/components/IMyopComponent";
576
+ import { BaseMyopMessage } from "@myop/sdk/messages";
577
+ import { CleanupHandler, IComponentDefinitionConfig, ISkinConfig } from "@myop/sdk/common";
578
+ import { loaderOptions } from "@myop/sdk/host/hostSDK";
579
+ /**
580
+ * Component wrapper for Myop Web Components that are extracted from HTML
581
+ * and run directly on the host document (not in an iframe).
582
+ *
583
+ * These components use the native Web Components API (Custom Elements + Shadow DOM)
584
+ * and communicate via direct method calls and CustomEvents instead of postMessage.
585
+ */
586
+ export class MyopExtractedWebComponent extends BaseMyopComponent {
587
+ container: HTMLElement;
588
+ private customElement;
589
+ private tagName;
590
+ private ctaCleanup?;
591
+ private _ctaHandler?;
592
+ private _ctaQueue;
593
+ constructor(componentDefinition: IComponentDefinitionConfig, skin: ISkinConfig, container: HTMLElement, customElement: HTMLElement, tagName: string, options?: loaderOptions);
594
+ cleanupInspect: CleanupHandler;
595
+ inspect(): CleanupHandler;
596
+ hide(): void;
597
+ show(): void;
598
+ /**
599
+ * Initialize the component with data by calling myop_init_interface directly
600
+ */
601
+ initWithData(data: unknown): void;
602
+ /**
603
+ * Get current data from the component
604
+ */
605
+ getData(): unknown;
606
+ /**
607
+ * Set CTA handler - unified API with iframe components.
608
+ * Called via props.myop_cta_handler = handler
609
+ */
610
+ setCtaHandler(handler: (action: string, payload: unknown) => void): void;
611
+ /**
612
+ * For compatibility with message-based components.
613
+ * Web components don't use postMessage, so this is a no-op for most messages.
614
+ */
615
+ send: (message: BaseMyopMessage<any>) => CleanupHandler;
616
+ dispose: () => void;
617
+ }
618
+ }
574
619
  declare module "@myop/sdk/host/myopLoader" {
575
620
  export const LOADER_GRADIENT = "linear-gradient(135deg, #FF8651 0%, #FFBEA8 50%, #A397F5 100%)";
576
621
  export const FALLBACK_GRADIENT = "linear-gradient(135deg, #9CA3AF 0%, #D1D5DB 50%, #E5E7EB 100%)";
@@ -657,6 +702,7 @@ declare module "@myop/sdk/host" {
657
702
  export { hostSDK } from "@myop/sdk/host/hostSDK";
658
703
  export type { loaderOptions } from "@myop/sdk/host/hostSDK";
659
704
  export * from "@myop/sdk/host/components/IMyopComponent";
705
+ export * from "@myop/sdk/host/components/myopExtractedWebComponent";
660
706
  export * from "@myop/sdk/host/loaders/IMyopLoader";
661
707
  export * from "@myop/sdk/host/componentCore";
662
708
  export * from "@myop/sdk/host/myopLoader";
@@ -1531,13 +1577,30 @@ declare module "@myop/sdk/host/embeddedSDK" {
1531
1577
  }
1532
1578
  declare module "@myop/sdk/host/loaders/HTMLComponentLoader" {
1533
1579
  import { MyopWebComponent } from "@myop/sdk/host/components/myopWebcomponent";
1580
+ import { MyopExtractedWebComponent } from "@myop/sdk/host/components/myopExtractedWebComponent";
1534
1581
  import { BaseMyopLoader } from "@myop/sdk/host/loaders/IMyopLoader";
1535
1582
  import { loaderOptions } from "@myop/sdk/host/hostSDK";
1536
1583
  import { IComponentDefinitionConfig, ISkinConfig } from "@myop/sdk/common";
1537
1584
  import { MyopIframeComponent } from "@myop/sdk/host/components/myopIframeComponent";
1538
1585
  export class HTMLComponentLoader extends BaseMyopLoader {
1539
1586
  type: "HTMLLoader";
1540
- load: (componentDefinition: IComponentDefinitionConfig, skin: ISkinConfig, container: HTMLElement, options?: loaderOptions) => Promise<MyopIframeComponent | MyopWebComponent>;
1587
+ /**
1588
+ * Detect if HTML is a Myop Web Component (starts with marker comment)
1589
+ */
1590
+ private isMyopWebComponent;
1591
+ /**
1592
+ * Extract the web component script content from HTML
1593
+ */
1594
+ private extractWebComponentScript;
1595
+ /**
1596
+ * Execute the web component script on the host document
1597
+ */
1598
+ private executeWebComponentScript;
1599
+ /**
1600
+ * Load a Myop Web Component (extracted and run on host document)
1601
+ */
1602
+ private loadExtractedWebComponent;
1603
+ load: (componentDefinition: IComponentDefinitionConfig, skin: ISkinConfig, container: HTMLElement, options?: loaderOptions) => Promise<MyopExtractedWebComponent | MyopIframeComponent | MyopWebComponent>;
1541
1604
  }
1542
1605
  }
1543
1606
  declare module "@myop/sdk/helpers/applyStylesheet" {
@@ -1156,6 +1156,114 @@ var MyopRefComponent = class extends BaseMyopComponent {
1156
1156
  }
1157
1157
  };
1158
1158
 
1159
+ // src/host/components/myopExtractedWebComponent.ts
1160
+ var MyopExtractedWebComponent = class extends BaseMyopComponent {
1161
+ constructor(componentDefinition, skin, container, customElement, tagName, options) {
1162
+ super(componentDefinition, container, options);
1163
+ this.container = container;
1164
+ this.customElement = customElement;
1165
+ this.tagName = tagName;
1166
+ __publicField(this, "ctaCleanup");
1167
+ __publicField(this, "_ctaHandler");
1168
+ __publicField(this, "_ctaQueue", []);
1169
+ __publicField(this, "cleanupInspect", () => {
1170
+ });
1171
+ /**
1172
+ * For compatibility with message-based components.
1173
+ * Web components don't use postMessage, so this is a no-op for most messages.
1174
+ */
1175
+ __publicField(this, "send", (message) => {
1176
+ const cleanupHandler = super.send(message);
1177
+ console.debug("[MyopExtractedWebComponent] send() called - web components use direct API instead", message);
1178
+ return cleanupHandler;
1179
+ });
1180
+ __publicField(this, "dispose", () => {
1181
+ var _a;
1182
+ if (this.ctaCleanup) {
1183
+ this.ctaCleanup();
1184
+ }
1185
+ super.dispose();
1186
+ (_a = this.customElement.parentNode) == null ? void 0 : _a.removeChild(this.customElement);
1187
+ });
1188
+ this.element = customElement;
1189
+ this.setInitiated();
1190
+ }
1191
+ inspect() {
1192
+ this.cleanupInspect = setDebugStyle(this.id, "MyopExtractedWebComponent", 0, this.container, this.customElement, this.componentDefinition);
1193
+ return this.cleanupInspect;
1194
+ }
1195
+ hide() {
1196
+ this.customElement.style.opacity = "0";
1197
+ this.customElement.style.position = "absolute";
1198
+ this.customElement.style.pointerEvents = "none";
1199
+ this.customElement.style.visibility = "hidden";
1200
+ this.customElement.style.height = "0";
1201
+ this.customElement.style.width = "0";
1202
+ }
1203
+ show() {
1204
+ this.customElement.style.opacity = "1";
1205
+ this.customElement.style.position = "unset";
1206
+ this.customElement.style.pointerEvents = "all";
1207
+ this.customElement.style.visibility = "visible";
1208
+ this.customElement.style.height = "";
1209
+ this.customElement.style.width = "";
1210
+ }
1211
+ /**
1212
+ * Initialize the component with data by calling myop_init_interface directly
1213
+ */
1214
+ initWithData(data) {
1215
+ if (typeof this.customElement.myop_init_interface === "function") {
1216
+ this.customElement.myop_init_interface(data);
1217
+ }
1218
+ }
1219
+ /**
1220
+ * Get current data from the component
1221
+ */
1222
+ getData() {
1223
+ if (typeof this.customElement.myop_init_interface === "function") {
1224
+ return this.customElement.myop_init_interface();
1225
+ }
1226
+ return void 0;
1227
+ }
1228
+ /**
1229
+ * Set CTA handler - unified API with iframe components.
1230
+ * Called via props.myop_cta_handler = handler
1231
+ */
1232
+ setCtaHandler(handler) {
1233
+ if (this.ctaCleanup) {
1234
+ this.ctaCleanup();
1235
+ }
1236
+ this._ctaHandler = handler;
1237
+ if (this._ctaQueue.length > 0) {
1238
+ const queue = [...this._ctaQueue];
1239
+ this._ctaQueue = [];
1240
+ queue.forEach((item) => {
1241
+ if (!this.markedForDisposed) {
1242
+ handler(item.action, item.payload);
1243
+ }
1244
+ });
1245
+ }
1246
+ const listener = (e) => {
1247
+ var _a;
1248
+ const customEvent = e;
1249
+ if ((_a = customEvent.detail) == null ? void 0 : _a.action) {
1250
+ if (this._ctaHandler && !this.markedForDisposed) {
1251
+ this._ctaHandler(customEvent.detail.action, customEvent.detail.payload);
1252
+ } else if (!this._ctaHandler) {
1253
+ this._ctaQueue.push({
1254
+ action: customEvent.detail.action,
1255
+ payload: customEvent.detail.payload
1256
+ });
1257
+ }
1258
+ }
1259
+ };
1260
+ this.customElement.addEventListener("myop-cta", listener);
1261
+ this.ctaCleanup = () => {
1262
+ this.customElement.removeEventListener("myop-cta", listener);
1263
+ };
1264
+ }
1265
+ };
1266
+
1159
1267
  // src/host/componentCore.ts
1160
1268
  var createDebugTitle = (text, top, componentDefinitionConfig) => {
1161
1269
  const titleEl = document.createElement("a");
@@ -1208,6 +1316,19 @@ var connectProps = (component, propsConfig, selectedSkin) => {
1208
1316
  return false;
1209
1317
  }
1210
1318
  if (propConfig.behavior.type === PropConfigBehaviorTypes.code) {
1319
+ if (component instanceof MyopExtractedWebComponent) {
1320
+ const typedPropBehavior = propConfig.behavior;
1321
+ const propName = typedPropBehavior.remap || prop;
1322
+ if (propName === "myop_init_interface") {
1323
+ return (data) => {
1324
+ if (data === void 0) {
1325
+ return component.getData();
1326
+ }
1327
+ component.initWithData(data);
1328
+ };
1329
+ }
1330
+ return void 0;
1331
+ }
1211
1332
  if (selectedSkin.loader.type === SkinLoaders.HTMLLoader) {
1212
1333
  const typedLoader = selectedSkin.loader;
1213
1334
  if (typedLoader.shadowRootMode === ShadowRootModeType.localFrame) {
@@ -1242,6 +1363,18 @@ var connectProps = (component, propsConfig, selectedSkin) => {
1242
1363
  return false;
1243
1364
  }
1244
1365
  if (propConfig.behavior.type === PropConfigBehaviorTypes.code) {
1366
+ if (component instanceof MyopExtractedWebComponent) {
1367
+ const typedPropBehavior = propConfig.behavior;
1368
+ const propName = typedPropBehavior.remap || prop;
1369
+ if (propName === "myop_cta_handler") {
1370
+ component.setCtaHandler(value);
1371
+ return true;
1372
+ }
1373
+ if (propName === "myop_init_interface") {
1374
+ component.initWithData(value);
1375
+ return true;
1376
+ }
1377
+ }
1245
1378
  if (selectedSkin.loader.type === SkinLoaders.HTMLLoader) {
1246
1379
  const typedLoader = selectedSkin.loader;
1247
1380
  if (typedLoader.shadowRootMode === ShadowRootModeType.localFrame) {
@@ -1818,7 +1951,7 @@ var WebcomponentLoader = class extends BaseMyopLoader {
1818
1951
  };
1819
1952
 
1820
1953
  // version:myop-sdk-version
1821
- var myop_sdk_version_default = "0.3.14";
1954
+ var myop_sdk_version_default = "0.3.16";
1822
1955
 
1823
1956
  // src/webcomponent/messageHandlers/BaseWebComponentMessageHandler.ts
1824
1957
  var BaseWebComponentMessageHandler = class extends BaseContextMessageHandler {
@@ -2148,6 +2281,9 @@ var EMBEDDED_SDK_CONTENT = "";
2148
2281
  var HAS_EMBEDDED_SDK = false;
2149
2282
 
2150
2283
  // src/host/loaders/HTMLComponentLoader.ts
2284
+ var MYOP_WEB_COMPONENT_MARKER = "<!-- myop-web-component -->";
2285
+ var MYOP_WEB_COMPONENT_SCRIPT_ID = "myop-web-component";
2286
+ var extractedWebComponentScripts = /* @__PURE__ */ new Set();
2151
2287
  var seen2 = [];
2152
2288
  var sdk;
2153
2289
  var getInitiatedSdk = async () => {
@@ -2186,6 +2322,9 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
2186
2322
  __publicField(this, "type", SkinLoaders.HTMLLoader);
2187
2323
  __publicField(this, "load", async (componentDefinition, skin, container, options) => {
2188
2324
  const loaderConfig = skin.loader;
2325
+ if (this.isMyopWebComponent(loaderConfig.HTML)) {
2326
+ return this.loadExtractedWebComponent(componentDefinition, skin, container, loaderConfig.HTML, options);
2327
+ }
2189
2328
  let domId = "myop-comp-".concat(uuidv4());
2190
2329
  let element;
2191
2330
  if (loaderConfig.shadowRootMode === ShadowRootModeType.localFrame) {
@@ -2270,6 +2409,83 @@ var HTMLComponentLoader = class extends BaseMyopLoader {
2270
2409
  return new MyopWebComponent(componentDefinition, skin, container, element, options);
2271
2410
  });
2272
2411
  }
2412
+ /**
2413
+ * Detect if HTML is a Myop Web Component (starts with marker comment)
2414
+ */
2415
+ isMyopWebComponent(html) {
2416
+ return html.trimStart().startsWith(MYOP_WEB_COMPONENT_MARKER);
2417
+ }
2418
+ /**
2419
+ * Extract the web component script content from HTML
2420
+ */
2421
+ extractWebComponentScript(html) {
2422
+ const parser = new DOMParser();
2423
+ const doc = parser.parseFromString(html, "text/html");
2424
+ const script = doc.getElementById(MYOP_WEB_COMPONENT_SCRIPT_ID);
2425
+ return (script == null ? void 0 : script.textContent) || null;
2426
+ }
2427
+ /**
2428
+ * Execute the web component script on the host document
2429
+ */
2430
+ executeWebComponentScript(scriptContent, scriptId) {
2431
+ if (extractedWebComponentScripts.has(scriptId)) {
2432
+ console.log("[MyopWebComponent] Script already executed for ".concat(scriptId, ", skipping"));
2433
+ return;
2434
+ }
2435
+ const script = document.createElement("script");
2436
+ script.textContent = scriptContent;
2437
+ script.id = "myop-extracted-".concat(scriptId);
2438
+ document.head.appendChild(script);
2439
+ extractedWebComponentScripts.add(scriptId);
2440
+ console.log("[MyopWebComponent] Executed web component script: ".concat(scriptId));
2441
+ }
2442
+ /**
2443
+ * Load a Myop Web Component (extracted and run on host document)
2444
+ */
2445
+ async loadExtractedWebComponent(componentDefinition, skin, container, html, options) {
2446
+ const scriptContent = this.extractWebComponentScript(html);
2447
+ if (!scriptContent) {
2448
+ throw new Error('[MyopWebComponent] No <script id="myop-web-component"> found in HTML');
2449
+ }
2450
+ const scriptId = "".concat(componentDefinition.id, "-").concat(skin.id);
2451
+ const previousTagName = window.__MYOP_TAG_NAME__;
2452
+ this.executeWebComponentScript(scriptContent, scriptId);
2453
+ const tagName = window.__MYOP_TAG_NAME__;
2454
+ if (!tagName) {
2455
+ throw new Error("[MyopWebComponent] Script did not set window.__MYOP_TAG_NAME__");
2456
+ }
2457
+ if (previousTagName && previousTagName !== tagName) {
2458
+ console.warn("[MyopWebComponent] __MYOP_TAG_NAME__ changed from ".concat(previousTagName, " to ").concat(tagName));
2459
+ }
2460
+ const domId = "myop-comp-".concat(uuidv4());
2461
+ const element = document.createElement(tagName);
2462
+ element.id = domId;
2463
+ if (options == null ? void 0 : options.hidden) {
2464
+ element.style.opacity = "0";
2465
+ element.style.position = "absolute";
2466
+ element.style.height = "0";
2467
+ element.style.width = "0";
2468
+ element.style.pointerEvents = "none";
2469
+ element.style.visibility = "hidden";
2470
+ }
2471
+ if (!container.querySelector('[id^="myop-comp-"]')) {
2472
+ container.innerHTML = "";
2473
+ }
2474
+ this.appendChild(container, element, options);
2475
+ const component = new MyopExtractedWebComponent(
2476
+ componentDefinition,
2477
+ skin,
2478
+ container,
2479
+ element,
2480
+ tagName,
2481
+ options
2482
+ );
2483
+ if ((options == null ? void 0 : options.data) !== void 0) {
2484
+ component.initWithData(options.data);
2485
+ }
2486
+ console.log("[MyopWebComponent] Loaded <".concat(tagName, "> into container"));
2487
+ return component;
2488
+ }
2273
2489
  };
2274
2490
 
2275
2491
  // src/helpers/CloudRepository.ts