@inappstory/slide-api 0.0.18 → 0.0.20

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/dist/index.js CHANGED
@@ -1252,7 +1252,7 @@ class WidgetBase {
1252
1252
  this.id = `w_${this.elementId}_${WidgetBase.widgetIndex}`;
1253
1253
  ++WidgetBase.widgetIndex;
1254
1254
  }
1255
- refreshUserData(localData) { }
1255
+ onRefreshUserData(localData) { }
1256
1256
  static widgetCacheKey = "ias.story-element";
1257
1257
  static widgetClassName = "";
1258
1258
  static getInstance(element) {
@@ -1431,13 +1431,14 @@ class WidgetBase {
1431
1431
  console.error(error);
1432
1432
  }
1433
1433
  }
1434
+ /** @deprecated */
1434
1435
  static refreshUserData(nodes, localData) {
1435
1436
  const cb = (el, localData) => {
1436
1437
  const widgetElement = el.closest(`.${this.widgetClassName}`);
1437
1438
  if (widgetElement) {
1438
1439
  const widget = WidgetBase.getInstance(widgetElement);
1439
1440
  if (widget) {
1440
- widget.refreshUserData(localData);
1441
+ widget.onRefreshUserData(localData);
1441
1442
  }
1442
1443
  }
1443
1444
  };
@@ -1452,6 +1453,25 @@ class WidgetBase {
1452
1453
  });
1453
1454
  }
1454
1455
  }
