@one-commerce/sdk-backoffice-vue3 1.11.0 → 1.13.0

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.
@@ -61,6 +61,8 @@ exports.Errors = exports.Message = void 0;
61
61
  Message["METHOD_CALL_ERROR"] = "one:method:error";
62
62
  Message["METHOD_RESULT"] = "one:method:result";
63
63
  Message["NAVIGATION_PUSH"] = "one:navigation:push";
64
+ Message["FRAME_HEIGHT_REQUEST"] = "one:frameheight:request";
65
+ Message["FRAME_HEIGHT_CHANGE"] = "one:frameheight:change";
64
66
  })(exports.Message || (exports.Message = {}));
65
67
  (function (Errors) {
66
68
  Errors["METHOD_DOES_NOT_EXISTS"] = "Method does not exists";
@@ -276,6 +278,10 @@ class Sdk extends Events {
276
278
 
277
279
  _defineProperty(this, "channel", void 0);
278
280
 
281
+ _defineProperty(this, "autoheight", true);
282
+
283
+ _defineProperty(this, "heightMutationObserver", null);
284
+
279
285
  _defineProperty(this, "origin", void 0);
280
286
 
281
287
  _defineProperty(this, "isInitialized", false);
@@ -311,18 +317,62 @@ class Sdk extends Events {
311
317
  Sdk.log('Emitting UPDATE with payload ', payload);
312
318
  this.emit(SdkInternalEvents.UPDATE, payload);
313
319
  });
320
+ this.channel.subscribe(main.Message.FRAME_HEIGHT_REQUEST, payload => {
321
+ if (this.autoheight) {
322
+ Sdk.log('Request for iframe height');
323
+ this.sendFrameHeight();
324
+ }
325
+ });
314
326
  this.channel.connect().then(() => {
315
327
  Sdk.log('Connected with ONe SDK');
328
+
329
+ if (this.autoheight) {
330
+ this.initializeHeightObserver();
331
+ }
316
332
  });
317
333
  this.setupOptions(options);
318
334
  Sdk.log('Initialized.');
319
335
  }
320
336
 
337
+ sendFrameHeight() {
338
+ const body = document.body,
339
+ html = document.documentElement;
340
+ const height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
341
+ this.channel.postMessage(main.Message.FRAME_HEIGHT_CHANGE, height);
342
+ }
343
+
344
+ initializeHeightObserver() {
345
+ if ("MutationObserver" in window) {
346
+ const onMutationObserved = () => {
347
+ this.sendFrameHeight();
348
+ };
349
+
350
+ const target = document.querySelector('body'),
351
+ config = {
352
+ attributes: true,
353
+ attributeOldValue: false,
354
+ characterData: true,
355
+ characterDataOldValue: false,
356
+ childList: true,
357
+ subtree: true
358
+ };
359
+ this.heightMutationObserver = new MutationObserver(onMutationObserved);
360
+ Sdk.log('Create body MutationObserver');
361
+ this.heightMutationObserver.observe(target, config);
362
+ } else {
363
+ Sdk.warn('MutationObserver not available. Auto-height functionality disabled.');
364
+ }
365
+ }
366
+
321
367
  setupOptions(options) {
322
368
  if (options) {
323
369
  if (typeof options.debug !== 'undefined') {
324
370
  Sdk.debug = options.debug;
325
371
  }
372
+
373
+ if (typeof options.autoheight !== 'undefined') {
374
+ this.autoheight = options.autoheight;
375
+ }
326
376
  }
327
377
  }
328
378