@kompasid/lit-web-components 0.5.7 → 0.5.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.
@@ -10,78 +10,6 @@ import { formatRupiah } from '../../utils/formatRupiah.js';
10
10
  import { addGoogleFonts } from '../../utils/googleFont.js';
11
11
  import { redirectToRegister, redirectToLogin } from '../../utils/cta.js';
12
12
  let KompasIdPaywallBody = class KompasIdPaywallBody extends LitElement {
13
- constructor() {
14
- super(...arguments);
15
- /**
16
- * Props
17
- */
18
- /**
19
- * prop slug untuk menghandle slug
20
- * prop isLogin untuk menghandle apakah user sudah login atau belum
21
- * prop type untuk menghandle tipe epaper
22
- * prop paywallData untuk menghandle data paywall
23
- * prop userGuid untuk menghandle user Guid
24
- * prop subscriptionStatus untuk menghandle status subscription user
25
- * prop countdownArticle untuk menghandle count artikel
26
- * prop swgEnable untuk menghandle swg apakah di aktifkan atau tidak
27
- * prop paywall_location = The location where user encounter the paywall
28
- * prop paywall_subscription_package = The name of the subscription package viewed by user
29
- * prop paywall_subscription_id = The ID of the subscription package viewed by user
30
- * prop paywall_subscription_price = The price of the subscriprtion package viewed by user
31
- * prop paywall_position = The position of the subscription package viewed by user
32
- * prop tracker_page_type = Type of the page
33
- * prop tracker_content_id = ID of article (slug)
34
- * prop tracker_content_type = Whether it's free article or paid article
35
- * prop tracker_content_title = The title of article
36
- * prop tracker_content_categories = The category of the content
37
- * prop tracker_user_type = Type of user based on their subscription
38
- * prop tracker_subscription_status = Status of their subscription
39
- * prop tracker_page_domain = Page Domain
40
- * prop tracker_metered_wall_type = The type of Metered Wall
41
- * prop tracker_metered_wall_balance = The balance of their metered wall
42
- * prop tracker_metered_wall_balance = The edition of epaper viewed by user
43
- * prop theme = The theme of the paywall component
44
- */
45
- this.slug = '';
46
- this.udin = 0;
47
- this.isLogin = false;
48
- this.type = 'reguler';
49
- this.paywallData = undefined;
50
- this.userGuid = '';
51
- this.subscriptionStatus = '';
52
- this.countdownArticle = 0;
53
- this.swgEnable = false;
54
- this.paywall_location = '';
55
- this.paywall_subscription_package = '';
56
- this.paywall_subscription_id = 0;
57
- this.paywall_subscription_price = 0;
58
- this.paywall_position = 0;
59
- this.tracker_page_type = '';
60
- this.tracker_content_id = '';
61
- this.tracker_content_title = '';
62
- this.tracker_content_categories = '';
63
- this.tracker_content_type = '';
64
- this.tracker_user_type = '';
65
- this.tracker_subscription_status = '';
66
- this.tracker_page_domain = '';
67
- this.tracker_metered_wall_type = '';
68
- this.tracker_metered_wall_balance = 0;
69
- this.tracker_epaper_edition = '';
70
- this.theme = '';
71
- /**
72
- * State
73
- */
74
- this.isExtensionsOpened = false;
75
- this.kompasAkunHost = 'https://akun.kompas.id';
76
- this.kompasApigenHost = 'https://apigen.kompas.id';
77
- this.kompasApiWcmHost = 'https://apiwcm.kompas.id';
78
- this.kompasLoginHost = 'https://account.kompas.id/login';
79
- this.epaperHost = 'https://epaper.kompas.id';
80
- this.swgPublisherName = 'Harian Kompas';
81
- this.swgPublisherId = 'kompas.id';
82
- this.swgProductId = 'kompas.id:kompas_digital_premium';
83
- this.errorFlag = 0;
84
- }
85
13
  /**
86
14
  * Getter
87
15
  */
@@ -100,7 +28,17 @@ let KompasIdPaywallBody = class KompasIdPaywallBody extends LitElement {
100
28
  redirectToCheckout(url, name, id, price, position) {
101
29
  this.sendDataLayeronButtonBuyPackage(name, id, price, position);
102
30
  const originHost = encodeURIComponent(window.location.href);
103
- const source = this.type === 'epaper' ? 'epaper' : 'article';
31
+ let source;
32
+ switch (this.type) {
33
+ case 'epaper':
34
+ source = 'epaper';
35
+ break;
36
+ case 'audio':
37
+ source = 'news_audio';
38
+ break;
39
+ default:
40
+ source = 'article';
41
+ }
104
42
  const directUrlCheckout = `${url}${originHost}&source=${source}`;
105
43
  window.open(directUrlCheckout);
106
44
  }
@@ -115,6 +53,17 @@ let KompasIdPaywallBody = class KompasIdPaywallBody extends LitElement {
115
53
  this.sendDataLayeronHelpDesk();
116
54
  window.open('https://api.whatsapp.com/send/?phone=6281290050800&text=Halo,%20saya%20perlu%20informasi%20mengenai%20kompas.id');
117
55
  }
56
+ close() {
57
+ this.isOpen = false;
58
+ }
59
+ handleClickOutside() {
60
+ if (this.isOpen) {
61
+ if (this.targetElement instanceof HTMLElement &&
62
+ this.targetElement.classList.contains('wrapper-body')) {
63
+ this.close();
64
+ }
65
+ }
66
+ }
118
67
  parsePrice(price) {
119
68
  const lowerCasePrice = price.toLowerCase();
120
69
  if (lowerCasePrice.startsWith('rp')) {
@@ -295,25 +244,112 @@ let KompasIdPaywallBody = class KompasIdPaywallBody extends LitElement {
295
244
  jsonHead.appendChild(jsonScript);
296
245
  }
297
246
  }
247
+ constructor() {
248
+ super();
249
+ /**
250
+ * Props
251
+ */
252
+ /**
253
+ * prop slug untuk menghandle slug
254
+ * prop isLogin untuk menghandle apakah user sudah login atau belum
255
+ * prop type untuk menghandle tipe epaper
256
+ * prop paywallData untuk menghandle data paywall
257
+ * prop userGuid untuk menghandle user Guid
258
+ * prop subscriptionStatus untuk menghandle status subscription user
259
+ * prop countdownArticle untuk menghandle count artikel
260
+ * prop swgEnable untuk menghandle swg apakah di aktifkan atau tidak
261
+ * prop paywall_location = The location where user encounter the paywall
262
+ * prop paywall_subscription_package = The name of the subscription package viewed by user
263
+ * prop paywall_subscription_id = The ID of the subscription package viewed by user
264
+ * prop paywall_subscription_price = The price of the subscriprtion package viewed by user
265
+ * prop paywall_position = The position of the subscription package viewed by user
266
+ * prop tracker_page_type = Type of the page
267
+ * prop tracker_content_id = ID of article (slug)
268
+ * prop tracker_content_type = Whether it's free article or paid article
269
+ * prop tracker_content_title = The title of article
270
+ * prop tracker_content_categories = The category of the content
271
+ * prop tracker_user_type = Type of user based on their subscription
272
+ * prop tracker_subscription_status = Status of their subscription
273
+ * prop tracker_page_domain = Page Domain
274
+ * prop tracker_metered_wall_type = The type of Metered Wall
275
+ * prop tracker_metered_wall_balance = The balance of their metered wall
276
+ * prop tracker_metered_wall_balance = The edition of epaper viewed by user
277
+ * prop theme = The theme of the paywall component
278
+ * prop isOpen = The condition for the visibility of the component
279
+ */
280
+ this.slug = '';
281
+ this.isLogin = false;
282
+ this.type = 'reguler';
283
+ this.paywallData = undefined;
284
+ this.userGuid = '';
285
+ this.subscriptionStatus = '';
286
+ this.countdownArticle = 0;
287
+ this.swgEnable = false;
288
+ this.paywall_location = '';
289
+ this.paywall_subscription_package = '';
290
+ this.paywall_subscription_id = 0;
291
+ this.paywall_subscription_price = 0;
292
+ this.paywall_position = 0;
293
+ this.tracker_page_type = '';
294
+ this.tracker_content_id = '';
295
+ this.tracker_content_title = '';
296
+ this.tracker_content_categories = '';
297
+ this.tracker_content_type = '';
298
+ this.tracker_user_type = '';
299
+ this.tracker_subscription_status = '';
300
+ this.tracker_page_domain = '';
301
+ this.tracker_metered_wall_type = '';
302
+ this.tracker_metered_wall_balance = 0;
303
+ this.tracker_epaper_edition = '';
304
+ this.theme = '';
305
+ this.isOpen = true;
306
+ /**
307
+ * State
308
+ */
309
+ this.isExtensionsOpened = false;
310
+ this.kompasAkunHost = 'https://akun.kompas.id';
311
+ this.kompasApigenHost = 'https://apigen.kompas.id';
312
+ this.kompasApiWcmHost = 'https://apiwcm.kompas.id';
313
+ this.kompasLoginHost = 'https://account.kompas.id/login';
314
+ this.epaperHost = 'https://epaper.kompas.id';
315
+ this.swgPublisherName = 'Harian Kompas';
316
+ this.swgPublisherId = 'kompas.id';
317
+ this.swgProductId = 'kompas.id:kompas_digital_premium';
318
+ this.errorFlag = 0;
319
+ this.handleClickOutside = this.handleClickOutside.bind(this);
320
+ }
321
+ createRenderRoot() {
322
+ const root = super.createRenderRoot();
323
+ root.addEventListener('click', (e) => (this.targetElement = e.target));
324
+ return root;
325
+ }
298
326
  async connectedCallback() {
299
- var _a;
300
327
  super.connectedCallback();
301
328
  await this.updateComplete;
302
329
  if (this.swgEnable) {
303
330
  this.jsonScript();
304
- this.buttonElement = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById('subscribe-with-google');
305
- if (this.buttonElement) {
306
- const head = document.querySelector('head');
307
- const script = document.createElement('script');
308
- script.src = 'https://news.google.com/swg/js/v1/swg.js';
309
- script.defer = true;
310
- script.onload = this.subscribeWithGoogleButton();
311
- if (head) {
312
- head.appendChild(script);
331
+ const appendSWGButton = () => {
332
+ var _a;
333
+ this.buttonElement = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById('subscribe-with-google');
334
+ if (this.buttonElement) {
335
+ const head = document.querySelector('head');
336
+ const script = document.createElement('script');
337
+ script.src = 'https://news.google.com/swg/js/v1/swg.js';
338
+ script.defer = true;
339
+ script.onload = this.subscribeWithGoogleButton();
340
+ if (head) {
341
+ head.appendChild(script);
342
+ }
313
343
  }
314
- }
344
+ };
345
+ setTimeout(appendSWGButton, 500);
315
346
  }
316
347
  addGoogleFonts(['pt-sans', 'lora']);
348
+ document.addEventListener('click', this.handleClickOutside);
349
+ }
350
+ async disconnectedCallback() {
351
+ super.disconnectedCallback();
352
+ document.removeEventListener('click', this.handleClickOutside);
317
353
  }
318
354
  otherPackagesClicked() {
319
355
  this.sendDataLayerOtherPackagesClicked();
@@ -459,33 +495,38 @@ let KompasIdPaywallBody = class KompasIdPaywallBody extends LitElement {
459
495
  /**
460
496
  * Component
461
497
  */
462
- headerSection(type) {
463
- const headerSectionText = type === 'epaper'
464
- ? 'Akses ePaper Ini dengan Berlangganan'
465
- : 'Lanjut Baca Artikel Ini dengan Berlangganan';
466
- return html `
467
- <div class="flex w-full items-center justify-center">
468
- ${type === 'epaper'
469
- ? html `<button
470
- @click=${this.redirectToPrevUrl}
471
- class="hidden lg:block w-8 h-8 ${this.isDark
498
+ headerSection(type, title) {
499
+ let buttonContent;
500
+ if (type === 'epaper') {
501
+ buttonContent = html ` <button
502
+ @click=${this.redirectToPrevUrl}
503
+ class="hidden lg:block w-8 h-8 pl-4 ${this.isDark
472
504
  ? 'text-blue-300'
473
- : 'text-blue-600'} pl-4"
474
- >
475
- ${unsafeSVG(getFontAwesomeIcon('fas', 'arrow-left'))}
476
- </button>`
477
- : nothing}
478
- <h4
479
- class="text-base flex justify-center self-center md:block md:text-xl ${this
480
- .isDark
481
- ? 'text-white'
482
- : 'text-grey-600'}
483
- text-center font-lora font-bold tracking-wide md:tracking-normal w-4/5 md:w-full"
484
- >
485
- ${headerSectionText}
486
- </h4>
487
- ${type === 'epaper'
488
- ? html `<div class="w-10 hidden lg:flex"></div>`
505
+ : 'text-blue-600'}"
506
+ >
507
+ ${unsafeSVG(getFontAwesomeIcon('fas', 'arrow-left'))}
508
+ </button>`;
509
+ }
510
+ else if (type === 'audio') {
511
+ buttonContent = html ` <button
512
+ @click=${this.close}
513
+ class="hidden md:block w-8 h-8 pl-4 ${this.isDark
514
+ ? 'text-blue-300'
515
+ : 'text-blue-600'}"
516
+ >
517
+ ${unsafeSVG(getFontAwesomeIcon('fas', 'xmark', 24, 24))}
518
+ </button>`;
519
+ }
520
+ else {
521
+ buttonContent = nothing;
522
+ }
523
+ const headerClass = `text-base flex justify-center self-center md:block md:text-xl ${this.isDark ? 'text-white' : 'text-grey-600'} text-center font-lora font-bold tracking-wide md:tracking-normal w-4/5 md:w-full ${type === 'audio' && 'sm:px-16 md:px-20'}`;
524
+ return html `
525
+ <div class="flex w-full items-start justify-center">
526
+ ${buttonContent}
527
+ <h4 class=${headerClass}>${title}</h4>
528
+ ${type === 'epaper' || type === 'audio'
529
+ ? html `<div class="w-10 hidden md:flex"></div>`
489
530
  : nothing}
490
531
  </div>
491
532
  `;
@@ -693,7 +734,7 @@ let KompasIdPaywallBody = class KompasIdPaywallBody extends LitElement {
693
734
  <h6
694
735
  class="text-xs md:text-sm ${this.isDark
695
736
  ? 'text-green-300'
696
- : 'text-green-500'} font-bold px-4 "
737
+ : 'text-green-500'} font-bold px-4"
697
738
  >
698
739
  Langganan
699
740
  </h6>
@@ -711,17 +752,30 @@ let KompasIdPaywallBody = class KompasIdPaywallBody extends LitElement {
711
752
  </div>
712
753
  `;
713
754
  }
714
- topNavigator() {
755
+ topNavigator(type) {
756
+ let icon;
757
+ let buttonText;
758
+ let clickAction;
759
+ if (type === 'audio') {
760
+ icon = getFontAwesomeIcon('fas', 'xmark');
761
+ buttonText = 'Tutup';
762
+ clickAction = this.close.bind(this);
763
+ }
764
+ else {
765
+ icon = getFontAwesomeIcon('fas', 'arrow-left');
766
+ buttonText = 'Kembali';
767
+ clickAction = this.redirectToPrevUrl.bind(this);
768
+ }
715
769
  return html `
716
- <div class="flex lg:hidden items-center w-full pb-4 ">
770
+ <div class="flex md:hidden w-full pb-4">
717
771
  <button
718
- @click=${this.redirectToPrevUrl}
772
+ @click=${clickAction}
719
773
  class="text-xs md:text-lg text-white flex flex-row"
720
774
  >
721
775
  <div class="icon-lg icon-white w-4 h-4 mr-3.5 md:mr-5 pt-0.5">
722
- ${unsafeSVG(getFontAwesomeIcon('fas', 'arrow-left'))}
776
+ ${unsafeSVG(icon)}
723
777
  </div>
724
- Kembali
778
+ ${buttonText}
725
779
  </button>
726
780
  </div>
727
781
  `;
@@ -794,7 +848,7 @@ let KompasIdPaywallBody = class KompasIdPaywallBody extends LitElement {
794
848
  <p
795
849
  class="${this.isDark
796
850
  ? 'text-dark-7'
797
- : 'text-grey-500'} text-[11px] md:text-xs whitespace-nowrap w-full "
851
+ : 'text-grey-500'} text-[11px] md:text-xs whitespace-nowrap w-full"
798
852
  >
799
853
  Subscribe with
800
854
  </p>
@@ -814,26 +868,31 @@ let KompasIdPaywallBody = class KompasIdPaywallBody extends LitElement {
814
868
  * Render Statement
815
869
  */
816
870
  render() {
817
- var _a, _b, _c, _d, _e, _f, _g, _h;
871
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
818
872
  return html `
819
873
  <div
820
874
  class="${this.type === 'epaper'
821
875
  ? 'bg-transparent wrapper-body mx-2'
876
+ : 'wrapper-body'}
877
+ ${this.type === 'audio'
878
+ ? `${this.isOpen ? 'visible' : 'invisible'} fixed w-full h-full inset-0 flex justify-center items-center z-50 bg-black bg-opacity-75`
822
879
  : 'wrapper-body'}"
823
880
  >
824
881
  <div
825
- class="flex flex-col justify-center items-center w-full max-w-screen-sm my-5 relative"
882
+ class="flex flex-col justify-center items-center w-full max-w-screen-sm my-5 px-2 relative"
826
883
  >
827
- ${this.type === 'epaper' ? this.topNavigator() : nothing}
884
+ ${this.type === 'epaper' || this.type === 'audio'
885
+ ? this.topNavigator(this.type)
886
+ : nothing}
828
887
  <div
829
888
  class="flex w-full flex-col items-center justify-center ${this
830
889
  .isDark
831
890
  ? 'bg-dark-3'
832
- : 'bg-blue-100'} rounded-xl pt-6 md:pt-8 relative"
891
+ : 'bg-blue-100'} rounded-xl pt-6 md:pt-8 relative"
833
892
  >
834
- ${this.headerSection(this.type)}
835
- ${this.descriptionSection((_c = (_b = (_a = this.paywallData) === null || _a === void 0 ? void 0 : _a.informations) === null || _b === void 0 ? void 0 : _b.description) !== null && _c !== void 0 ? _c : [])}
836
- ${this.packagesSection((_e = (_d = this.paywallData) === null || _d === void 0 ? void 0 : _d.packages) !== null && _e !== void 0 ? _e : {})}
893
+ ${this.headerSection(this.type, (_c = (_b = (_a = this.paywallData) === null || _a === void 0 ? void 0 : _a.informations) === null || _b === void 0 ? void 0 : _b.title) !== null && _c !== void 0 ? _c : '')}
894
+ ${this.descriptionSection((_f = (_e = (_d = this.paywallData) === null || _d === void 0 ? void 0 : _d.informations) === null || _e === void 0 ? void 0 : _e.description) !== null && _f !== void 0 ? _f : [])}
895
+ ${this.packagesSection((_h = (_g = this.paywallData) === null || _g === void 0 ? void 0 : _g.packages) !== null && _h !== void 0 ? _h : {})}
837
896
  ${this.informationPackages()}
838
897
  ${!this.isLogin
839
898
  ? html `
@@ -848,7 +907,7 @@ let KompasIdPaywallBody = class KompasIdPaywallBody extends LitElement {
848
907
  ${this.userAction()} ${this.sendDataLayeronPaywallBody()}
849
908
  </div>
850
909
  ${this.isExtensionsOpened
851
- ? this.paymentMobileExtension((_h = (_g = (_f = this.paywallData) === null || _f === void 0 ? void 0 : _f.payment) === null || _g === void 0 ? void 0 : _g.ekstension) !== null && _h !== void 0 ? _h : [])
910
+ ? this.paymentMobileExtension((_l = (_k = (_j = this.paywallData) === null || _j === void 0 ? void 0 : _j.payment) === null || _k === void 0 ? void 0 : _k.ekstension) !== null && _l !== void 0 ? _l : [])
852
911
  : nothing}
853
912
  </div>
854
913
  </div>
@@ -873,9 +932,6 @@ KompasIdPaywallBody.styles = [
873
932
  __decorate([
874
933
  property({ type: String })
875
934
  ], KompasIdPaywallBody.prototype, "slug", void 0);
876
- __decorate([
877
- property({ type: Number })
878
- ], KompasIdPaywallBody.prototype, "udin", void 0);
879
935
  __decorate([
880
936
  property({ type: Boolean })
881
937
  ], KompasIdPaywallBody.prototype, "isLogin", void 0);
@@ -948,6 +1004,9 @@ __decorate([
948
1004
  __decorate([
949
1005
  property({ type: String })
950
1006
  ], KompasIdPaywallBody.prototype, "theme", void 0);
1007
+ __decorate([
1008
+ property({ type: Boolean })
1009
+ ], KompasIdPaywallBody.prototype, "isOpen", void 0);
951
1010
  __decorate([
952
1011
  state()
953
1012
  ], KompasIdPaywallBody.prototype, "isExtensionsOpened", void 0);