1456
+ static onRefreshUserData(element, localData) {
1457
+ const cb = (el, localData) => {
1458
+ const widgetElement = el.closest(`.${this.widgetClassName}`);
1459
+ if (widgetElement) {
1460
+ const widget = WidgetBase.getInstance(widgetElement);
1461
+ if (widget) {
1462
+ widget.onRefreshUserData(localData);
1463
+ }
1464
+ }
1465
+ };
1466
+ if (localData != null) {
1467
+ cb(element, localData);
1468
+ }
1469
+ else {
1470
+ WidgetBase.getLocalData().then(localData => {
1471
+ cb(element, localData);
1472
+ });
1473
+ }
1474
+ }
1455
1475
  getPromotionalCodeFetchPath(promotionalCodeId) {
1456
1476
  switch (this.cardType) {
1457
1477
  case 4 /* CARD_TYPE.IN_APP_MESSAGING */:
@@ -1493,7 +1513,12 @@ class WidgetCopy extends WidgetBase {
1493
1513
  this.msgNoMoreCodes = getTagData(this.element, "msgNoMoreCodes");
1494
1514
  this.msgTryAgain = getTagData(this.element, "msgTryAgain");
1495
1515
  this.geometry = this.element.closest(".narrative-element-geometry");
1496
- this.resultLayer = this.slide.querySelector(".narrative-element-copy-result-variant");
1516
+ // this is result layer - skip init
1517
+ // todo prevent call Widget.init on result-layer
1518
+ if (this.element.classList.contains("narrative-element-copy-result-variant")) {
1519
+ return;
1520
+ }
1521
+ this.resultLayer = this.slide.querySelector(`.narrative-element-copy-result-variant[data-element-id="${this.elementId}"]`);
1497
1522
  if (this.resultLayer && this.geometry) {
1498
1523
  this.resultLayerGeometry = this.resultLayer.closest(".narrative-element-geometry");
1499
1524
  // create align center
@@ -1514,9 +1539,9 @@ class WidgetCopy extends WidgetBase {
1514
1539
  if (this.isPromotionalCode) {
1515
1540
  this.fetchPromoCode();
1516
1541
  }
1517
- // this.refreshUserData(this.options.localData);
1542
+ // this.onRefreshUserData(this.options.localData);
1518
1543
  }
1519
- refreshUserData(localData) { }
1544
+ onRefreshUserData(localData) { }
1520
1545
  isTransparentElement() {
1521
1546
  if (this.element) {
1522
1547
  try {
@@ -1658,7 +1683,9 @@ class WidgetCopy extends WidgetBase {
1658
1683
  }
1659
1684
  static api = {
1660
1685
  widgetClassName: WidgetCopy.widgetClassName,
1686
+ /** @deprecated */
1661
1687
  refreshUserData: WidgetCopy.refreshUserData,
1688
+ onRefreshUserData: WidgetCopy.onRefreshUserData,
1662
1689
  init: function (element, localData) {
1663
1690
  // prevent initWidget for result layer
1664
1691
  if (!element.classList.contains("narrative-element-copy-result-variant")) {
@@ -1719,9 +1746,9 @@ class WidgetDataInput extends WidgetBase {
1719
1746
  this.inputElement = getValueOrException(this.element.querySelector(".input-view .input"), "Empty .input-view .input");
1720
1747
  this.textElement = getValueOrException(this.inputElement.querySelector(".narrative-element-text-lines"), "Empty .narrative-element-text-lines");
1721
1748
  this.inputPlaceholderValue = this.textElement.innerHTML;
1722
- this.refreshUserData(this.options.localData);
1749
+ this.onRefreshUserData(this.options.localData);
1723
1750
  }
1724
- refreshUserData(localData) {
1751
+ onRefreshUserData(localData) {
1725
1752
  this.savedData = this.sdkApi.getCardServerData(this.cardId);
1726
1753
  this.localData = extend({}, this.savedData ?? {}, localData);
1727
1754
  const text = this.localData["_di_g_" + this.elementId + "_t"];
@@ -1852,7 +1879,9 @@ class WidgetDataInput extends WidgetBase {
1852
1879
  }
1853
1880
  static api = {
1854
1881
  widgetClassName: WidgetDataInput.widgetClassName,
1882
+ /** @deprecated */
1855
1883
  refreshUserData: WidgetDataInput.refreshUserData,
1884
+ onRefreshUserData: WidgetDataInput.onRefreshUserData,
1856
1885
  init: function (element, localData) {
1857
1886
  WidgetDataInput.initWidget(element, localData, (element, options) => new WidgetDataInput(element, options));
1858
1887
  },
@@ -1942,9 +1971,9 @@ class WidgetDateCountdown extends WidgetBase {
1942
1971
  // } else {
1943
1972
  this.initTimer();
1944
1973
  // }
1945
- // this.refreshUserData(this.options.localData);
1974
+ // this.onRefreshUserData(this.options.localData);
1946
1975
  }
1947
- refreshUserData(localData) { }
1976
+ onRefreshUserData(localData) { }
1948
1977
  pause() {
1949
1978
  if (this.timerInited) {
1950
1979
  this.pendingUpdate = false;
@@ -2070,7 +2099,9 @@ class WidgetDateCountdown extends WidgetBase {
2070
2099
  }
2071
2100
  static api = {
2072
2101
  widgetClassName: WidgetDateCountdown.widgetClassName,
2102
+ /** @deprecated */
2073
2103
  refreshUserData: WidgetDateCountdown.refreshUserData,
2104
+ onRefreshUserData: WidgetDateCountdown.onRefreshUserData,
2074
2105
  init: function (element, layers, localData) {
2075
2106
  WidgetDateCountdown.initWidget(element, localData, (element, options) => new WidgetDateCountdown(element, { ...options, layers }));
2076
2107
  },
@@ -2279,9 +2310,9 @@ class WidgetPoll extends WidgetBase {
2279
2310
  this.getUseResponseOnFirstButton = Boolean(getTagDataAsNumber(this.element, "getUserResponseOnFirstButton"));
2280
2311
  this.getUseResponseOnSecondButton = Boolean(getTagDataAsNumber(this.element, "getUserResponseOnSecondButton"));
2281
2312
  this.showClientTotalResult = Boolean(getTagDataAsNumber(this.element, "showClientTotalResult"));
2282
- this.refreshUserData(this.options.localData);
2313
+ this.onRefreshUserData(this.options.localData);
2283
2314
  }
2284
- refreshUserData(localData) {
2315
+ onRefreshUserData(localData) {
2285
2316
  this.savedData = this.sdkApi.getCardServerData(this.cardId);
2286
2317
  this.localData = extend({}, this.savedData ?? {}, localData);
2287
2318
  this.selectedVariant = undefined;
@@ -2711,7 +2742,9 @@ class WidgetPoll extends WidgetBase {
2711
2742
  }
2712
2743
  static api = {
2713
2744
  widgetClassName: WidgetPoll.widgetClassName,
2745
+ /** @deprecated */
2714
2746
  refreshUserData: WidgetPoll.refreshUserData,
2747
+ onRefreshUserData: WidgetPoll.onRefreshUserData,
2715
2748
  init: function (element, localData) {
2716
2749
  WidgetPoll.initWidget(element, localData, (element, options) => new WidgetPoll(element, options));
2717
2750
  },
@@ -2794,9 +2827,9 @@ class WidgetPollLayers extends WidgetBase {
2794
2827
  this._showLayout(this.layers, 0);
2795
2828
  }
2796
2829
  this.firstOpenTime = new Date().getTime();
2797
- this.refreshUserData(this.options.localData);
2830
+ this.onRefreshUserData(this.options.localData);
2798
2831
  }
2799
- refreshUserData(localData) { }
2832
+ onRefreshUserData(localData) { }
2800
2833
  _statEventPollVariant() {
2801
2834
  try {
2802
2835
  if (this.selectedVariant != null) {
@@ -2879,7 +2912,9 @@ class WidgetPollLayers extends WidgetBase {
2879
2912
  }
2880
2913
  static api = {
2881
2914
  widgetClassName: WidgetPollLayers.widgetClassName,
2915
+ /** @deprecated */
2882
2916
  refreshUserData: WidgetPollLayers.refreshUserData,
2917
+ onRefreshUserData: WidgetPollLayers.onRefreshUserData,
2883
2918
  init: function (element, layers, localData) {
2884
2919
  WidgetPollLayers.initWidget(element, localData, (element, options) => new WidgetPollLayers(element, { ...options, layers }));
2885
2920
  },
@@ -2944,9 +2979,9 @@ class WidgetQuest extends WidgetBase {
2944
2979
  this.label = this.element.querySelector(".label-view .label");
2945
2980
  this.variants = slice.call(this.element.querySelectorAll(".variants-box .variant-view"));
2946
2981
  this.selectedAnswer = undefined;
2947
- // this.refreshUserData(this.options.localData);
2982
+ // this.onRefreshUserData(this.options.localData);
2948
2983
  }
2949
- refreshUserData(localData) { }
2984
+ onRefreshUserData(localData) { }
2950
2985
  setCardSessionValue(name, value) {
2951
2986
  this.sdkApi.setCardSessionValue(this.element, name, value);
2952
2987
  }
@@ -3170,7 +3205,9 @@ class WidgetQuest extends WidgetBase {
3170
3205
  }
3171
3206
  static api = {
3172
3207
  widgetClassName: WidgetQuest.widgetClassName,
3208
+ /** @deprecated */
3173
3209
  refreshUserData: WidgetQuest.refreshUserData,
3210
+ onRefreshUserData: WidgetQuest.onRefreshUserData,
3174
3211
  init: function (element, localData) {
3175
3212
  return new Promise(function (resolve, reject) {
3176
3213
  WidgetQuest.initWidget(element, localData, (element, options) => new WidgetQuest(element, options)).then(localData => {
@@ -3241,9 +3278,9 @@ class WidgetQuiz extends WidgetBase {
3241
3278
  this.question = this.element.querySelector(".label-view .label");
3242
3279
  this.answers = slice.call(this.element.querySelectorAll(".variants-box .variant-view-group"));
3243
3280
  this.questionCount = getValueOrException(getTagDataAsNumber(this.slide, "quizCount"), "Empty quizCount");
3244
- this.refreshUserData(this.options.localData);
3281
+ this.onRefreshUserData(this.options.localData);
3245
3282
  }
3246
- refreshUserData(localData) {
3283
+ onRefreshUserData(localData) {
3247
3284
  this.savedData = this.sdkApi.getCardServerData(this.cardId);
3248
3285
  this.localData = extend({}, this.savedData ?? {}, localData);
3249
3286
  this.selectedAnswer = undefined;
@@ -3380,7 +3417,9 @@ class WidgetQuiz extends WidgetBase {
3380
3417
  }
3381
3418
  static api = {
3382
3419
  widgetClassName: WidgetQuiz.widgetClassName,
3420
+ /** @deprecated */
3383
3421
  refreshUserData: WidgetQuiz.refreshUserData,
3422
+ onRefreshUserData: WidgetQuiz.onRefreshUserData,
3384
3423
  init: function (element, localData) {
3385
3424
  WidgetQuiz.initWidget(element, localData, (element, options) => new WidgetQuiz(element, options));
3386
3425
  },
@@ -3434,9 +3473,9 @@ class WidgetQuizGrouped extends WidgetBase {
3434
3473
  this.question = this.element.querySelector(".label-view .label");
3435
3474
  this.answers = slice.call(this.element.querySelectorAll(".variants-box .variant-view-group"));
3436
3475
  this.questionCount = getValueOrException(getTagDataAsNumber(this.slide, "quizCount"), "Empty quizCount");
3437
- this.refreshUserData(this.options.localData);
3476
+ this.onRefreshUserData(this.options.localData);
3438
3477
  }
3439
- refreshUserData(localData) {
3478
+ onRefreshUserData(localData) {
3440
3479
  this.savedData = this.sdkApi.getCardServerData(this.cardId);
3441
3480
  this.localData = extend({}, this.savedData ?? {}, localData);
3442
3481
  this.selectedAnswer = undefined;
@@ -3577,7 +3616,9 @@ class WidgetQuizGrouped extends WidgetBase {
3577
3616
  }
3578
3617
  static api = {
3579
3618
  widgetClassName: WidgetQuizGrouped.widgetClassName,
3619
+ /** @deprecated */
3580
3620
  refreshUserData: WidgetQuizGrouped.refreshUserData,
3621
+ onRefreshUserData: WidgetQuizGrouped.onRefreshUserData,
3581
3622
  init: function (element, localData) {
3582
3623
  WidgetQuizGrouped.initWidget(element, localData, (element, options) => new WidgetQuizGrouped(element, options));
3583
3624
  },
@@ -3814,7 +3855,7 @@ class WidgetRangeSlider extends WidgetBase {
3814
3855
  this.handleDown = proxy(this.handleDown, this);
3815
3856
  this.handleMove = proxy(this.handleMove, this);
3816
3857
  this.handleEnd = proxy(this.handleEnd, this);
3817
- this.refreshUserData(this.options.localData);
3858
+ this.onRefreshUserData(this.options.localData);
3818
3859
  // Attach Events
3819
3860
  // window.addEventListener('resize.' + this.identifier, debounce(function() {
3820
3861
  // // Simulate resizeEnd event.
@@ -3825,7 +3866,7 @@ class WidgetRangeSlider extends WidgetBase {
3825
3866
  this.env.document.addEventListener("touchstart", this.handleDown);
3826
3867
  this.env.document.addEventListener("mousedown", this.handleDown);
3827
3868
  }
3828
- refreshUserData(localData) {
3869
+ onRefreshUserData(localData) {
3829
3870
  this.savedData = this.sdkApi.getCardServerData(this.cardId);
3830
3871
  this.localData = extend({}, this.savedData ?? {}, localData);
3831
3872
  if (this.localData["_rs_g_" + this.elementId + "_v"] !== undefined) {
@@ -4189,7 +4230,9 @@ class WidgetRangeSlider extends WidgetBase {
4189
4230
  }
4190
4231
  static api = {
4191
4232
  widgetClassName: WidgetRangeSlider.widgetClassName,
4233
+ /** @deprecated */
4192
4234
  refreshUserData: WidgetRangeSlider.refreshUserData,
4235
+ onRefreshUserData: WidgetRangeSlider.onRefreshUserData,
4193
4236
  init: function (element, localData) {
4194
4237
  WidgetRangeSlider.initWidget(element, localData, (element, options) => new WidgetRangeSlider(element, options));
4195
4238
  },
@@ -4251,9 +4294,9 @@ class WidgetRate extends WidgetBase {
4251
4294
  this.showDialogOnLowRate = Boolean(getValueOrDefault(getTagDataAsNumber(this.element, "showDialogOnLowRate"), 0));
4252
4295
  this.showDialogueMin = getValueOrDefault(getTagDataAsNumber(this.element, "showDialogueMin"), 1);
4253
4296
  this.showDialogueMax = getValueOrDefault(getTagDataAsNumber(this.element, "showDialogueMax"), 3);
4254
- this.refreshUserData(this.options.localData);
4297
+ this.onRefreshUserData(this.options.localData);
4255
4298
  }
4256
- refreshUserData(localData) {
4299
+ onRefreshUserData(localData) {
4257
4300
  this.savedData = this.sdkApi.getCardServerData(this.cardId);
4258
4301
  this.localData = extend({}, this.savedData ?? {}, localData);
4259
4302
  this.selectedStar = undefined;
@@ -4440,7 +4483,9 @@ class WidgetRate extends WidgetBase {
4440
4483
  }
4441
4484
  static api = {
4442
4485
  widgetClassName: WidgetRate.widgetClassName,
4486
+ /** @deprecated */
4443
4487
  refreshUserData: WidgetRate.refreshUserData,
4488
+ onRefreshUserData: WidgetRate.onRefreshUserData,
4444
4489
  init: function (element, localData) {
4445
4490
  WidgetRate.initWidget(element, localData, (element, options) => new WidgetRate(element, options));
4446
4491
  },
@@ -4504,9 +4549,9 @@ class WidgetShare extends WidgetBase {
4504
4549
  this.startDisabledTimeline();
4505
4550
  }
4506
4551
  this.btnDisabled = false;
4507
- // this.refreshUserData(this.options.localData);
4552
+ // this.onRefreshUserData(this.options.localData);
4508
4553
  }
4509
- refreshUserData(localData) { }
4554
+ onRefreshUserData(localData) { }
4510
4555
  _statEventShare(result, via) {
4511
4556
  try {
4512
4557
  const buttonText = this.element.textContent ?? "";
@@ -4571,7 +4616,9 @@ class WidgetShare extends WidgetBase {
4571
4616
  }
4572
4617
  static api = {
4573
4618
  widgetClassName: WidgetShare.widgetClassName,
4619
+ /** @deprecated */
4574
4620
  refreshUserData: WidgetShare.refreshUserData,
4621
+ onRefreshUserData: WidgetShare.onRefreshUserData,
4575
4622
  init: function (element, layers, localData) {
4576
4623
  WidgetShare.initWidget(element, localData, (element, options) => new WidgetShare(element, { ...options, layers }));
4577
4624
  },
@@ -4702,9 +4749,9 @@ class WidgetTest extends WidgetBase {
4702
4749
  }
4703
4750
  }
4704
4751
  }
4705
- // this.refreshUserData(this.options.localData);
4752
+ // this.onRefreshUserData(this.options.localData);
4706
4753
  }
4707
- refreshUserData(localData) { }
4754
+ onRefreshUserData(localData) { }
4708
4755
  _statEventVoteAnswer(answerScore) {
4709
4756
  try {
4710
4757
  if (this.selectedAnswer != null) {
@@ -4824,7 +4871,9 @@ class WidgetTest extends WidgetBase {
4824
4871
  }
4825
4872
  static api = {
4826
4873
  widgetClassName: WidgetTest.widgetClassName,
4874
+ /** @deprecated */
4827
4875
  refreshUserData: WidgetTest.refreshUserData,
4876
+ onRefreshUserData: WidgetTest.onRefreshUserData,
4828
4877
  init: function (element, localData) {
4829
4878
  WidgetTest.initWidget(element, localData, (element, options) => new WidgetTest(element, options));
4830
4879
  },
@@ -4901,7 +4950,7 @@ class WidgetVote extends WidgetBase {
4901
4950
  });
4902
4951
  this.hideClientTotalResult = getValueOrDefault(Boolean(getTagDataAsNumber(this.element, "hideClientTotalResult")), false);
4903
4952
  this.multipleChoice = getValueOrDefault(Boolean(getTagDataAsNumber(this.element, "multipleChoice")), false);
4904
- this.refreshUserData(this.options.localData);
4953
+ this.onRefreshUserData(this.options.localData);
4905
4954
  }
4906
4955
  _initFromLocalData() {
4907
4956
  const value = this.localData["_v_g_" + this.elementId + "_sa"];
@@ -4936,7 +4985,7 @@ class WidgetVote extends WidgetBase {
4936
4985
  this._fillWidget(true);
4937
4986
  }
4938
4987
  }
4939
- refreshUserData(localData) {
4988
+ onRefreshUserData(localData) {
4940
4989
  this.savedData = this.sdkApi.getCardServerData(this.cardId);
4941
4990
  this.localData = extend({}, this.savedData ?? {}, localData);
4942
4991
  this.selectedVariant = undefined;
@@ -5266,7 +5315,9 @@ class WidgetVote extends WidgetBase {
5266
5315
  }
5267
5316
  static api = {
5268
5317
  widgetClassName: WidgetVote.widgetClassName,
5318
+ /** @deprecated */
5269
5319
  refreshUserData: WidgetVote.refreshUserData,
5320
+ onRefreshUserData: WidgetVote.onRefreshUserData,
5270
5321
  init: function (element, localData) {
5271
5322
  WidgetVote.initWidget(element, localData, (element, options) => new WidgetVote(element, options));
5272
5323
  },
@@ -14729,9 +14780,9 @@ class WidgetBarcode extends WidgetBase {
14729
14780
  this.renderCodeView();
14730
14781
  this.renderCaptionView();
14731
14782
  }
14732
- // this.refreshUserData(this.options.localData);
14783
+ // this.onRefreshUserData(this.options.localData);
14733
14784
  }
14734
- refreshUserData(localData) { }
14785
+ onRefreshUserData(localData) { }
14735
14786
  isTransparentElement() {
14736
14787
  if (this.element) {
14737
14788
  try {
@@ -14937,7 +14988,9 @@ class WidgetBarcode extends WidgetBase {
14937
14988
  }
14938
14989
  static api = {
14939
14990
  widgetClassName: WidgetBarcode.widgetClassName,
14991
+ /** @deprecated */
14940
14992
  refreshUserData: WidgetBarcode.refreshUserData,
14993
+ onRefreshUserData: WidgetBarcode.onRefreshUserData,
14941
14994
  init: function (element, localData) {
14942
14995
  WidgetBarcode.initWidget(element, localData, (element, options) => new WidgetBarcode(element, options));
14943
14996
  },