@kompasid/lit-web-components 0.8.27 → 0.8.28
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/demo/index.html +16 -0
- package/dist/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.d.ts +16 -0
- package/dist/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.js +114 -5
- package/dist/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.js.map +1 -1
- package/dist/src/components/kompasid-widget-recirculations-default/types.d.ts +8 -0
- package/dist/src/components/kompasid-widget-recirculations-default/types.js.map +1 -1
- package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.d.ts +1 -0
- package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.js +8 -1
- package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.js.map +1 -1
- package/dist/src/utils/IntersectionObserver.d.ts +21 -0
- package/dist/src/utils/IntersectionObserver.js +109 -0
- package/dist/src/utils/IntersectionObserver.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.ts +89 -5
- package/src/components/kompasid-widget-recirculations-default/readme.md +32 -17
- package/src/components/kompasid-widget-recirculations-default/types.ts +9 -0
- package/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.ts +10 -1
- package/src/utils/IntersectionObserver.ts +97 -0
package/demo/index.html
CHANGED
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
const trackerContentType = 'content_type'
|
|
71
71
|
const trackerContentTitle = 'content_title'
|
|
72
72
|
const trackerContentCategories = 'content_categories'
|
|
73
|
+
const trackerUserId = 'user_id'
|
|
73
74
|
const trackerUserType = 'user_type'
|
|
74
75
|
const trackerMeteredWallBalance = 0
|
|
75
76
|
const subscriptionStatus = 'subscription_status'
|
|
@@ -195,9 +196,24 @@
|
|
|
195
196
|
>
|
|
196
197
|
</kompasid-widget-recirculations-list>
|
|
197
198
|
|
|
199
|
+
<kompasid-widget-recirculations-list
|
|
200
|
+
widgetTitle="Terbaru"
|
|
201
|
+
apiSlug="list"
|
|
202
|
+
>
|
|
203
|
+
</kompasid-widget-recirculations-list>
|
|
204
|
+
|
|
198
205
|
<kompasid-widget-recirculations-default
|
|
199
206
|
.permalinkArticle=${widgetRelatedPost.permalinkArticle}
|
|
200
207
|
.slugs=${widgetRelatedPost.slugs}
|
|
208
|
+
.tracker_content_id=${trackerContentId}
|
|
209
|
+
.tracker_content_categories=${trackerContentCategories}
|
|
210
|
+
.tracker_user_id=${trackerUserId}
|
|
211
|
+
.tracker_user_type=${trackerUserType}
|
|
212
|
+
.tracker_subscription_status=${trackerSubscriptionStatus}
|
|
213
|
+
.tracker_subscription_package=${paywallSubscriptionPackage}
|
|
214
|
+
.tracker_metered_wall_type=${meteredWallType}
|
|
215
|
+
.tracker_metered_wall_balance=${trackerMeteredWallBalance}
|
|
216
|
+
.tracker_page_domain=${trackerPageDomain}
|
|
201
217
|
></kompasid-widget-recirculations-default>
|
|
202
218
|
|
|
203
219
|
<kompasid-widget-recirculations-default
|
|
@@ -6,6 +6,7 @@ export declare class KompasWidgetRecirculationsDefault extends LitElement {
|
|
|
6
6
|
* Props
|
|
7
7
|
*/
|
|
8
8
|
posts: Post[][];
|
|
9
|
+
recoID: string;
|
|
9
10
|
permalinkArticle: string;
|
|
10
11
|
userGuid: string;
|
|
11
12
|
slugs: string;
|
|
@@ -14,6 +15,15 @@ export declare class KompasWidgetRecirculationsDefault extends LitElement {
|
|
|
14
15
|
titleName: string;
|
|
15
16
|
titleLink: string;
|
|
16
17
|
isDark: boolean;
|
|
18
|
+
tracker_content_id: string;
|
|
19
|
+
tracker_content_categories: string;
|
|
20
|
+
tracker_user_id: string;
|
|
21
|
+
tracker_user_type: string;
|
|
22
|
+
tracker_subscription_status: string;
|
|
23
|
+
tracker_subscription_package: string;
|
|
24
|
+
tracker_metered_wall_type: string;
|
|
25
|
+
tracker_metered_wall_balance: number;
|
|
26
|
+
tracker_page_domain: string;
|
|
17
27
|
/**
|
|
18
28
|
* Fetch Data
|
|
19
29
|
*/
|
|
@@ -28,5 +38,11 @@ export declare class KompasWidgetRecirculationsDefault extends LitElement {
|
|
|
28
38
|
private titleOtherArticle;
|
|
29
39
|
renderChips(post: Post): import("lit").TemplateResult<1>[];
|
|
30
40
|
renderImage(post: Post): import("lit").TemplateResult<1> | "";
|
|
41
|
+
/**
|
|
42
|
+
* mengirim event ke datalayer
|
|
43
|
+
*/
|
|
44
|
+
private recoContentClicked;
|
|
45
|
+
private recoContentViewed;
|
|
46
|
+
handleObserver(): void;
|
|
31
47
|
render(): import("lit").TemplateResult<1>;
|
|
32
48
|
}
|
|
@@ -3,6 +3,8 @@ import { html, css, LitElement } from 'lit';
|
|
|
3
3
|
import { customElement, property } from 'lit/decorators.js';
|
|
4
4
|
import { TWStyles } from '../../../tailwind/tailwind.js';
|
|
5
5
|
import { useTimeDifference } from '../../utils/useTimeDIfference.js';
|
|
6
|
+
import { createIntersectionObserverComponent } from '../../utils/IntersectionObserver.js';
|
|
7
|
+
createIntersectionObserverComponent();
|
|
6
8
|
let KompasWidgetRecirculationsDefault = class KompasWidgetRecirculationsDefault extends LitElement {
|
|
7
9
|
constructor() {
|
|
8
10
|
super(...arguments);
|
|
@@ -10,6 +12,7 @@ let KompasWidgetRecirculationsDefault = class KompasWidgetRecirculationsDefault
|
|
|
10
12
|
* Props
|
|
11
13
|
*/
|
|
12
14
|
this.posts = [];
|
|
15
|
+
this.recoID = '';
|
|
13
16
|
this.permalinkArticle = '';
|
|
14
17
|
this.userGuid = '0';
|
|
15
18
|
this.slugs = '';
|
|
@@ -18,6 +21,17 @@ let KompasWidgetRecirculationsDefault = class KompasWidgetRecirculationsDefault
|
|
|
18
21
|
this.titleName = ''; // contoh: Artikel Terkait / Lainnya dalam 'kategori'
|
|
19
22
|
this.titleLink = ''; // contoh: /kategori/opini
|
|
20
23
|
this.isDark = false;
|
|
24
|
+
// data dari artikel yg sedang dibuka, untuk datalayer reco_content_viewed
|
|
25
|
+
this.tracker_content_id = ''; //
|
|
26
|
+
this.tracker_content_categories = '';
|
|
27
|
+
// datau user
|
|
28
|
+
this.tracker_user_id = '';
|
|
29
|
+
this.tracker_user_type = '';
|
|
30
|
+
this.tracker_subscription_status = '';
|
|
31
|
+
this.tracker_subscription_package = '';
|
|
32
|
+
this.tracker_metered_wall_type = '';
|
|
33
|
+
this.tracker_metered_wall_balance = 0;
|
|
34
|
+
this.tracker_page_domain = '';
|
|
21
35
|
}
|
|
22
36
|
/**
|
|
23
37
|
* Fetch Data
|
|
@@ -52,6 +66,9 @@ let KompasWidgetRecirculationsDefault = class KompasWidgetRecirculationsDefault
|
|
|
52
66
|
'Content-Type': 'application/json',
|
|
53
67
|
},
|
|
54
68
|
});
|
|
69
|
+
// get x-request-id from headers
|
|
70
|
+
const recoId = response.headers.get('X-Request-Id') || '';
|
|
71
|
+
this.recoID = recoId;
|
|
55
72
|
const result = await response.json();
|
|
56
73
|
if (result === null || result === void 0 ? void 0 : result.result) {
|
|
57
74
|
const items = result.result;
|
|
@@ -182,6 +199,54 @@ let KompasWidgetRecirculationsDefault = class KompasWidgetRecirculationsDefault
|
|
|
182
199
|
/>
|
|
183
200
|
`;
|
|
184
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* mengirim event ke datalayer
|
|
204
|
+
*/
|
|
205
|
+
recoContentClicked(post, recoIndex) {
|
|
206
|
+
var _a;
|
|
207
|
+
if (this.type !== 'relatedArticle')
|
|
208
|
+
return; // Hanya trigger event jika type 'relatedArticle'
|
|
209
|
+
window.dataLayer = window.dataLayer || [];
|
|
210
|
+
window.dataLayer.push({
|
|
211
|
+
// data dari component
|
|
212
|
+
event: 'reco_content_clicked',
|
|
213
|
+
content_id: post.name,
|
|
214
|
+
content_categories: ((_a = post.category) === null || _a === void 0 ? void 0 : _a.map(cat => cat.name).join('|')) || '',
|
|
215
|
+
reco_index: recoIndex,
|
|
216
|
+
reco_id: this.recoID || '',
|
|
217
|
+
reco_model: 'context',
|
|
218
|
+
// data dari implementor
|
|
219
|
+
user_id: this.tracker_user_id || 'NA',
|
|
220
|
+
user_type: this.tracker_user_type || '',
|
|
221
|
+
subscription_status: this.tracker_subscription_status || '',
|
|
222
|
+
subscription_package: this.tracker_subscription_package || '',
|
|
223
|
+
metered_wall_type: this.tracker_metered_wall_type || '',
|
|
224
|
+
metered_wall_balance: this.tracker_metered_wall_balance,
|
|
225
|
+
page_domain: this.tracker_page_domain || 'Kompas.id',
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
recoContentViewed() {
|
|
229
|
+
window.dataLayer = window.dataLayer || [];
|
|
230
|
+
window.dataLayer.push({
|
|
231
|
+
event: 'reco_content_viewed',
|
|
232
|
+
content_id: this.tracker_content_id || '',
|
|
233
|
+
content_categories: this.tracker_content_categories || '',
|
|
234
|
+
user_type: this.tracker_user_type || '',
|
|
235
|
+
subscription_status: this.tracker_subscription_status || '',
|
|
236
|
+
subscription_package: this.tracker_subscription_package || '',
|
|
237
|
+
metered_wall_type: this.tracker_metered_wall_type || '',
|
|
238
|
+
metered_wall_balance: this.tracker_metered_wall_balance,
|
|
239
|
+
page_domain: this.tracker_page_domain || 'Kompas.id',
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
handleObserver() {
|
|
243
|
+
if (this.type === 'relatedArticle') {
|
|
244
|
+
this.recoContentViewed();
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
// kalo mau implemen buat artikel lainnya
|
|
248
|
+
}
|
|
249
|
+
}
|
|
185
250
|
render() {
|
|
186
251
|
return html `
|
|
187
252
|
<div class="w-full ${this.isDark ? 'bg-dark-5 ' : ''}">
|
|
@@ -190,17 +255,25 @@ let KompasWidgetRecirculationsDefault = class KompasWidgetRecirculationsDefault
|
|
|
190
255
|
? this.titleRelatedArticle()
|
|
191
256
|
: this.titleOtherArticle()}
|
|
192
257
|
<!-- end: widget title -->
|
|
193
|
-
|
|
258
|
+
<intersection-observer-component
|
|
259
|
+
.onTrigger="${() => this.handleObserver()}"
|
|
260
|
+
></intersection-observer-component>
|
|
194
261
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 md:gap-8">
|
|
195
262
|
<!-- start: left-post-loop -->
|
|
196
263
|
<div class="grid grid-cols-1 gap-6">
|
|
197
264
|
${this.posts[0]
|
|
198
|
-
? this.posts[0].map(post => html `
|
|
265
|
+
? this.posts[0].map((post, index) => html `
|
|
199
266
|
<div class="w-full">
|
|
200
267
|
<div class="flex">
|
|
201
268
|
<div class="w-1/2">${this.renderImage(post)}</div>
|
|
202
269
|
<div class="flex-grow pl-4 w-1/2">
|
|
203
|
-
<a
|
|
270
|
+
<a
|
|
271
|
+
href="${post.permalink}?open_from=${this.type ===
|
|
272
|
+
'relatedArticle'
|
|
273
|
+
? 'Artikel_Terkait'
|
|
274
|
+
: 'Artikel_Lainnya'}"
|
|
275
|
+
@click="${() => this.recoContentClicked(post, index + 1)}"
|
|
276
|
+
>
|
|
204
277
|
${this.renderChips(post)}
|
|
205
278
|
<h5
|
|
206
279
|
class="hover:underline font-bold font-sans leading-tight text-lg md:text-xl ${this
|
|
@@ -229,12 +302,18 @@ let KompasWidgetRecirculationsDefault = class KompasWidgetRecirculationsDefault
|
|
|
229
302
|
<!-- start: right-post-loop -->
|
|
230
303
|
<div class="flex flex-col w-full">
|
|
231
304
|
${this.posts[1]
|
|
232
|
-
? this.posts[1].map(post => html `
|
|
305
|
+
? this.posts[1].map((post, index) => html `
|
|
233
306
|
<div class="mb-6">
|
|
234
307
|
<div class="flex">
|
|
235
308
|
<div class="w-1/2">${this.renderImage(post)}</div>
|
|
236
309
|
<div class="flex-grow pl-4 w-1/2">
|
|
237
|
-
<a
|
|
310
|
+
<a
|
|
311
|
+
href="${post.permalink}?open_from=${this.type ===
|
|
312
|
+
'relatedArticle'
|
|
313
|
+
? 'Artikel_Terkait'
|
|
314
|
+
: 'Artikel_Lainnya'}"
|
|
315
|
+
@click="${() => this.recoContentClicked(post, index + 6)}"
|
|
316
|
+
>
|
|
238
317
|
${this.renderChips(post)}
|
|
239
318
|
<h5
|
|
240
319
|
class="hover:underline font-bold font-sans leading-tight text-lg md:text-xl ${this
|
|
@@ -291,6 +370,9 @@ KompasWidgetRecirculationsDefault.styles = [
|
|
|
291
370
|
__decorate([
|
|
292
371
|
property({ type: Array })
|
|
293
372
|
], KompasWidgetRecirculationsDefault.prototype, "posts", void 0);
|
|
373
|
+
__decorate([
|
|
374
|
+
property({ type: String })
|
|
375
|
+
], KompasWidgetRecirculationsDefault.prototype, "recoID", void 0);
|
|
294
376
|
__decorate([
|
|
295
377
|
property({ type: String })
|
|
296
378
|
], KompasWidgetRecirculationsDefault.prototype, "permalinkArticle", void 0);
|
|
@@ -315,6 +397,33 @@ __decorate([
|
|
|
315
397
|
__decorate([
|
|
316
398
|
property({ type: Boolean })
|
|
317
399
|
], KompasWidgetRecirculationsDefault.prototype, "isDark", void 0);
|
|
400
|
+
__decorate([
|
|
401
|
+
property({ type: String })
|
|
402
|
+
], KompasWidgetRecirculationsDefault.prototype, "tracker_content_id", void 0);
|
|
403
|
+
__decorate([
|
|
404
|
+
property({ type: String })
|
|
405
|
+
], KompasWidgetRecirculationsDefault.prototype, "tracker_content_categories", void 0);
|
|
406
|
+
__decorate([
|
|
407
|
+
property({ type: String })
|
|
408
|
+
], KompasWidgetRecirculationsDefault.prototype, "tracker_user_id", void 0);
|
|
409
|
+
__decorate([
|
|
410
|
+
property({ type: String })
|
|
411
|
+
], KompasWidgetRecirculationsDefault.prototype, "tracker_user_type", void 0);
|
|
412
|
+
__decorate([
|
|
413
|
+
property({ type: String })
|
|
414
|
+
], KompasWidgetRecirculationsDefault.prototype, "tracker_subscription_status", void 0);
|
|
415
|
+
__decorate([
|
|
416
|
+
property({ type: String })
|
|
417
|
+
], KompasWidgetRecirculationsDefault.prototype, "tracker_subscription_package", void 0);
|
|
418
|
+
__decorate([
|
|
419
|
+
property({ type: String })
|
|
420
|
+
], KompasWidgetRecirculationsDefault.prototype, "tracker_metered_wall_type", void 0);
|
|
421
|
+
__decorate([
|
|
422
|
+
property({ type: Number })
|
|
423
|
+
], KompasWidgetRecirculationsDefault.prototype, "tracker_metered_wall_balance", void 0);
|
|
424
|
+
__decorate([
|
|
425
|
+
property({ type: String })
|
|
426
|
+
], KompasWidgetRecirculationsDefault.prototype, "tracker_page_domain", void 0);
|
|
318
427
|
KompasWidgetRecirculationsDefault = __decorate([
|
|
319
428
|
customElement('kompasid-widget-recirculations-default')
|
|
320
429
|
], KompasWidgetRecirculationsDefault);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KompasWidgetRecirculationsDefault.js","sourceRoot":"","sources":["../../../../src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AAG7D,IAAM,iCAAiC,GAAvC,MAAM,iCAAkC,SAAQ,UAAU;IAA1D;;QAuBL;;WAEG;QACwB,UAAK,GAAa,EAAE,CAAA;QACnB,qBAAgB,GAAG,EAAE,CAAA;QACrB,aAAQ,GAAG,GAAG,CAAA;QACd,UAAK,GAAG,EAAE,CAAA;QACV,SAAI,GAC9B,gBAAgB,CAAA;QACU,iBAAY,GAAG,EAAE,CAAA;QACjB,cAAS,GAAG,EAAE,CAAA,CAAC,qDAAqD;QACpE,cAAS,GAAG,EAAE,CAAA,CAAC,0BAA0B;QAExC,WAAM,GAAG,KAAK,CAAA;IAiR7C,CAAC;IA/QC;;OAEG;IACH,K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AAE,CAAC;oEAAe;AACd;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oEAAe;AAEb;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;iEAAe;AApChC,iCAAiC;IAD7C,aAAa,CAAC,wCAAwC,CAAC;GAC3C,iCAAiC,CAqT7C;SArTY,iCAAiC","sourcesContent":["import { html, css, LitElement } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport { TWStyles } from '../../../tailwind/tailwind.js'\nimport { Post } from './types.js'\nimport { useTimeDifference } from '../../utils/useTimeDIfference.js'\n\n@customElement('kompasid-widget-recirculations-default')\nexport class KompasWidgetRecirculationsDefault extends LitElement {\n static styles = [\n css`\n :host {\n font-family: 'PT Sans', sans-serif;\n }\n .chip {\n align-items: center;\n border-radius: 0.25rem;\n display: flex;\n font-family: 'PT Sans', sans-serif;\n font-size: 0.75rem;\n font-weight: bold;\n height: 1.5rem;\n justify-content: center;\n line-height: 1rem;\n margin-bottom: 0.25rem;\n padding: 0.375rem 0.5rem;\n }\n `,\n TWStyles,\n ]\n\n /**\n * Props\n */\n @property({ type: Array }) posts: Post[][] = []\n @property({ type: String }) permalinkArticle = ''\n @property({ type: String }) userGuid = '0'\n @property({ type: String }) slugs = ''\n @property({ type: String }) type: 'relatedArticle' | 'otherArticle' =\n 'relatedArticle'\n @property({ type: String }) mainCategory = ''\n @property({ type: String }) titleName = '' // contoh: Artikel Terkait / Lainnya dalam 'kategori'\n @property({ type: String }) titleLink = '' // contoh: /kategori/opini\n\n @property({ type: Boolean }) isDark = false\n\n /**\n * Fetch Data\n */\n async connectedCallback() {\n super.connectedCallback()\n try {\n if (this.type === 'relatedArticle') {\n await this.relatedArticles()\n } else if (this.type === 'otherArticle') {\n await this.otherArticles()\n }\n } catch (error) {\n this.handleFetchError(error)\n }\n }\n\n async relatedArticles() {\n const kompasApiAi = 'https://ai.kompas.id/api/v1'\n\n // Constructing parameters\n const params = new URLSearchParams()\n params.append('page_url', this.permalinkArticle)\n params.append('page_type', 'read')\n params.append('item_type', 'articles')\n params.append('guid', this.userGuid)\n params.append('slugs', this.slugs)\n\n // Constructing the URL with parameters\n const endpoint = `${kompasApiAi}/recommendation?${params.toString()}`\n\n const response = await fetch(endpoint, {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n\n const result = await response.json()\n\n if (result?.result) {\n const items = result.result\n const firstChunk = items.slice(0, 5)\n const secondChunk = items.slice(5, 7)\n this.posts = [Object.freeze(firstChunk), Object.freeze(secondChunk)]\n } else {\n throw new Error('Data artikel terkait tidak ditemukan')\n }\n }\n\n async otherArticles() {\n const kompasApiCdsSPA = 'https://cds.kompas.id/api/v2'\n\n // Constructing the URL with parameters\n const endpoint = `${kompasApiCdsSPA}/article/list/category/${this.mainCategory}`\n\n const response = await fetch(endpoint, {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n\n const result = await response.json()\n\n if (result?.result) {\n const items = result.result\n const firstChunk = items.slice(0, 5)\n const secondChunk = items.slice(5, 7)\n this.posts = [Object.freeze(firstChunk), Object.freeze(secondChunk)]\n } else {\n throw new Error('Data artikel lainnya tidak ditemukan')\n }\n }\n\n handleFetchError(error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Kesalahan tidak diketahui'\n alert(`Terjadi kesalahan: ${errorMessage}`)\n }\n\n /**\n * Render widget components\n */\n\n private titleRelatedArticle() {\n return html`\n <div class=\"flex font-sans uppercase items-start mb-6 mt-8\">\n <div>\n <h5\n class=\"capitalize font-bold font-sans text-lg md:text-xl ${this\n .isDark\n ? 'text-white'\n : 'text-grey-600'}\"\n >\n Artikel Terkait\n </h5>\n </div>\n </div>\n `\n }\n\n private titleOtherArticle() {\n return html`\n <a\n href=\"${this.titleLink}\"\n class=\"flex font-sans uppercase items-start mb-6 mt-8\"\n >\n <h5\n class=\"capitalize font-bold font-sans text-lg md:text-xl ${this.isDark\n ? 'text-blue-200'\n : 'text-brand-1'}\"\n >\n ${this.titleName}\n </h5>\n </a>\n `\n }\n\n renderChips(post: Post) {\n const chips = []\n const isAnalisis = post.postTag?.some(tag => tag.slug === 'analisis')\n const isEksklusif = post.postTag?.some(tag => tag.slug === 'eksklusif')\n const isKompasBrief = post.postTag?.some(tag => tag.slug === 'kompas-brief')\n const isFreemium = post.isFreemium === true\n\n if (isKompasBrief) {\n chips.push(\n html`\n <div class=\"flex\">\n <div class=\"chip bg-red-100 text-red-600\">Kompas Brief</div>\n </div>\n `\n )\n } else if (isEksklusif) {\n chips.push(\n html`\n <div class=\"flex\">\n <div class=\"chip bg-grey-600 text-white\">\n <img\n src=\"https://cdn-www.kompas.id/assets/img/icons/kompas-icon-small.svg\"\n alt=\"Kompas Icon\"\n style=\"width: 16px; height: 16px; margin-right: 4px;\"\n />\n Eksklusif\n </div>\n </div>\n `\n )\n } else if (isFreemium) {\n chips.push(\n html`\n <div class=\"flex\">\n <div class=\"chip bg-blue-100 text-brand-1\">Bebas Akses</div>\n </div>\n `\n )\n } else if (isAnalisis) {\n chips.push(\n html`\n <div class=\"flex\">\n <div class=\"chip bg-orange-100 text-orange-500\">Analisis</div>\n </div>\n `\n )\n }\n\n return chips\n }\n\n renderImage(post: Post) {\n const { thumbnailMedium } = post.thumbnails?.sizes || {}\n if (!thumbnailMedium) return ''\n\n const { permalink, width, height } = thumbnailMedium\n return html`\n <img\n src=\"${permalink}\"\n width=\"${width}\"\n height=\"${height}\"\n alt=\"${post.title}\"\n class=\"aspect-video object-cover w-full\"\n />\n `\n }\n\n render() {\n return html`\n <div class=\"w-full ${this.isDark ? 'bg-dark-5 ' : ''}\">\n <!-- start: widget title -->\n ${this.type === 'relatedArticle'\n ? this.titleRelatedArticle()\n : this.titleOtherArticle()}\n <!-- end: widget title -->\n\n <div class=\"grid grid-cols-1 md:grid-cols-2 gap-6 md:gap-8\">\n <!-- start: left-post-loop -->\n <div class=\"grid grid-cols-1 gap-6\">\n ${this.posts[0]\n ? this.posts[0].map(\n post => html`\n <div class=\"w-full\">\n <div class=\"flex\">\n <div class=\"w-1/2\">${this.renderImage(post)}</div>\n <div class=\"flex-grow pl-4 w-1/2\">\n <a href=\"${post.permalink}\">\n ${this.renderChips(post)}\n <h5\n class=\"hover:underline font-bold font-sans leading-tight text-lg md:text-xl ${this\n .isDark\n ? 'text-white'\n : 'text-grey-600'}\"\n >\n ${post.title}\n </h5>\n <p\n class=\"font-sans pt-2 text-sm ${this.isDark\n ? 'text-white'\n : 'text-grey-600'}\"\n >\n ${useTimeDifference(post.publishedDate)}\n </p>\n </a>\n </div>\n </div>\n </div>\n `\n )\n : 'Belum ada artikel'}\n </div>\n <!-- end: left-post-loop -->\n\n <!-- start: right-post-loop -->\n <div class=\"flex flex-col w-full\">\n ${this.posts[1]\n ? this.posts[1].map(\n post => html`\n <div class=\"mb-6\">\n <div class=\"flex\">\n <div class=\"w-1/2\">${this.renderImage(post)}</div>\n <div class=\"flex-grow pl-4 w-1/2\">\n <a href=\"${post.permalink}\">\n ${this.renderChips(post)}\n <h5\n class=\"hover:underline font-bold font-sans leading-tight text-lg md:text-xl ${this\n .isDark\n ? 'text-white'\n : 'text-grey-600'}\"\n >\n ${post.title}\n </h5>\n <p\n class=\"font-sans pt-2 text-sm ${this.isDark\n ? 'text-white'\n : 'text-grey-600'}\"\n >\n ${useTimeDifference(post.publishedDate)}\n </p>\n </a>\n </div>\n </div>\n </div>\n `\n )\n : ''}\n <!-- start: ads -->\n <slot></slot>\n <!-- end: ads -->\n </div>\n <!-- end: right-post-loop -->\n </div>\n </div>\n `\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"KompasWidgetRecirculationsDefault.js","sourceRoot":"","sources":["../../../../src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC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pB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4EAAuB;AACtB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sFAAiC;AAChC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uFAAkC;AACjC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oFAA+B;AAC9B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uFAAiC;AAChC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8EAAyB;AAjDzC,iCAAiC;IAD7C,aAAa,CAAC,wCAAwC,CAAC;GAC3C,iCAAiC,CAuY7C;SAvYY,iCAAiC","sourcesContent":["import { html, css, LitElement } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport { TWStyles } from '../../../tailwind/tailwind.js'\nimport { Post } from './types.js'\nimport { useTimeDifference } from '../../utils/useTimeDIfference.js'\nimport { createIntersectionObserverComponent } from '../../utils/IntersectionObserver.js'\n\ncreateIntersectionObserverComponent()\n@customElement('kompasid-widget-recirculations-default')\nexport class KompasWidgetRecirculationsDefault extends LitElement {\n static styles = [\n css`\n :host {\n font-family: 'PT Sans', sans-serif;\n }\n .chip {\n align-items: center;\n border-radius: 0.25rem;\n display: flex;\n font-family: 'PT Sans', sans-serif;\n font-size: 0.75rem;\n font-weight: bold;\n height: 1.5rem;\n justify-content: center;\n line-height: 1rem;\n margin-bottom: 0.25rem;\n padding: 0.375rem 0.5rem;\n }\n `,\n TWStyles,\n ]\n\n /**\n * Props\n */\n @property({ type: Array }) posts: Post[][] = []\n @property({ type: String }) recoID = ''\n @property({ type: String }) permalinkArticle = ''\n @property({ type: String }) userGuid = '0'\n @property({ type: String }) slugs = ''\n @property({ type: String }) type: 'relatedArticle' | 'otherArticle' =\n 'relatedArticle'\n @property({ type: String }) mainCategory = ''\n @property({ type: String }) titleName = '' // contoh: Artikel Terkait / Lainnya dalam 'kategori'\n @property({ type: String }) titleLink = '' // contoh: /kategori/opini\n\n @property({ type: Boolean }) isDark = false\n\n // data dari artikel yg sedang dibuka, untuk datalayer reco_content_viewed\n @property({ type: String }) tracker_content_id = '' //\n @property({ type: String }) tracker_content_categories = ''\n // datau user\n @property({ type: String }) tracker_user_id = ''\n @property({ type: String }) tracker_user_type = ''\n @property({ type: String }) tracker_subscription_status = ''\n @property({ type: String }) tracker_subscription_package = ''\n @property({ type: String }) tracker_metered_wall_type = ''\n @property({ type: Number }) tracker_metered_wall_balance = 0\n @property({ type: String }) tracker_page_domain = ''\n\n /**\n * Fetch Data\n */\n async connectedCallback() {\n super.connectedCallback()\n try {\n if (this.type === 'relatedArticle') {\n await this.relatedArticles()\n } else if (this.type === 'otherArticle') {\n await this.otherArticles()\n }\n } catch (error) {\n this.handleFetchError(error)\n }\n }\n\n async relatedArticles() {\n const kompasApiAi = 'https://ai.kompas.id/api/v1'\n\n // Constructing parameters\n const params = new URLSearchParams()\n params.append('page_url', this.permalinkArticle)\n params.append('page_type', 'read')\n params.append('item_type', 'articles')\n params.append('guid', this.userGuid)\n params.append('slugs', this.slugs)\n\n // Constructing the URL with parameters\n const endpoint = `${kompasApiAi}/recommendation?${params.toString()}`\n\n const response = await fetch(endpoint, {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n\n // get x-request-id from headers\n const recoId = response.headers.get('X-Request-Id') || ''\n this.recoID = recoId\n\n const result = await response.json()\n\n if (result?.result) {\n const items = result.result\n const firstChunk = items.slice(0, 5)\n const secondChunk = items.slice(5, 7)\n this.posts = [Object.freeze(firstChunk), Object.freeze(secondChunk)]\n } else {\n throw new Error('Data artikel terkait tidak ditemukan')\n }\n }\n\n async otherArticles() {\n const kompasApiCdsSPA = 'https://cds.kompas.id/api/v2'\n\n // Constructing the URL with parameters\n const endpoint = `${kompasApiCdsSPA}/article/list/category/${this.mainCategory}`\n\n const response = await fetch(endpoint, {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n\n const result = await response.json()\n\n if (result?.result) {\n const items = result.result\n const firstChunk = items.slice(0, 5)\n const secondChunk = items.slice(5, 7)\n this.posts = [Object.freeze(firstChunk), Object.freeze(secondChunk)]\n } else {\n throw new Error('Data artikel lainnya tidak ditemukan')\n }\n }\n\n handleFetchError(error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Kesalahan tidak diketahui'\n alert(`Terjadi kesalahan: ${errorMessage}`)\n }\n\n /**\n * Render widget components\n */\n\n private titleRelatedArticle() {\n return html`\n <div class=\"flex font-sans uppercase items-start mb-6 mt-8\">\n <div>\n <h5\n class=\"capitalize font-bold font-sans text-lg md:text-xl ${this\n .isDark\n ? 'text-white'\n : 'text-grey-600'}\"\n >\n Artikel Terkait\n </h5>\n </div>\n </div>\n `\n }\n\n private titleOtherArticle() {\n return html`\n <a\n href=\"${this.titleLink}\"\n class=\"flex font-sans uppercase items-start mb-6 mt-8\"\n >\n <h5\n class=\"capitalize font-bold font-sans text-lg md:text-xl ${this.isDark\n ? 'text-blue-200'\n : 'text-brand-1'}\"\n >\n ${this.titleName}\n </h5>\n </a>\n `\n }\n\n renderChips(post: Post) {\n const chips = []\n const isAnalisis = post.postTag?.some(tag => tag.slug === 'analisis')\n const isEksklusif = post.postTag?.some(tag => tag.slug === 'eksklusif')\n const isKompasBrief = post.postTag?.some(tag => tag.slug === 'kompas-brief')\n const isFreemium = post.isFreemium === true\n\n if (isKompasBrief) {\n chips.push(\n html`\n <div class=\"flex\">\n <div class=\"chip bg-red-100 text-red-600\">Kompas Brief</div>\n </div>\n `\n )\n } else if (isEksklusif) {\n chips.push(\n html`\n <div class=\"flex\">\n <div class=\"chip bg-grey-600 text-white\">\n <img\n src=\"https://cdn-www.kompas.id/assets/img/icons/kompas-icon-small.svg\"\n alt=\"Kompas Icon\"\n style=\"width: 16px; height: 16px; margin-right: 4px;\"\n />\n Eksklusif\n </div>\n </div>\n `\n )\n } else if (isFreemium) {\n chips.push(\n html`\n <div class=\"flex\">\n <div class=\"chip bg-blue-100 text-brand-1\">Bebas Akses</div>\n </div>\n `\n )\n } else if (isAnalisis) {\n chips.push(\n html`\n <div class=\"flex\">\n <div class=\"chip bg-orange-100 text-orange-500\">Analisis</div>\n </div>\n `\n )\n }\n\n return chips\n }\n\n renderImage(post: Post) {\n const { thumbnailMedium } = post.thumbnails?.sizes || {}\n if (!thumbnailMedium) return ''\n\n const { permalink, width, height } = thumbnailMedium\n return html`\n <img\n src=\"${permalink}\"\n width=\"${width}\"\n height=\"${height}\"\n alt=\"${post.title}\"\n class=\"aspect-video object-cover w-full\"\n />\n `\n }\n\n /**\n * mengirim event ke datalayer\n */\n private recoContentClicked(post: Post, recoIndex: number) {\n if (this.type !== 'relatedArticle') return // Hanya trigger event jika type 'relatedArticle'\n\n window.dataLayer = window.dataLayer || []\n window.dataLayer.push({\n // data dari component\n event: 'reco_content_clicked',\n content_id: post.name,\n content_categories: post.category?.map(cat => cat.name).join('|') || '',\n reco_index: recoIndex,\n reco_id: this.recoID || '',\n reco_model: 'context',\n // data dari implementor\n user_id: this.tracker_user_id || 'NA',\n user_type: this.tracker_user_type || '',\n subscription_status: this.tracker_subscription_status || '',\n subscription_package: this.tracker_subscription_package || '',\n metered_wall_type: this.tracker_metered_wall_type || '',\n metered_wall_balance: this.tracker_metered_wall_balance,\n page_domain: this.tracker_page_domain || 'Kompas.id',\n })\n }\n\n private recoContentViewed() {\n window.dataLayer = window.dataLayer || []\n window.dataLayer.push({\n event: 'reco_content_viewed',\n content_id: this.tracker_content_id || '',\n content_categories: this.tracker_content_categories || '',\n user_type: this.tracker_user_type || '',\n subscription_status: this.tracker_subscription_status || '',\n subscription_package: this.tracker_subscription_package || '',\n metered_wall_type: this.tracker_metered_wall_type || '',\n metered_wall_balance: this.tracker_metered_wall_balance,\n page_domain: this.tracker_page_domain || 'Kompas.id',\n })\n }\n\n handleObserver() {\n if (this.type === 'relatedArticle') {\n this.recoContentViewed()\n } else {\n // kalo mau implemen buat artikel lainnya\n }\n }\n\n render() {\n return html`\n <div class=\"w-full ${this.isDark ? 'bg-dark-5 ' : ''}\">\n <!-- start: widget title -->\n ${this.type === 'relatedArticle'\n ? this.titleRelatedArticle()\n : this.titleOtherArticle()}\n <!-- end: widget title -->\n <intersection-observer-component\n .onTrigger=\"${() => this.handleObserver()}\"\n ></intersection-observer-component>\n <div class=\"grid grid-cols-1 md:grid-cols-2 gap-6 md:gap-8\">\n <!-- start: left-post-loop -->\n <div class=\"grid grid-cols-1 gap-6\">\n ${this.posts[0]\n ? this.posts[0].map(\n (post, index) => html`\n <div class=\"w-full\">\n <div class=\"flex\">\n <div class=\"w-1/2\">${this.renderImage(post)}</div>\n <div class=\"flex-grow pl-4 w-1/2\">\n <a\n href=\"${post.permalink}?open_from=${this.type ===\n 'relatedArticle'\n ? 'Artikel_Terkait'\n : 'Artikel_Lainnya'}\"\n @click=\"${() =>\n this.recoContentClicked(post, index + 1)}\"\n >\n ${this.renderChips(post)}\n <h5\n class=\"hover:underline font-bold font-sans leading-tight text-lg md:text-xl ${this\n .isDark\n ? 'text-white'\n : 'text-grey-600'}\"\n >\n ${post.title}\n </h5>\n <p\n class=\"font-sans pt-2 text-sm ${this.isDark\n ? 'text-white'\n : 'text-grey-600'}\"\n >\n ${useTimeDifference(post.publishedDate)}\n </p>\n </a>\n </div>\n </div>\n </div>\n `\n )\n : 'Belum ada artikel'}\n </div>\n <!-- end: left-post-loop -->\n\n <!-- start: right-post-loop -->\n <div class=\"flex flex-col w-full\">\n ${this.posts[1]\n ? this.posts[1].map(\n (post, index) => html`\n <div class=\"mb-6\">\n <div class=\"flex\">\n <div class=\"w-1/2\">${this.renderImage(post)}</div>\n <div class=\"flex-grow pl-4 w-1/2\">\n <a\n href=\"${post.permalink}?open_from=${this.type ===\n 'relatedArticle'\n ? 'Artikel_Terkait'\n : 'Artikel_Lainnya'}\"\n @click=\"${() =>\n this.recoContentClicked(post, index + 6)}\"\n >\n ${this.renderChips(post)}\n <h5\n class=\"hover:underline font-bold font-sans leading-tight text-lg md:text-xl ${this\n .isDark\n ? 'text-white'\n : 'text-grey-600'}\"\n >\n ${post.title}\n </h5>\n <p\n class=\"font-sans pt-2 text-sm ${this.isDark\n ? 'text-white'\n : 'text-grey-600'}\"\n >\n ${useTimeDifference(post.publishedDate)}\n </p>\n </a>\n </div>\n </div>\n </div>\n `\n )\n : ''}\n <!-- start: ads -->\n <slot></slot>\n <!-- end: ads -->\n </div>\n <!-- end: right-post-loop -->\n </div>\n </div>\n `\n }\n}\n"]}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
interface Category {
|
|
2
|
+
id: number;
|
|
3
|
+
name: string;
|
|
4
|
+
slug: string;
|
|
5
|
+
}
|
|
1
6
|
interface PostTag {
|
|
2
7
|
slug: string;
|
|
3
8
|
}
|
|
4
9
|
export interface Post {
|
|
10
|
+
id: number;
|
|
5
11
|
title: string;
|
|
12
|
+
name: string;
|
|
13
|
+
category: Category[];
|
|
6
14
|
isAnalisis?: boolean;
|
|
7
15
|
isEksklusif?: boolean;
|
|
8
16
|
isFreemium?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/components/kompasid-widget-recirculations-default/types.ts"],"names":[],"mappings":"","sourcesContent":["interface PostTag {\n slug: string\n}\n\nexport interface Post {\n title: string\n isAnalisis?: boolean\n isEksklusif?: boolean\n isFreemium?: boolean\n featuredImageThumbnailMedium: string\n permalink: string\n publishedDate: string\n postTag?: PostTag[]\n thumbnails: {\n sizes: {\n thumbnailMedium: {\n permalink: string\n width: number\n height: number\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/components/kompasid-widget-recirculations-default/types.ts"],"names":[],"mappings":"","sourcesContent":["interface Category {\n id: number\n name: string\n slug: string\n}\n\ninterface PostTag {\n slug: string\n}\n\nexport interface Post {\n id: number\n title: string\n name: string\n category: Category[]\n isAnalisis?: boolean\n isEksklusif?: boolean\n isFreemium?: boolean\n featuredImageThumbnailMedium: string\n permalink: string\n publishedDate: string\n postTag?: PostTag[]\n thumbnails: {\n sizes: {\n thumbnailMedium: {\n permalink: string\n width: number\n height: number\n }\n }\n }\n}\n"]}
|
package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare class KompasWidgetRecirculationsList extends LitElement {
|
|
|
22
22
|
fetchArticles(): Promise<void>;
|
|
23
23
|
handleFetchError(error: unknown): void;
|
|
24
24
|
renderChips(item: ListItem): import("lit").TemplateResult<1>[];
|
|
25
|
+
getSectionName(): "Section_Terbaru" | "Section_Terpopuler";
|
|
25
26
|
render(): import("lit").TemplateResult<1>;
|
|
26
27
|
}
|
|
27
28
|
export {};
|
package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.js
CHANGED
|
@@ -92,6 +92,13 @@ let KompasWidgetRecirculationsList = class KompasWidgetRecirculationsList extend
|
|
|
92
92
|
}
|
|
93
93
|
return chips;
|
|
94
94
|
}
|
|
95
|
+
getSectionName() {
|
|
96
|
+
const sectionMapping = {
|
|
97
|
+
Terbaru: 'Section_Terbaru',
|
|
98
|
+
Terpopuler: 'Section_Terpopuler',
|
|
99
|
+
};
|
|
100
|
+
return sectionMapping[this.widgetTitle] || '';
|
|
101
|
+
}
|
|
95
102
|
render() {
|
|
96
103
|
return html `
|
|
97
104
|
<div class="${this.isDark ? 'bg-dark-5 ' : ''}">
|
|
@@ -113,7 +120,7 @@ let KompasWidgetRecirculationsList = class KompasWidgetRecirculationsList extend
|
|
|
113
120
|
<div class="flex flex-col w-full">
|
|
114
121
|
${this.renderChips(item)}
|
|
115
122
|
<a
|
|
116
|
-
href="${item.permalink}"
|
|
123
|
+
href="${item.permalink}?open_from=${this.getSectionName()}"
|
|
117
124
|
class="font-bold font-lora hover:underline leading-normal text-xl ${this
|
|
118
125
|
.isDark
|
|
119
126
|
? 'text-white'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KompasWidgetRecirculationsList.js","sourceRoot":"","sources":["../../../../src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AAkB7D,IAAM,8BAA8B,GAApC,MAAM,8BAA+B,SAAQ,UAAU;IAAvD;;QACuB,gBAAW,GAAG,EAAE,CAAA;QACjB,gBAAW,GAAe,EAAE,CAAA;QAC3B,YAAO,GAAG,EAAE,CAAA;QAEX,WAAM,GAAG,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"KompasWidgetRecirculationsList.js","sourceRoot":"","sources":["../../../../src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AAkB7D,IAAM,8BAA8B,GAApC,MAAM,8BAA+B,SAAQ,UAAU;IAAvD;;QACuB,gBAAW,GAAG,EAAE,CAAA;QACjB,gBAAW,GAAe,EAAE,CAAA;QAC3B,YAAO,GAAG,EAAE,CAAA;QAEX,WAAM,GAAG,KAAK,CAAA;IAuM7C,CAAC;IA/KC,KAAK,CAAC,iBAAiB;QACrB,KAAK,CAAC,iBAA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CAAC,GAAG,CAChC,IAAI,CAAC,EAAE,CACL,IAAI,CAAA;;;;wBAIM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;;gCAEd,IAAI,CAAC,SAAS,cAAc,IAAI,CAAC,cAAc,EAAE;4FACW,IAAI;aACrE,MAAM;YACP,CAAC,CAAC,YAAY;YACd,CAAC,CAAC,eAAe;;0BAEjB,IAAI,CAAC,KAAK;;;yHAGqF,IAAI;aAClG,MAAM;YACP,CAAC,CAAC,YAAY;YACd,CAAC,CAAC,eAAe;;0BAEjB,IAAI,CAAC,aAAa;YAClB,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC;YAC7C,CAAC,CAAC,wBAAwB;;;;;eAKrC,CACJ;;;KAGN,CAAA;IACH,CAAC;;AApMM,qCAAM,GAAG;IACd,GAAG,CAAA;;;;;;;;;;;;;;;;;KAiBF;IACD,QAAQ;CACT,CAAA;AA1B2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;mEAAiB;AACjB;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;mEAA6B;AAC3B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+DAAa;AAEX;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;8DAAe;AALhC,8BAA8B;IAD1C,aAAa,CAAC,qCAAqC,CAAC;GACxC,8BAA8B,CA4M1C;SA5MY,8BAA8B","sourcesContent":["import { html, css, LitElement } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport { TWStyles } from '../../../tailwind/tailwind.js'\nimport { useTimeDifference } from '../../utils/useTimeDIfference.js'\n\ninterface PostTag {\n slug: string\n}\n\ninterface ListItem {\n title: string\n isAnalisis?: boolean\n isEksklusif?: boolean\n isFreemium?: boolean\n isKompasBrief?: boolean\n permalink: string\n publishedDate?: string\n postTag?: PostTag[]\n}\n\n@customElement('kompasid-widget-recirculations-list')\nexport class KompasWidgetRecirculationsList extends LitElement {\n @property({ type: String }) widgetTitle = ''\n @property({ type: Array }) articleList: ListItem[] = []\n @property({ type: String }) apiSlug = ''\n\n @property({ type: Boolean }) isDark = false\n\n static styles = [\n css`\n :host {\n font-family: 'PT Sans', sans-serif;\n }\n .chip {\n align-items: center;\n border-radius: 0.25rem;\n display: flex;\n font-family: 'PT Sans', sans-serif;\n font-size: 0.75rem;\n font-weight: bold;\n height: 1.5rem;\n justify-content: center;\n line-height: 1rem;\n margin-bottom: 0.25rem;\n padding: 0.375rem 0.5rem;\n }\n `,\n TWStyles,\n ]\n\n async connectedCallback() {\n super.connectedCallback()\n try {\n await this.fetchArticles()\n } catch (error) {\n this.handleFetchError(error)\n }\n }\n\n async fetchArticles() {\n const endpoint = `https://cds.kompas.id/api/v2/article/${this.apiSlug}`\n\n const response = await fetch(endpoint, {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n\n const result = await response.json()\n\n if (result?.result) {\n this.articleList = result.result.map(\n (article: {\n postTag?: never[] | undefined\n isFreemium?: false | undefined\n title: any\n permalink: any\n publishedDate: any\n }) => {\n const {\n postTag = [],\n isFreemium = false,\n title,\n permalink,\n publishedDate,\n } = article\n\n const isAnalisis = postTag.some(\n (tag: { slug: string }) => tag.slug === 'analisis'\n )\n const isEksklusif = postTag.some(\n (tag: { slug: string }) => tag.slug === 'eksklusif'\n )\n const isKompasBrief = postTag.some(\n (tag: { slug: string }) => tag.slug === 'kompas-brief'\n )\n\n return {\n isAnalisis,\n isEksklusif,\n isFreemium,\n isKompasBrief,\n title,\n permalink,\n publishedDate,\n }\n }\n )\n } else {\n throw new Error('Data artikel populer tidak ditemukan')\n }\n }\n\n handleFetchError(error: unknown) {\n const errorMessage =\n error instanceof Error ? error.message : 'Kesalahan tidak diketahui'\n alert(`Terjadi kesalahan: ${errorMessage}`)\n }\n\n renderChips(item: ListItem) {\n const chips = []\n\n if (item.isKompasBrief) {\n chips.push(\n html`\n <div class=\"flex\">\n <div class=\"chip bg-red-100 text-red-600\">Kompas Brief</div>\n </div>\n `\n )\n } else if (item.isEksklusif) {\n chips.push(\n html`\n <div class=\"flex\">\n <div class=\"chip bg-grey-600 text-white\">\n <img\n src=\"https://cdn-www.kompas.id/assets/img/icons/kompas-icon-small.svg\"\n alt=\"Kompas Icon\"\n style=\"width: 16px; height: 16px; margin-right: 4px;\"\n />\n Eksklusif\n </div>\n </div>\n `\n )\n } else if (item.isFreemium) {\n chips.push(\n html`\n <div class=\"flex\">\n <div class=\"chip bg-blue-100 text-brand-1\">Bebas Akses</div>\n </div>\n `\n )\n } else if (item.isAnalisis) {\n chips.push(\n html`\n <div class=\"flex\">\n <div class=\"chip bg-orange-100 text-orange-500\">Analisis</div>\n </div>\n `\n )\n }\n\n return chips\n }\n\n getSectionName() {\n const sectionMapping = {\n Terbaru: 'Section_Terbaru',\n Terpopuler: 'Section_Terpopuler',\n } as const\n\n return sectionMapping[this.widgetTitle as keyof typeof sectionMapping] || ''\n }\n\n render() {\n return html`\n <div class=\"${this.isDark ? 'bg-dark-5 ' : ''}\">\n <div class=\"mb-6\">\n <h5\n class=\"capitalize font-bold font-sans text-lg md:text-xl ${this\n .isDark\n ? 'text-white'\n : 'text-grey-600'}\"\n >\n ${this.widgetTitle}\n </h5>\n </div>\n\n <ul class=\"flex flex-col\">\n ${this.articleList.slice(0, 5).map(\n item =>\n html`\n <li class=\"flex flex-col items-start mb-3\">\n <div class=\"flex w-full\">\n <div class=\"flex flex-col w-full\">\n ${this.renderChips(item)}\n <a\n href=\"${item.permalink}?open_from=${this.getSectionName()}\"\n class=\"font-bold font-lora hover:underline leading-normal text-xl ${this\n .isDark\n ? 'text-white'\n : 'text-grey-600'}\"\n >\n ${item.title}\n </a>\n <div\n class=\"flex w-full flex-row font-sans items-center leading-normal justify-between pt-2 text-sm ${this\n .isDark\n ? 'text-white'\n : 'text-grey-500'}\"\n >\n ${item.publishedDate\n ? useTimeDifference(item.publishedDate, true)\n : 'Tanggal tidak tersedia'}\n </div>\n </div>\n </div>\n </li>\n `\n )}\n </ul>\n </div>\n `\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
export declare class IntersectionObserverComponent extends LitElement {
|
|
3
|
+
rootMargin: string;
|
|
4
|
+
threshold: number;
|
|
5
|
+
multipleTrigger: boolean;
|
|
6
|
+
forceTrigger: boolean;
|
|
7
|
+
timer: number;
|
|
8
|
+
onTrigger?: () => void;
|
|
9
|
+
elementTarget: HTMLElement;
|
|
10
|
+
private intersectionObserver;
|
|
11
|
+
private timerId;
|
|
12
|
+
connectedCallback(): void;
|
|
13
|
+
firstUpdated(): void;
|
|
14
|
+
disconnectedCallback(): void;
|
|
15
|
+
private handleIntersection;
|
|
16
|
+
private handleEntryInView;
|
|
17
|
+
private clearTimer;
|
|
18
|
+
private emitTrigger;
|
|
19
|
+
render(): import("lit").TemplateResult<1>;
|
|
20
|
+
}
|
|
21
|
+
export declare const createIntersectionObserverComponent: () => typeof IntersectionObserverComponent;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { html, LitElement } from 'lit';
|
|
3
|
+
import { property, query } from 'lit/decorators.js';
|
|
4
|
+
export class IntersectionObserverComponent extends LitElement {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.rootMargin = '0px 0px 0px 0px';
|
|
8
|
+
this.threshold = 1;
|
|
9
|
+
this.multipleTrigger = false;
|
|
10
|
+
this.forceTrigger = false;
|
|
11
|
+
this.timer = 0;
|
|
12
|
+
this.intersectionObserver = null;
|
|
13
|
+
this.timerId = null;
|
|
14
|
+
}
|
|
15
|
+
connectedCallback() {
|
|
16
|
+
super.connectedCallback();
|
|
17
|
+
this.intersectionObserver = new IntersectionObserver(this.handleIntersection.bind(this), {
|
|
18
|
+
threshold: this.threshold,
|
|
19
|
+
rootMargin: this.rootMargin,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
firstUpdated() {
|
|
23
|
+
var _a;
|
|
24
|
+
if (this.elementTarget) {
|
|
25
|
+
(_a = this.intersectionObserver) === null || _a === void 0 ? void 0 : _a.observe(this.elementTarget);
|
|
26
|
+
}
|
|
27
|
+
if (this.forceTrigger) {
|
|
28
|
+
this.emitTrigger();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
disconnectedCallback() {
|
|
32
|
+
var _a;
|
|
33
|
+
super.disconnectedCallback();
|
|
34
|
+
(_a = this.intersectionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
35
|
+
this.clearTimer();
|
|
36
|
+
}
|
|
37
|
+
handleIntersection(entries) {
|
|
38
|
+
entries.forEach(entry => {
|
|
39
|
+
if (entry.isIntersecting) {
|
|
40
|
+
this.handleEntryInView();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.clearTimer();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
handleEntryInView() {
|
|
48
|
+
var _a;
|
|
49
|
+
if (this.timer > 0) {
|
|
50
|
+
this.clearTimer();
|
|
51
|
+
this.timerId = window.setTimeout(() => {
|
|
52
|
+
var _a;
|
|
53
|
+
this.emitTrigger();
|
|
54
|
+
if (!this.multipleTrigger) {
|
|
55
|
+
(_a = this.intersectionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
56
|
+
}
|
|
57
|
+
}, this.timer);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.emitTrigger();
|
|
61
|
+
if (!this.multipleTrigger) {
|
|
62
|
+
(_a = this.intersectionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
clearTimer() {
|
|
67
|
+
if (this.timerId !== null) {
|
|
68
|
+
clearTimeout(this.timerId);
|
|
69
|
+
this.timerId = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
emitTrigger() {
|
|
73
|
+
this.dispatchEvent(new CustomEvent('trigger'));
|
|
74
|
+
if (this.onTrigger) {
|
|
75
|
+
this.onTrigger();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
render() {
|
|
79
|
+
return html `<div id="elementTarget"><slot></slot></div>`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
__decorate([
|
|
83
|
+
property({ type: String })
|
|
84
|
+
], IntersectionObserverComponent.prototype, "rootMargin", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
property({ type: Number })
|
|
87
|
+
], IntersectionObserverComponent.prototype, "threshold", void 0);
|
|
88
|
+
__decorate([
|
|
89
|
+
property({ type: Boolean })
|
|
90
|
+
], IntersectionObserverComponent.prototype, "multipleTrigger", void 0);
|
|
91
|
+
__decorate([
|
|
92
|
+
property({ type: Boolean })
|
|
93
|
+
], IntersectionObserverComponent.prototype, "forceTrigger", void 0);
|
|
94
|
+
__decorate([
|
|
95
|
+
property({ type: Number })
|
|
96
|
+
], IntersectionObserverComponent.prototype, "timer", void 0);
|
|
97
|
+
__decorate([
|
|
98
|
+
property({ attribute: false })
|
|
99
|
+
], IntersectionObserverComponent.prototype, "onTrigger", void 0);
|
|
100
|
+
__decorate([
|
|
101
|
+
query('#elementTarget')
|
|
102
|
+
], IntersectionObserverComponent.prototype, "elementTarget", void 0);
|
|
103
|
+
export const createIntersectionObserverComponent = () => {
|
|
104
|
+
if (!customElements.get('intersection-observer-component')) {
|
|
105
|
+
customElements.define('intersection-observer-component', IntersectionObserverComponent);
|
|
106
|
+
}
|
|
107
|
+
return IntersectionObserverComponent;
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=IntersectionObserver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntersectionObserver.js","sourceRoot":"","sources":["../../../src/utils/IntersectionObserver.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAA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,EAAE,OAAO,EAAE,CAAC;mEAA8B;AAC9B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4DAAkB;AACb;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;gEAAuB;AAE7B;IAAxB,KAAK,CAAC,gBAAgB,CAAC;oEAA4B;AA6EtD,MAAM,CAAC,MAAM,mCAAmC,GAAG,GAAG,EAAE;IACtD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,iCAAiC,CAAC,EAAE;QAC1D,cAAc,CAAC,MAAM,CACnB,iCAAiC,EACjC,6BAA6B,CAC9B,CAAA;KACF;IACD,OAAO,6BAA6B,CAAA;AACtC,CAAC,CAAA","sourcesContent":["import { html, LitElement } from 'lit'\nimport { property, query } from 'lit/decorators.js'\n\nexport class IntersectionObserverComponent extends LitElement {\n @property({ type: String }) rootMargin: string = '0px 0px 0px 0px'\n @property({ type: Number }) threshold: number = 1\n @property({ type: Boolean }) multipleTrigger: boolean = false\n @property({ type: Boolean }) forceTrigger: boolean = false\n @property({ type: Number }) timer: number = 0\n @property({ attribute: false }) onTrigger?: () => void\n\n @query('#elementTarget') elementTarget!: HTMLElement\n\n private intersectionObserver: IntersectionObserver | null = null\n private timerId: number | null = null\n\n connectedCallback(): void {\n super.connectedCallback()\n this.intersectionObserver = new IntersectionObserver(\n this.handleIntersection.bind(this),\n {\n threshold: this.threshold,\n rootMargin: this.rootMargin,\n }\n )\n }\n\n firstUpdated(): void {\n if (this.elementTarget) {\n this.intersectionObserver?.observe(this.elementTarget)\n }\n if (this.forceTrigger) {\n this.emitTrigger()\n }\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback()\n this.intersectionObserver?.disconnect()\n this.clearTimer()\n }\n\n private handleIntersection(entries: IntersectionObserverEntry[]): void {\n entries.forEach(entry => {\n if (entry.isIntersecting) {\n this.handleEntryInView()\n } else {\n this.clearTimer()\n }\n })\n }\n\n private handleEntryInView(): void {\n if (this.timer > 0) {\n this.clearTimer()\n this.timerId = window.setTimeout(() => {\n this.emitTrigger()\n if (!this.multipleTrigger) {\n this.intersectionObserver?.disconnect()\n }\n }, this.timer)\n } else {\n this.emitTrigger()\n if (!this.multipleTrigger) {\n this.intersectionObserver?.disconnect()\n }\n }\n }\n\n private clearTimer(): void {\n if (this.timerId !== null) {\n clearTimeout(this.timerId)\n this.timerId = null\n }\n }\n\n private emitTrigger(): void {\n this.dispatchEvent(new CustomEvent('trigger'))\n if (this.onTrigger) {\n this.onTrigger()\n }\n }\n\n render() {\n return html`<div id=\"elementTarget\"><slot></slot></div>`\n }\n}\n\nexport const createIntersectionObserverComponent = () => {\n if (!customElements.get('intersection-observer-component')) {\n customElements.define(\n 'intersection-observer-component',\n IntersectionObserverComponent\n )\n }\n return IntersectionObserverComponent\n}\n"]}
|