@kompasid/lit-web-components 0.6.7 → 0.7.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.
- package/demo/index.html +35 -1
- package/dist/src/components/kompasid-paywall-body/KompasPaywallBody.js +39 -11
- package/dist/src/components/kompasid-paywall-body/KompasPaywallBody.js.map +1 -1
- package/dist/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.d.ts +39 -0
- package/dist/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.js +340 -0
- package/dist/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.js.map +1 -0
- package/dist/src/components/kompasid-widget-recirculations-default/types.d.ts +27 -0
- package/dist/src/components/kompasid-widget-recirculations-default/types.js +2 -0
- package/dist/src/components/kompasid-widget-recirculations-default/types.js.map +1 -0
- package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.d.ts +28 -0
- package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.js +188 -0
- package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/tailwind/tailwind.js +88 -170
- package/dist/tailwind/tailwind.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/src/components/kompasid-paywall-body/KompasPaywallBody.ts +39 -11
- package/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.ts +342 -0
- package/src/components/kompasid-widget-recirculations-default/readme.md +57 -0
- package/src/components/kompasid-widget-recirculations-default/types.ts +28 -0
- package/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.ts +230 -0
- package/src/components/kompasid-widget-recirculations-list/readme.md +27 -0
- package/src/index.ts +2 -0
- package/tailwind/tailwind.css +85 -170
- package/tailwind/tailwind.ts +88 -170
- package/tailwind.config.js +2 -1
- package/assets/kompas-free-trial.png +0 -0
- package/assets/qr-code.png +0 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { html, css, LitElement } from 'lit';
|
|
3
|
+
import { customElement, property } from 'lit/decorators.js';
|
|
4
|
+
import { format } from 'date-fns';
|
|
5
|
+
import { id } from 'date-fns/locale/id';
|
|
6
|
+
import { TWStyles } from '../../../tailwind/tailwind.js';
|
|
7
|
+
let KompasWidgetRecirculationsDefault = class KompasWidgetRecirculationsDefault extends LitElement {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
/**
|
|
11
|
+
* Props
|
|
12
|
+
*/
|
|
13
|
+
this.posts = [];
|
|
14
|
+
this.navigation = undefined;
|
|
15
|
+
this.accessToken = '';
|
|
16
|
+
this.permalinkArticle = '';
|
|
17
|
+
this.userGuid = '0';
|
|
18
|
+
this.slugs = '';
|
|
19
|
+
this.type = 'relatedArticle';
|
|
20
|
+
this.mainCategory = '';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Getters
|
|
24
|
+
*/
|
|
25
|
+
get navigationPermalink() {
|
|
26
|
+
var _a;
|
|
27
|
+
return (_a = this.navigation) === null || _a === void 0 ? void 0 : _a.permalink;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Fetch Data
|
|
31
|
+
*/
|
|
32
|
+
async connectedCallback() {
|
|
33
|
+
super.connectedCallback();
|
|
34
|
+
try {
|
|
35
|
+
await this.fetchAccessToken();
|
|
36
|
+
if (this.type === 'relatedArticle') {
|
|
37
|
+
await this.relatedArticles();
|
|
38
|
+
}
|
|
39
|
+
else if (this.type === 'otherArticle') {
|
|
40
|
+
await this.otherArticles();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
this.handleFetchError(error);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async fetchAccessToken() {
|
|
48
|
+
var _a;
|
|
49
|
+
const response = await fetch('https://api.kompas.id/account/api/v1/login/guest', {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: {
|
|
52
|
+
'Content-Type': 'application/json',
|
|
53
|
+
},
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
email: 'anonynous.user@kompas.id',
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
const result = await response.json();
|
|
59
|
+
if ((_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.accessToken) {
|
|
60
|
+
this.accessToken = result.data.accessToken;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw new Error('Token akses tidak tersedia dalam respons');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async relatedArticles() {
|
|
67
|
+
if (!this.accessToken) {
|
|
68
|
+
throw new Error('Token akses tidak tersedia');
|
|
69
|
+
}
|
|
70
|
+
const kompasApiAi = 'https://ai.kompas.id/api/v1';
|
|
71
|
+
// Constructing parameters
|
|
72
|
+
const params = new URLSearchParams();
|
|
73
|
+
params.append('page_url', this.permalinkArticle);
|
|
74
|
+
params.append('page_type', 'read');
|
|
75
|
+
params.append('item_type', 'articles');
|
|
76
|
+
params.append('guid', this.userGuid);
|
|
77
|
+
params.append('slugs', this.slugs);
|
|
78
|
+
// Constructing the URL with parameters
|
|
79
|
+
const endpoint = `${kompasApiAi}/recommendation?${params.toString()}`;
|
|
80
|
+
const response = await fetch(endpoint, {
|
|
81
|
+
headers: {
|
|
82
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
83
|
+
'Content-Type': 'application/json',
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
const result = await response.json();
|
|
87
|
+
if (result === null || result === void 0 ? void 0 : result.result) {
|
|
88
|
+
const items = result.result;
|
|
89
|
+
const firstChunk = items.slice(0, 5);
|
|
90
|
+
const secondChunk = items.slice(5, 7);
|
|
91
|
+
this.posts = [Object.freeze(firstChunk), Object.freeze(secondChunk)];
|
|
92
|
+
console.log('related article:', this.posts);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw new Error('Data artikel terkait tidak ditemukan');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async otherArticles() {
|
|
99
|
+
if (!this.accessToken) {
|
|
100
|
+
throw new Error('Token akses tidak tersedia');
|
|
101
|
+
}
|
|
102
|
+
const kompasApiCdsSPA = 'https://cds.kompas.id/api/v1';
|
|
103
|
+
// Constructing the URL with parameters
|
|
104
|
+
const endpoint = `${kompasApiCdsSPA}/article/list/category/${this.mainCategory}`;
|
|
105
|
+
const response = await fetch(endpoint, {
|
|
106
|
+
headers: {
|
|
107
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
108
|
+
'Content-Type': 'application/json',
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
const result = await response.json();
|
|
112
|
+
if (result === null || result === void 0 ? void 0 : result.result) {
|
|
113
|
+
const items = result.result;
|
|
114
|
+
const firstChunk = items.slice(0, 5);
|
|
115
|
+
const secondChunk = items.slice(5, 7);
|
|
116
|
+
this.posts = [Object.freeze(firstChunk), Object.freeze(secondChunk)];
|
|
117
|
+
console.log('other article:', this.posts);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
throw new Error('Data artikel lainnya tidak ditemukan');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
handleFetchError(error) {
|
|
124
|
+
const errorMessage = error instanceof Error ? error.message : 'Kesalahan tidak diketahui';
|
|
125
|
+
alert(`Terjadi kesalahan: ${errorMessage}`);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Function to format date
|
|
129
|
+
*/
|
|
130
|
+
formatDate(date) {
|
|
131
|
+
return format(new Date(date), 'dd MMMM yyyy', { locale: id });
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Render widget components
|
|
135
|
+
*/
|
|
136
|
+
WidgetTitle() {
|
|
137
|
+
var _a, _b;
|
|
138
|
+
if (this.navigationPermalink) {
|
|
139
|
+
return html `
|
|
140
|
+
<a
|
|
141
|
+
href="${this.navigationPermalink}"
|
|
142
|
+
class="flex font-sans uppercase items-start mb-6 mt-8"
|
|
143
|
+
>
|
|
144
|
+
<h5
|
|
145
|
+
class="${[
|
|
146
|
+
'capitalize font-bold font-sans',
|
|
147
|
+
this.navigationPermalink ? 'text-brand-1' : 'text-grey-600',
|
|
148
|
+
].join(' ')}"
|
|
149
|
+
>
|
|
150
|
+
${(_a = this.navigation) === null || _a === void 0 ? void 0 : _a.name}
|
|
151
|
+
</h5>
|
|
152
|
+
</a>
|
|
153
|
+
`;
|
|
154
|
+
}
|
|
155
|
+
return html `
|
|
156
|
+
<div class="flex font-sans uppercase items-start mb-6 mt-8">
|
|
157
|
+
<div>
|
|
158
|
+
<h5
|
|
159
|
+
class="${[
|
|
160
|
+
'capitalize font-bold font-sans',
|
|
161
|
+
this.navigationPermalink ? 'text-brand-1' : 'text-grey-600',
|
|
162
|
+
].join(' ')}"
|
|
163
|
+
>
|
|
164
|
+
${(_b = this.navigation) === null || _b === void 0 ? void 0 : _b.name}
|
|
165
|
+
</h5>
|
|
166
|
+
</div>
|
|
167
|
+
</div>
|
|
168
|
+
`;
|
|
169
|
+
}
|
|
170
|
+
renderChips(post) {
|
|
171
|
+
var _a, _b;
|
|
172
|
+
const chips = [];
|
|
173
|
+
const isAnalisis = (_a = post.postTag) === null || _a === void 0 ? void 0 : _a.some(tag => tag.slug === 'analisis');
|
|
174
|
+
const isEksklusif = (_b = post.postTag) === null || _b === void 0 ? void 0 : _b.some(tag => tag.slug === 'eksklusif');
|
|
175
|
+
const isFreemium = post.isFreemium === true;
|
|
176
|
+
if (isEksklusif) {
|
|
177
|
+
chips.push(html `
|
|
178
|
+
<div class="flex">
|
|
179
|
+
<div class="chip bg-grey-600 text-white">
|
|
180
|
+
<img
|
|
181
|
+
src="https://cdn-www.kompas.id/assets/img/icons/kompas-icon-small.svg"
|
|
182
|
+
alt="Kompas Icon"
|
|
183
|
+
style="width: 16px; height: 16px; margin-right: 4px;"
|
|
184
|
+
/>
|
|
185
|
+
Eksklusif
|
|
186
|
+
</div>
|
|
187
|
+
</div>
|
|
188
|
+
`);
|
|
189
|
+
}
|
|
190
|
+
else if (isFreemium) {
|
|
191
|
+
chips.push(html `
|
|
192
|
+
<div class="flex">
|
|
193
|
+
<div class="chip bg-blue-100 text-brand-1">Bebas Akses</div>
|
|
194
|
+
</div>
|
|
195
|
+
`);
|
|
196
|
+
}
|
|
197
|
+
else if (isAnalisis) {
|
|
198
|
+
chips.push(html `
|
|
199
|
+
<div class="flex">
|
|
200
|
+
<div class="chip bg-orange-100 text-orange-500">Analisis</div>
|
|
201
|
+
</div>
|
|
202
|
+
`);
|
|
203
|
+
}
|
|
204
|
+
return chips;
|
|
205
|
+
}
|
|
206
|
+
renderImage(post) {
|
|
207
|
+
var _a;
|
|
208
|
+
const { thumbnailMedium } = ((_a = post.thumbnails) === null || _a === void 0 ? void 0 : _a.sizes) || {};
|
|
209
|
+
if (!thumbnailMedium)
|
|
210
|
+
return '';
|
|
211
|
+
const { permalink, width, height } = thumbnailMedium;
|
|
212
|
+
return html `
|
|
213
|
+
<img
|
|
214
|
+
src="${permalink}"
|
|
215
|
+
width="${width}"
|
|
216
|
+
height="${height}"
|
|
217
|
+
alt="${post.title}"
|
|
218
|
+
class="aspect-video object-cover w-full"
|
|
219
|
+
/>
|
|
220
|
+
`;
|
|
221
|
+
}
|
|
222
|
+
render() {
|
|
223
|
+
return html `
|
|
224
|
+
<div class="w-full">
|
|
225
|
+
<!-- start: widget title -->
|
|
226
|
+
${this.WidgetTitle()}
|
|
227
|
+
<!-- end: widget title -->
|
|
228
|
+
|
|
229
|
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 md:gap-8">
|
|
230
|
+
<!-- start: left-post-loop -->
|
|
231
|
+
<div class="grid grid-cols-1 gap-6">
|
|
232
|
+
${this.posts[0]
|
|
233
|
+
? this.posts[0].map(post => html `
|
|
234
|
+
<div class="w-full">
|
|
235
|
+
<div class="flex">
|
|
236
|
+
<div class="w-1/2">${this.renderImage(post)}</div>
|
|
237
|
+
<div class="flex-grow pl-4 w-1/2">
|
|
238
|
+
<a href="${post.permalink}">
|
|
239
|
+
${this.renderChips(post)}
|
|
240
|
+
<h5
|
|
241
|
+
class="hover:underline font-bold font-sans leading-tight text-grey-600"
|
|
242
|
+
>
|
|
243
|
+
${post.title}
|
|
244
|
+
</h5>
|
|
245
|
+
<p class="text-grey-600 pt-2">
|
|
246
|
+
${this.formatDate(post.publishedDate)}
|
|
247
|
+
</p>
|
|
248
|
+
</a>
|
|
249
|
+
</div>
|
|
250
|
+
</div>
|
|
251
|
+
</div>
|
|
252
|
+
`)
|
|
253
|
+
: 'Belum ada artikel'}
|
|
254
|
+
</div>
|
|
255
|
+
<!-- end: left-post-loop -->
|
|
256
|
+
|
|
257
|
+
<!-- start: right-post-loop -->
|
|
258
|
+
<div class="flex flex-col w-full">
|
|
259
|
+
${this.posts[1]
|
|
260
|
+
? this.posts[1].map(post => html `
|
|
261
|
+
<div class="mb-6">
|
|
262
|
+
<div class="flex">
|
|
263
|
+
<div class="w-1/2">${this.renderImage(post)}</div>
|
|
264
|
+
<div class="flex-grow pl-4 w-1/2">
|
|
265
|
+
<a href="${post.permalink}">
|
|
266
|
+
${this.renderChips(post)}
|
|
267
|
+
<h5
|
|
268
|
+
class="hover:underline font-bold font-sans leading-tight text-grey-600"
|
|
269
|
+
>
|
|
270
|
+
${post.title}
|
|
271
|
+
</h5>
|
|
272
|
+
<p class="text-grey-600 pt-2">
|
|
273
|
+
${this.formatDate(post.publishedDate)}
|
|
274
|
+
</p>
|
|
275
|
+
</a>
|
|
276
|
+
</div>
|
|
277
|
+
</div>
|
|
278
|
+
</div>
|
|
279
|
+
`)
|
|
280
|
+
: ''}
|
|
281
|
+
<!-- start: ads -->
|
|
282
|
+
<slot></slot>
|
|
283
|
+
<!-- end: ads -->
|
|
284
|
+
</div>
|
|
285
|
+
<!-- end: right-post-loop -->
|
|
286
|
+
</div>
|
|
287
|
+
</div>
|
|
288
|
+
`;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
KompasWidgetRecirculationsDefault.styles = [
|
|
292
|
+
css `
|
|
293
|
+
:host {
|
|
294
|
+
font-family: 'PT Sans', sans-serif;
|
|
295
|
+
}
|
|
296
|
+
.chip {
|
|
297
|
+
align-items: center;
|
|
298
|
+
border-radius: 0.25rem;
|
|
299
|
+
display: flex;
|
|
300
|
+
font-family: 'PT Sans', sans-serif;
|
|
301
|
+
font-size: 0.75rem;
|
|
302
|
+
font-weight: bold;
|
|
303
|
+
height: 1.5rem;
|
|
304
|
+
justify-content: center;
|
|
305
|
+
line-height: 1rem;
|
|
306
|
+
margin-bottom: 0.25rem;
|
|
307
|
+
padding: 0.375rem 0.5rem;
|
|
308
|
+
}
|
|
309
|
+
`,
|
|
310
|
+
TWStyles,
|
|
311
|
+
];
|
|
312
|
+
__decorate([
|
|
313
|
+
property({ type: Array })
|
|
314
|
+
], KompasWidgetRecirculationsDefault.prototype, "posts", void 0);
|
|
315
|
+
__decorate([
|
|
316
|
+
property({ type: Object })
|
|
317
|
+
], KompasWidgetRecirculationsDefault.prototype, "navigation", void 0);
|
|
318
|
+
__decorate([
|
|
319
|
+
property({ type: String })
|
|
320
|
+
], KompasWidgetRecirculationsDefault.prototype, "accessToken", void 0);
|
|
321
|
+
__decorate([
|
|
322
|
+
property({ type: String })
|
|
323
|
+
], KompasWidgetRecirculationsDefault.prototype, "permalinkArticle", void 0);
|
|
324
|
+
__decorate([
|
|
325
|
+
property({ type: String })
|
|
326
|
+
], KompasWidgetRecirculationsDefault.prototype, "userGuid", void 0);
|
|
327
|
+
__decorate([
|
|
328
|
+
property({ type: String })
|
|
329
|
+
], KompasWidgetRecirculationsDefault.prototype, "slugs", void 0);
|
|
330
|
+
__decorate([
|
|
331
|
+
property({ type: String })
|
|
332
|
+
], KompasWidgetRecirculationsDefault.prototype, "type", void 0);
|
|
333
|
+
__decorate([
|
|
334
|
+
property({ type: String })
|
|
335
|
+
], KompasWidgetRecirculationsDefault.prototype, "mainCategory", void 0);
|
|
336
|
+
KompasWidgetRecirculationsDefault = __decorate([
|
|
337
|
+
customElement('kompasid-widget-recirculations-default')
|
|
338
|
+
], KompasWidgetRecirculationsDefault);
|
|
339
|
+
export { KompasWidgetRecirculationsDefault };
|
|
340
|
+
//# sourceMappingURL=KompasWidgetRecirculationsDefault.js.map
|
|
@@ -0,0 +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,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AAIjD,IAAM,iCAAiC,GAAvC,MAAM,iCAAkC,SAAQ,UAAU;IAA1D;;QAuBL;;WAEG;QACwB,UAAK,GAAa,EAAE,CAAA;QACnB,eAAU,GAA2B,SAAS,CAAA;QAC9C,gBAAW,GAAG,EAAE,CAAA;QAChB,qBAAgB,GAAG,EAAE,CAAA;QACrB,aAAQ,GAAG,GAAG,CAAA;QACd,UAAK,GAAG,EAAE,CAAA;QACV,SAAI,GAC9B,gBAAgB,CAAA;QACU,iBAAY,GAAG,EAAE,CAAA;IA2S/C,CAAC;IAzSC;;OAEG;IACH,IAAI,mBAAmB;;QACrB,OAAO,MAAA,IAAI,CAAC,UAAU,0CAAE,SAAS,CAAA;IACnC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,iBAAiB;QACrB,KAAK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,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC;;;;;;mBAMhD,CACF;YACH,CAAC,CAAC,EAAE;;;;;;;;KAQb,CAAA;IACH,CAAC;;AA3UM,wCAAM,GAAG;IACd,GAAG,CAAA;;;;;;;;;;;;;;;;;KAiBF;IACD,QAAQ;CACT,CAAA;AAK0B;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;gEAAqB;AACnB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qEAA+C;AAC9C;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sEAAiB;AAChB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;2EAAsB;AACrB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;mEAAe;AACd;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gEAAW;AACV;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+DACT;AACU;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uEAAkB;AAlClC,iCAAiC;IAD7C,aAAa,CAAC,wCAAwC,CAAC;GAC3C,iCAAiC,CA6U7C;SA7UY,iCAAiC","sourcesContent":["import { html, css, LitElement } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport { format } from 'date-fns'\nimport { id } from 'date-fns/locale/id'\nimport { TWStyles } from '../../../tailwind/tailwind.js'\nimport { Post, Navigation } from './types.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: Object }) navigation: Navigation | undefined = undefined\n @property({ type: String }) accessToken = ''\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\n /**\n * Getters\n */\n get navigationPermalink(): string | undefined {\n return this.navigation?.permalink\n }\n\n /**\n * Fetch Data\n */\n async connectedCallback() {\n super.connectedCallback()\n try {\n await this.fetchAccessToken()\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 fetchAccessToken() {\n const response = await fetch(\n 'https://api.kompas.id/account/api/v1/login/guest',\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n email: 'anonynous.user@kompas.id',\n }),\n }\n )\n\n const result = await response.json()\n\n if (result?.data?.accessToken) {\n this.accessToken = result.data.accessToken\n } else {\n throw new Error('Token akses tidak tersedia dalam respons')\n }\n }\n\n async relatedArticles() {\n if (!this.accessToken) {\n throw new Error('Token akses tidak tersedia')\n }\n\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 Authorization: `Bearer ${this.accessToken}`,\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 console.log('related article:', this.posts)\n } else {\n throw new Error('Data artikel terkait tidak ditemukan')\n }\n }\n\n async otherArticles() {\n if (!this.accessToken) {\n throw new Error('Token akses tidak tersedia')\n }\n\n const kompasApiCdsSPA = 'https://cds.kompas.id/api/v1'\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 Authorization: `Bearer ${this.accessToken}`,\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 console.log('other article:', this.posts)\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 * Function to format date\n */\n formatDate(date: string) {\n return format(new Date(date), 'dd MMMM yyyy', { locale: id })\n }\n\n /**\n * Render widget components\n */\n\n private WidgetTitle() {\n if (this.navigationPermalink) {\n return html`\n <a\n href=\"${this.navigationPermalink}\"\n class=\"flex font-sans uppercase items-start mb-6 mt-8\"\n >\n <h5\n class=\"${[\n 'capitalize font-bold font-sans',\n this.navigationPermalink ? 'text-brand-1' : 'text-grey-600',\n ].join(' ')}\"\n >\n ${this.navigation?.name}\n </h5>\n </a>\n `\n }\n\n return html`\n <div class=\"flex font-sans uppercase items-start mb-6 mt-8\">\n <div>\n <h5\n class=\"${[\n 'capitalize font-bold font-sans',\n this.navigationPermalink ? 'text-brand-1' : 'text-grey-600',\n ].join(' ')}\"\n >\n ${this.navigation?.name}\n </h5>\n </div>\n </div>\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 isFreemium = post.isFreemium === true\n\n 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\">\n <!-- start: widget title -->\n ${this.WidgetTitle()}\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-grey-600\"\n >\n ${post.title}\n </h5>\n <p class=\"text-grey-600 pt-2\">\n ${this.formatDate(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-grey-600\"\n >\n ${post.title}\n </h5>\n <p class=\"text-grey-600 pt-2\">\n ${this.formatDate(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"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface PostTag {
|
|
2
|
+
slug: string;
|
|
3
|
+
}
|
|
4
|
+
export interface Post {
|
|
5
|
+
title: string;
|
|
6
|
+
isAnalisis?: boolean;
|
|
7
|
+
isEksklusif?: boolean;
|
|
8
|
+
isFreemium?: boolean;
|
|
9
|
+
featuredImageThumbnailMedium: string;
|
|
10
|
+
permalink: string;
|
|
11
|
+
publishedDate: string;
|
|
12
|
+
postTag?: PostTag[];
|
|
13
|
+
thumbnails: {
|
|
14
|
+
sizes: {
|
|
15
|
+
thumbnailMedium: {
|
|
16
|
+
permalink: string;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface Navigation {
|
|
24
|
+
name: string;
|
|
25
|
+
permalink: string;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +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\nexport interface Navigation {\n name: string\n permalink: string\n}\n"]}
|
package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
interface PostTag {
|
|
3
|
+
slug: string;
|
|
4
|
+
}
|
|
5
|
+
interface ListItem {
|
|
6
|
+
title: string;
|
|
7
|
+
isAnalisis?: boolean;
|
|
8
|
+
isEksklusif?: boolean;
|
|
9
|
+
isFreemium?: boolean;
|
|
10
|
+
permalink: string;
|
|
11
|
+
publishedDate?: string;
|
|
12
|
+
postTag?: PostTag[];
|
|
13
|
+
}
|
|
14
|
+
export declare class KompasWidgetRecirculationsList extends LitElement {
|
|
15
|
+
widgetTitle: string;
|
|
16
|
+
articleList: ListItem[];
|
|
17
|
+
accessToken: string;
|
|
18
|
+
apiSlug: string;
|
|
19
|
+
static styles: import("lit").CSSResult[];
|
|
20
|
+
connectedCallback(): Promise<void>;
|
|
21
|
+
fetchAccessToken(): Promise<void>;
|
|
22
|
+
fetchArticles(): Promise<void>;
|
|
23
|
+
formatDate(date: string): string;
|
|
24
|
+
handleFetchError(error: unknown): void;
|
|
25
|
+
renderChips(item: ListItem): import("lit").TemplateResult<1>[];
|
|
26
|
+
render(): import("lit").TemplateResult<1>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { html, css, LitElement } from 'lit';
|
|
3
|
+
import { customElement, property } from 'lit/decorators.js';
|
|
4
|
+
import { format } from 'date-fns';
|
|
5
|
+
import { id } from 'date-fns/locale/id';
|
|
6
|
+
import { TWStyles } from '../../../tailwind/tailwind.js';
|
|
7
|
+
let KompasWidgetRecirculationsList = class KompasWidgetRecirculationsList extends LitElement {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.widgetTitle = '';
|
|
11
|
+
this.articleList = [];
|
|
12
|
+
this.accessToken = '';
|
|
13
|
+
this.apiSlug = '';
|
|
14
|
+
}
|
|
15
|
+
async connectedCallback() {
|
|
16
|
+
super.connectedCallback();
|
|
17
|
+
try {
|
|
18
|
+
await this.fetchAccessToken();
|
|
19
|
+
await this.fetchArticles();
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
this.handleFetchError(error);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async fetchAccessToken() {
|
|
26
|
+
var _a;
|
|
27
|
+
const response = await fetch('https://api.kompas.id/account/api/v1/login/guest', {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers: {
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
},
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
email: 'anonynous.user@kompas.id',
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
const result = await response.json();
|
|
37
|
+
if ((_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.accessToken) {
|
|
38
|
+
this.accessToken = result.data.accessToken;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error('Token akses tidak tersedia dalam respons');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async fetchArticles() {
|
|
45
|
+
if (!this.accessToken) {
|
|
46
|
+
throw new Error('Token akses tidak tersedia');
|
|
47
|
+
}
|
|
48
|
+
const endpoint = `https://cds.kompas.id/api/v1/article/${this.apiSlug}`;
|
|
49
|
+
const response = await fetch(endpoint, {
|
|
50
|
+
headers: {
|
|
51
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
52
|
+
'Content-Type': 'application/json',
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
const result = await response.json();
|
|
56
|
+
if (result === null || result === void 0 ? void 0 : result.result) {
|
|
57
|
+
this.articleList = result.result.map((article) => {
|
|
58
|
+
const { postTag = [], isFreemium = false, title, permalink, publishedDate, } = article;
|
|
59
|
+
const isAnalisis = postTag.some((tag) => tag.slug === 'analisis');
|
|
60
|
+
const isEksklusif = postTag.some((tag) => tag.slug === 'eksklusif');
|
|
61
|
+
return {
|
|
62
|
+
isAnalisis,
|
|
63
|
+
isEksklusif,
|
|
64
|
+
isFreemium,
|
|
65
|
+
title,
|
|
66
|
+
permalink,
|
|
67
|
+
publishedDate,
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
throw new Error('Data artikel populer tidak ditemukan');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
formatDate(date) {
|
|
76
|
+
return format(new Date(date), "dd MMMM yyyy' · 'HH:mm' WIB", { locale: id });
|
|
77
|
+
}
|
|
78
|
+
handleFetchError(error) {
|
|
79
|
+
const errorMessage = error instanceof Error ? error.message : 'Kesalahan tidak diketahui';
|
|
80
|
+
alert(`Terjadi kesalahan: ${errorMessage}`);
|
|
81
|
+
}
|
|
82
|
+
renderChips(item) {
|
|
83
|
+
const chips = [];
|
|
84
|
+
if (item.isAnalisis) {
|
|
85
|
+
chips.push(html `
|
|
86
|
+
<div class="flex">
|
|
87
|
+
<div class="chip bg-orange-100 text-orange-500">Analisis</div>
|
|
88
|
+
</div>
|
|
89
|
+
`);
|
|
90
|
+
}
|
|
91
|
+
if (item.isEksklusif) {
|
|
92
|
+
chips.push(html `
|
|
93
|
+
<div class="flex">
|
|
94
|
+
<div class="chip bg-grey-600 text-white">
|
|
95
|
+
<img
|
|
96
|
+
src="https://cdn-www.kompas.id/assets/img/icons/kompas-icon-small.svg"
|
|
97
|
+
alt="Kompas Icon"
|
|
98
|
+
style="width: 16px; height: 16px; margin-right: 4px;"
|
|
99
|
+
/>
|
|
100
|
+
Eksklusif
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
`);
|
|
104
|
+
}
|
|
105
|
+
if (item.isFreemium) {
|
|
106
|
+
chips.push(html `
|
|
107
|
+
<div class="flex">
|
|
108
|
+
<div class="chip bg-blue-100 text-brand-1">Bebas Akses</div>
|
|
109
|
+
</div>
|
|
110
|
+
`);
|
|
111
|
+
}
|
|
112
|
+
return chips;
|
|
113
|
+
}
|
|
114
|
+
render() {
|
|
115
|
+
return html `
|
|
116
|
+
<div>
|
|
117
|
+
<div class="mb-6">
|
|
118
|
+
<h5 class="capitalize font-bold text-grey-600 font-sans">
|
|
119
|
+
${this.widgetTitle}
|
|
120
|
+
</h5>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<ul class="flex flex-col">
|
|
124
|
+
${this.articleList.slice(0, 5).map(item => html `
|
|
125
|
+
<li class="flex flex-col items-start mb-3">
|
|
126
|
+
<div class="flex w-full">
|
|
127
|
+
<div class="flex flex-col w-full">
|
|
128
|
+
${this.renderChips(item)}
|
|
129
|
+
<a
|
|
130
|
+
href="${item.permalink}"
|
|
131
|
+
class="font-bold font-sans hover:underline leading-tight text-base text-grey-600"
|
|
132
|
+
>
|
|
133
|
+
${item.title}
|
|
134
|
+
</a>
|
|
135
|
+
<div
|
|
136
|
+
class="flex w-full flex-row items-center leading-normal justify-between text-sm text-grey-500 font-sans pt-2"
|
|
137
|
+
>
|
|
138
|
+
${item.publishedDate
|
|
139
|
+
? this.formatDate(item.publishedDate)
|
|
140
|
+
: 'Tanggal tidak tersedia'}
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
</li>
|
|
145
|
+
`)}
|
|
146
|
+
</ul>
|
|
147
|
+
</div>
|
|
148
|
+
`;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
KompasWidgetRecirculationsList.styles = [
|
|
152
|
+
css `
|
|
153
|
+
:host {
|
|
154
|
+
font-family: 'PT Sans', sans-serif;
|
|
155
|
+
}
|
|
156
|
+
.chip {
|
|
157
|
+
align-items: center;
|
|
158
|
+
border-radius: 0.25rem;
|
|
159
|
+
display: flex;
|
|
160
|
+
font-family: 'PT Sans', sans-serif;
|
|
161
|
+
font-size: 0.75rem;
|
|
162
|
+
font-weight: bold;
|
|
163
|
+
height: 1.5rem;
|
|
164
|
+
justify-content: center;
|
|
165
|
+
line-height: 1rem;
|
|
166
|
+
margin-bottom: 0.25rem;
|
|
167
|
+
padding: 0.375rem 0.5rem;
|
|
168
|
+
}
|
|
169
|
+
`,
|
|
170
|
+
TWStyles,
|
|
171
|
+
];
|
|
172
|
+
__decorate([
|
|
173
|
+
property({ type: String })
|
|
174
|
+
], KompasWidgetRecirculationsList.prototype, "widgetTitle", void 0);
|
|
175
|
+
__decorate([
|
|
176
|
+
property({ type: Array })
|
|
177
|
+
], KompasWidgetRecirculationsList.prototype, "articleList", void 0);
|
|
178
|
+
__decorate([
|
|
179
|
+
property({ type: String })
|
|
180
|
+
], KompasWidgetRecirculationsList.prototype, "accessToken", void 0);
|
|
181
|
+
__decorate([
|
|
182
|
+
property({ type: String })
|
|
183
|
+
], KompasWidgetRecirculationsList.prototype, "apiSlug", void 0);
|
|
184
|
+
KompasWidgetRecirculationsList = __decorate([
|
|
185
|
+
customElement('kompasid-widget-recirculations-list')
|
|
186
|
+
], KompasWidgetRecirculationsList);
|
|
187
|
+
export { KompasWidgetRecirculationsList };
|
|
188
|
+
//# sourceMappingURL=KompasWidgetRecirculationsList.js.map
|
|
@@ -0,0 +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,UAA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B;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;mEAAiB;AAChB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+DAAa;AAJ7B,8BAA8B;IAD1C,aAAa,CAAC,qCAAqC,CAAC;GACxC,8BAA8B,CAgN1C;SAhNY,8BAA8B","sourcesContent":["import { html, css, LitElement } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport { format } from 'date-fns'\nimport { id } from 'date-fns/locale/id'\nimport { TWStyles } from '../../../tailwind/tailwind.js'\n\ninterface PostTag {\n slug: string\n}\n\ninterface ListItem {\n title: string\n isAnalisis?: boolean\n isEksklusif?: boolean\n isFreemium?: 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 }) accessToken = ''\n @property({ type: String }) apiSlug = ''\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.fetchAccessToken()\n await this.fetchArticles()\n } catch (error) {\n this.handleFetchError(error)\n }\n }\n\n async fetchAccessToken() {\n const response = await fetch(\n 'https://api.kompas.id/account/api/v1/login/guest',\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n email: 'anonynous.user@kompas.id',\n }),\n }\n )\n\n const result = await response.json()\n\n if (result?.data?.accessToken) {\n this.accessToken = result.data.accessToken\n } else {\n throw new Error('Token akses tidak tersedia dalam respons')\n }\n }\n\n async fetchArticles() {\n if (!this.accessToken) {\n throw new Error('Token akses tidak tersedia')\n }\n\n const endpoint = `https://cds.kompas.id/api/v1/article/${this.apiSlug}`\n\n const response = await fetch(endpoint, {\n headers: {\n Authorization: `Bearer ${this.accessToken}`,\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\n return {\n isAnalisis,\n isEksklusif,\n isFreemium,\n title,\n permalink,\n publishedDate,\n }\n }\n )\n } else {\n throw new Error('Data artikel populer tidak ditemukan')\n }\n }\n\n formatDate(date: string) {\n return format(new Date(date), \"dd MMMM yyyy' · 'HH:mm' WIB\", { locale: id })\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.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 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 }\n\n 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 }\n\n return chips\n }\n\n render() {\n return html`\n <div>\n <div class=\"mb-6\">\n <h5 class=\"capitalize font-bold text-grey-600 font-sans\">\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}\"\n class=\"font-bold font-sans hover:underline leading-tight text-base text-grey-600\"\n >\n ${item.title}\n </a>\n <div\n class=\"flex w-full flex-row items-center leading-normal justify-between text-sm text-grey-500 font-sans pt-2\"\n >\n ${item.publishedDate\n ? this.formatDate(item.publishedDate)\n : 'Tanggal tidak tersedia'}\n </div>\n </div>\n </div>\n </li>\n `\n )}\n </ul>\n </div>\n `\n }\n}\n"]}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { KompasWidgetRecirculationsDefault } from './components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.js';
|
|
2
|
+
export { KompasWidgetRecirculationsList } from './components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.js';
|
|
1
3
|
export { KompasPaywall } from './components/kompasid-paywall/KompasPaywall.js';
|
|
2
4
|
export { KompasFooter } from './components/kompasid-footer/KompasFooter.js';
|
|
3
5
|
export { KompasPaywallVideo } from './components/kompasid-paywall-video/KompasPaywallVideo.js';
|