@wix/blog 1.0.692 → 1.0.694
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/_sdk-exports/context-blog-feed-context-provider/runtime.d.ts +280 -99
- package/_sdk-exports/context-category-item-context-provider/runtime.d.ts +13 -14
- package/_sdk-exports/context-post-context-provider/runtime.d.ts +257 -81
- package/_sdk-exports/context-post-item-context-provider/runtime.d.ts +201 -78
- package/_sdk-exports/context-related-posts-context-provider/runtime.d.ts +178 -82
- package/_sdk-exports/context-tag-item-context-provider/runtime.d.ts +12 -11
- package/build/cjs/context-blog-feed-context-provider.d.ts +280 -99
- package/build/cjs/context-category-item-context-provider.d.ts +13 -14
- package/build/cjs/context-post-context-provider.d.ts +257 -81
- package/build/cjs/context-post-item-context-provider.d.ts +201 -78
- package/build/cjs/context-related-posts-context-provider.d.ts +178 -82
- package/build/cjs/context-tag-item-context-provider.d.ts +12 -11
- package/build/es/context-blog-feed-context-provider.d.mts +280 -99
- package/build/es/context-category-item-context-provider.d.mts +13 -14
- package/build/es/context-post-context-provider.d.mts +257 -81
- package/build/es/context-post-item-context-provider.d.mts +201 -78
- package/build/es/context-related-posts-context-provider.d.mts +178 -82
- package/build/es/context-tag-item-context-provider.d.mts +12 -11
- package/build/internal/cjs/context-blog-feed-context-provider.d.ts +280 -99
- package/build/internal/cjs/context-category-item-context-provider.d.ts +13 -14
- package/build/internal/cjs/context-post-context-provider.d.ts +257 -81
- package/build/internal/cjs/context-post-item-context-provider.d.ts +201 -78
- package/build/internal/cjs/context-related-posts-context-provider.d.ts +178 -82
- package/build/internal/cjs/context-tag-item-context-provider.d.ts +12 -11
- package/build/internal/es/context-blog-feed-context-provider.d.mts +280 -99
- package/build/internal/es/context-category-item-context-provider.d.mts +13 -14
- package/build/internal/es/context-post-context-provider.d.mts +257 -81
- package/build/internal/es/context-post-item-context-provider.d.mts +201 -78
- package/build/internal/es/context-related-posts-context-provider.d.mts +178 -82
- package/build/internal/es/context-tag-item-context-provider.d.mts +12 -11
- package/package.json +4 -4
|
@@ -167,134 +167,198 @@ declare global {
|
|
|
167
167
|
}
|
|
168
168
|
//#endregion
|
|
169
169
|
//#region src/lib/parse-post-cover-media.d.ts
|
|
170
|
-
/**
|
|
170
|
+
/** Playable file of a cover video uploaded to Wix. */
|
|
171
171
|
interface VideoSource {
|
|
172
|
+
/** URL of the video file. */
|
|
172
173
|
url: string;
|
|
174
|
+
/** Width of the video, in pixels. `undefined` when it isn't known. */
|
|
173
175
|
width?: number;
|
|
176
|
+
/** Height of the video, in pixels. `undefined` when it isn't known. */
|
|
174
177
|
height?: number;
|
|
175
178
|
}
|
|
176
|
-
|
|
179
|
+
/** Site that hosts an embedded cover video. */
|
|
180
|
+
type EmbedProvider =
|
|
177
181
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
|
|
182
|
+
* YouTube. `embedUrl` is the video in YouTube's player, set to play as soon as it loads,
|
|
183
|
+
* so load it only after a site visitor clicks to play.
|
|
184
|
+
*/
|
|
185
|
+
'youtube'
|
|
186
|
+
/**
|
|
187
|
+
* Vimeo. `embedUrl` is the video in Vimeo's player, set to play as soon as it loads, so
|
|
188
|
+
* load it only after a site visitor clicks to play.
|
|
189
|
+
*/
|
|
190
|
+
| 'vimeo' /** Any other site. There's no `embedUrl`, so show the thumbnail instead of a player. */ | 'unknown';
|
|
191
|
+
/**
|
|
192
|
+
* Post's cover. It's an image, a video uploaded to Wix, or a video from another site, such as
|
|
193
|
+
* YouTube, embedded by its URL.
|
|
181
194
|
*/
|
|
182
195
|
type CoverMedia = {
|
|
183
|
-
kind: 'image';
|
|
196
|
+
/** Image cover. */kind: 'image'; /** Cover image, with its URL, size, and alt text. */
|
|
184
197
|
image: Image;
|
|
185
198
|
} | {
|
|
186
|
-
kind: 'wixVideo'; /**
|
|
199
|
+
/** Cover video uploaded to Wix. */kind: 'wixVideo'; /** Video ID. */
|
|
187
200
|
id: string;
|
|
188
|
-
|
|
189
|
-
|
|
201
|
+
/**
|
|
202
|
+
* URL of the video's poster image, the image shown before the video plays.
|
|
203
|
+
*
|
|
204
|
+
* `undefined` when the video has no poster image.
|
|
205
|
+
*/
|
|
206
|
+
posterUrl?: string; /** Width of the poster image, in pixels. `undefined` when it isn't known. */
|
|
207
|
+
posterWidth?: number; /** Height of the poster image, in pixels. `undefined` when it isn't known. */
|
|
190
208
|
posterHeight?: number;
|
|
191
209
|
/**
|
|
192
|
-
* Playable
|
|
193
|
-
*
|
|
194
|
-
*
|
|
210
|
+
* Playable files of the video, the recommended one first.
|
|
211
|
+
*
|
|
212
|
+
* Empty when the video's files couldn't be loaded. Show the poster image instead.
|
|
195
213
|
*/
|
|
196
|
-
sources: VideoSource[];
|
|
214
|
+
sources: VideoSource[]; /** Alt text for the cover. The post's title when the cover has no alt text. */
|
|
197
215
|
altText: string;
|
|
198
216
|
} | {
|
|
199
|
-
kind: 'embed';
|
|
200
|
-
provider: EmbedProvider; /**
|
|
201
|
-
videoUrl: string;
|
|
217
|
+
/** Cover video embedded from another site, such as YouTube. */kind: 'embed'; /** Site that hosts the video. */
|
|
218
|
+
provider: EmbedProvider; /** URL of the video on its own site. */
|
|
219
|
+
videoUrl: string;
|
|
220
|
+
/**
|
|
221
|
+
* URL of the video in its site's player, set to play as soon as it loads.
|
|
222
|
+
*
|
|
223
|
+
* `undefined` when `provider` is `'unknown'`.
|
|
224
|
+
*/
|
|
202
225
|
embedUrl?: string;
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
226
|
+
/**
|
|
227
|
+
* URL of the video's thumbnail image.
|
|
228
|
+
*
|
|
229
|
+
* `undefined` when the video has no thumbnail.
|
|
230
|
+
*/
|
|
231
|
+
thumbnailUrl?: string; /** Width of the thumbnail image, in pixels. `undefined` when it isn't known. */
|
|
232
|
+
thumbnailWidth?: number; /** Height of the thumbnail image, in pixels. `undefined` when it isn't known. */
|
|
233
|
+
thumbnailHeight?: number; /** Alt text for the cover. The post's title when the cover has no alt text. */
|
|
206
234
|
altText: string;
|
|
207
235
|
};
|
|
208
236
|
//#endregion
|
|
209
237
|
//#region src/extensions/post-list-context-provider/utils.d.ts
|
|
210
|
-
/**
|
|
211
|
-
* One item of the `postsList` array — the object the platform hands the Post Item
|
|
212
|
-
* context provider as its `postData` prop (via the manifest's `contextImplementor`).
|
|
213
|
-
* The `item*`/`recentPostItem` keys must match the Post Item context manifest's
|
|
214
|
-
* `context.items` keys — the runtime resolves an element's binding by looking the key
|
|
215
|
-
* up on the per-item hook's return value.
|
|
216
|
-
*/
|
|
238
|
+
/** Post with its fields ready to show in a repeater item. */
|
|
217
239
|
interface PostListItem {
|
|
218
|
-
/**
|
|
240
|
+
/** Post ID. */
|
|
219
241
|
_id: string;
|
|
220
|
-
/**
|
|
242
|
+
/** Post's title, as plain text. */
|
|
221
243
|
title: string;
|
|
244
|
+
/**
|
|
245
|
+
* Post's title, as rich text. Its `text` field holds the plain text, and its `html` field
|
|
246
|
+
* holds the text as an HTML paragraph.
|
|
247
|
+
*/
|
|
222
248
|
itemTitle: RichText;
|
|
249
|
+
/** Post's excerpt, as rich text. Empty when the post has no excerpt. */
|
|
223
250
|
itemExcerpt: RichText;
|
|
251
|
+
/**
|
|
252
|
+
* Post's cover image, with its URL, size, and alt text. For a post whose cover is a video
|
|
253
|
+
* uploaded to Wix, the video's poster image.
|
|
254
|
+
*
|
|
255
|
+
* `undefined` when there's no image to show, such as when the cover is an embedded video.
|
|
256
|
+
*
|
|
257
|
+
* It holds the cover image even when the post's author hid the cover. To leave out a hidden
|
|
258
|
+
* cover, check `itemCoverMedia`, which is `undefined` then.
|
|
259
|
+
*/
|
|
224
260
|
itemCoverImage: Image | undefined;
|
|
225
261
|
/**
|
|
226
|
-
*
|
|
227
|
-
* `itemCoverImage`
|
|
228
|
-
*
|
|
229
|
-
* the
|
|
230
|
-
* see post-item-contract.ts). Not bindable in Connect Value; consumed via
|
|
231
|
-
* `usePostItemContext()` only.
|
|
262
|
+
* Post's cover as an image or a playable video. Use it to play a video cover, which
|
|
263
|
+
* `itemCoverImage` holds only as its poster image.
|
|
264
|
+
*
|
|
265
|
+
* `undefined` when the post has no cover, or the post's author hid it.
|
|
232
266
|
*/
|
|
233
267
|
itemCoverMedia: CoverMedia | undefined;
|
|
268
|
+
/**
|
|
269
|
+
* Link to the post's page. `href` is the page's URL, and `target` is `'_self'`, so the link
|
|
270
|
+
* opens in the same tab.
|
|
271
|
+
*
|
|
272
|
+
* `undefined` when the post has no slug and no URL.
|
|
273
|
+
*/
|
|
234
274
|
itemLink: Link | undefined;
|
|
275
|
+
/**
|
|
276
|
+
* Date the post was first published, as rich text in the site's regional format. In the
|
|
277
|
+
* week after publishing, it's relative, such as "3 days ago". After that, it's a date, such
|
|
278
|
+
* as "Aug 5", with the year when it isn't the current year.
|
|
279
|
+
*/
|
|
235
280
|
itemPublishedDate: RichText;
|
|
236
281
|
/**
|
|
237
|
-
*
|
|
238
|
-
* (
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
* would not survive the round-trip.
|
|
282
|
+
* Date the post was first published, as an
|
|
283
|
+
* [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) string.
|
|
284
|
+
*
|
|
285
|
+
* `undefined` when the post has no publish date.
|
|
242
286
|
*/
|
|
243
|
-
/** ISO 8601; `undefined` for a post without `firstPublishedDate`. */
|
|
244
287
|
publishedDateValue: string | undefined;
|
|
245
288
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
289
|
+
* Current time that `itemPublishedDate` is relative to, in milliseconds since the Unix
|
|
290
|
+
* epoch.
|
|
291
|
+
*
|
|
292
|
+
* When you format `publishedDateValue` as a relative date yourself, use this value as the
|
|
293
|
+
* current time, so your text matches `itemPublishedDate`.
|
|
249
294
|
*/
|
|
250
295
|
clockValue: number;
|
|
251
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* Estimated reading time, in minutes.
|
|
298
|
+
*
|
|
299
|
+
* `undefined` when the post has no estimate.
|
|
300
|
+
*/
|
|
252
301
|
minutesToReadValue: number | undefined;
|
|
253
302
|
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
303
|
+
* Number of times the post was viewed, as loaded with the post.
|
|
304
|
+
*
|
|
305
|
+
* `undefined` when the count wasn't loaded with the post. In the editor, but not in Preview,
|
|
306
|
+
* a sample number instead.
|
|
258
307
|
*/
|
|
259
308
|
initialViewCount: number | undefined;
|
|
260
|
-
initialCommentCount: number | undefined;
|
|
261
309
|
/**
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
310
|
+
* Number of comments on the post, as loaded with the post.
|
|
311
|
+
*
|
|
312
|
+
* `undefined` when the count wasn't loaded with the post. In the editor, but not in Preview,
|
|
313
|
+
* a sample number instead.
|
|
265
314
|
*/
|
|
315
|
+
initialCommentCount: number | undefined;
|
|
316
|
+
/** Name of the post's author, as rich text. Empty when the author isn't found. */
|
|
266
317
|
authorName: RichText;
|
|
318
|
+
/**
|
|
319
|
+
* Author's profile photo, with its URL, size, and alt text. The alt text is the author's
|
|
320
|
+
* name, or a generic author-photo label when the author has no name.
|
|
321
|
+
*
|
|
322
|
+
* `undefined` when the author has no photo.
|
|
323
|
+
*/
|
|
267
324
|
authorImage: Image | undefined;
|
|
325
|
+
/**
|
|
326
|
+
* Estimated reading time as rich text in the site's language, such as "5 min read".
|
|
327
|
+
*
|
|
328
|
+
* Empty when the post has no estimate.
|
|
329
|
+
*/
|
|
268
330
|
timeToRead: RichText;
|
|
269
331
|
/**
|
|
270
|
-
*
|
|
271
|
-
* 1. the post's own `metrics` (the `METRICS` fieldset) — renders everywhere, including
|
|
272
|
-
* the editor canvas and inside SSR HTML;
|
|
273
|
-
* 2. an editor stand-in, when the API answers without metrics;
|
|
274
|
-
* 3. blank, for the Post Item provider to fill in from its per-cell metrics read.
|
|
332
|
+
* Number of views as rich text in the site's language, such as "1,234 views".
|
|
275
333
|
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
* per-cell read is client-only by design (personal data must never bake into SSR HTML the
|
|
279
|
-
* host caches for days) AND is skipped outright in the editor, which left a bound counter
|
|
280
|
-
* permanently blank on the canvas.
|
|
334
|
+
* Empty when the count wasn't loaded with the post. In the editor, but not in Preview, a
|
|
335
|
+
* sample count instead.
|
|
281
336
|
*/
|
|
282
337
|
viewCount: RichText;
|
|
338
|
+
/**
|
|
339
|
+
* Number of comments as rich text in the site's language.
|
|
340
|
+
*
|
|
341
|
+
* Empty when the count wasn't loaded with the post. In the editor, but not in Preview, a
|
|
342
|
+
* sample count instead.
|
|
343
|
+
*/
|
|
283
344
|
commentCount: RichText;
|
|
284
345
|
/**
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
346
|
+
* Name of the post's main category, as rich text. It's the first of the post's categories
|
|
347
|
+
* that still exists.
|
|
348
|
+
*
|
|
349
|
+
* Empty when none of the post's categories exists. In the editor, but not in Preview, a
|
|
350
|
+
* sample name instead.
|
|
288
351
|
*/
|
|
289
352
|
itemCategoryLabel: RichText;
|
|
290
|
-
/**
|
|
353
|
+
/** Post's title and slug, as plain text. */
|
|
291
354
|
recentPostItem: {
|
|
292
|
-
title: string;
|
|
355
|
+
/** Post's title. */title: string; /** Post's slug, the last part of the post page's URL. */
|
|
293
356
|
slug: string;
|
|
294
357
|
};
|
|
295
358
|
/**
|
|
296
|
-
* Whether
|
|
297
|
-
*
|
|
359
|
+
* Whether site visitors can comment on the post.
|
|
360
|
+
*
|
|
361
|
+
* `undefined` when it isn't known, such as for the sample posts in the editor.
|
|
298
362
|
*/
|
|
299
363
|
commentingEnabled: boolean | undefined;
|
|
300
364
|
}
|
|
@@ -327,17 +391,76 @@ interface PostLikes {
|
|
|
327
391
|
}
|
|
328
392
|
/** What `LiveLikes` reports — the `PostLikes` fields a widget renders. */
|
|
329
393
|
type LiveLikeSnapshot = Pick<PostLikes, 'isLiked' | 'likeCount' | 'isLikeCountLoaded' | 'viewCount' | 'commentCount'>;
|
|
330
|
-
/**
|
|
331
|
-
* Why the like state exists twice: on a hydrating post page, a provider state update that is
|
|
332
|
-
* NOT a transition makes React discard the server HTML of every child boundary still waiting
|
|
333
|
-
* on its module load or the viewport gate (React #421 — thunderbolt logs "SSR HTML discard").
|
|
334
|
-
* So the provider's own state updates only in transitions — but a transition is held until
|
|
335
|
-
* every boundary below has hydrated, which for a viewport-gated one means until the visitor
|
|
336
|
-
* scrolls to it. The Counters and Actions widgets subscribe here instead, after their own
|
|
337
|
-
* mount, and show the fresh numbers right away (`usePostWidgetContext`).
|
|
338
|
-
*/
|
|
394
|
+
/** The site visitor's like state and the post's counts, without delay. */
|
|
339
395
|
interface LiveLikes {
|
|
396
|
+
/**
|
|
397
|
+
* Retrieves the current like state and counts.
|
|
398
|
+
*
|
|
399
|
+
* @returns An object with `isLiked`, `likeCount`, `isLikeCountLoaded`, `viewCount`, and
|
|
400
|
+
* `commentCount`. `likeCount` is the number the context's `likeCountValue` holds, and
|
|
401
|
+
* `isLiked` and `isLikeCountLoaded` match the context properties with the same names.
|
|
402
|
+
*
|
|
403
|
+
* `viewCount` and `commentCount` are numbers, or `undefined` until the current counts load
|
|
404
|
+
* in the browser, and when they can't be loaded, such as in the editor's Preview mode.
|
|
405
|
+
*
|
|
406
|
+
* @example Thank the site visitor after they like the post
|
|
407
|
+
* ```tsx
|
|
408
|
+
* import { useState } from 'react';
|
|
409
|
+
* import { usePostByIdContext } from '@wix/blog/post-by-id-context-provider';
|
|
410
|
+
*
|
|
411
|
+
* function LikeButton() {
|
|
412
|
+
* const { isEmpty, isLiked, liveLikes, toggleLike } = usePostByIdContext();
|
|
413
|
+
* const [isThanked, setIsThanked] = useState(false);
|
|
414
|
+
*
|
|
415
|
+
* if (isEmpty || !liveLikes) {
|
|
416
|
+
* return null;
|
|
417
|
+
* }
|
|
418
|
+
*
|
|
419
|
+
* const handleClick = async () => {
|
|
420
|
+
* await toggleLike();
|
|
421
|
+
* // `isLiked` in this function is from before the click. `get()` has the current state.
|
|
422
|
+
* setIsThanked(liveLikes.get().isLiked);
|
|
423
|
+
* };
|
|
424
|
+
*
|
|
425
|
+
* return (
|
|
426
|
+
* <>
|
|
427
|
+
* <button aria-pressed={isLiked} onClick={handleClick}>
|
|
428
|
+
* {isLiked ? 'Liked' : 'Like'}
|
|
429
|
+
* </button>
|
|
430
|
+
* {isThanked && <span>Thanks for liking this post</span>}
|
|
431
|
+
* </>
|
|
432
|
+
* );
|
|
433
|
+
* }
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
340
436
|
get(): LiveLikeSnapshot;
|
|
437
|
+
/**
|
|
438
|
+
* Calls a listener each time the like state or the counts change.
|
|
439
|
+
*
|
|
440
|
+
* @param listener Callback that runs after each change, with no arguments. Call `get()` in
|
|
441
|
+
* it to read the new values.
|
|
442
|
+
* @returns Function that removes the listener. Call it when your component unmounts.
|
|
443
|
+
*
|
|
444
|
+
* @example Show the like count as soon as it changes
|
|
445
|
+
* ```tsx
|
|
446
|
+
* import { useSyncExternalStore } from 'react';
|
|
447
|
+
* import { usePostByIdContext } from '@wix/blog/post-by-id-context-provider';
|
|
448
|
+
*
|
|
449
|
+
* const noLikes = () => () => {};
|
|
450
|
+
*
|
|
451
|
+
* function LiveLikeCount() {
|
|
452
|
+
* const { liveLikes } = usePostByIdContext();
|
|
453
|
+
* const readLikeCount = () => liveLikes?.get().likeCount;
|
|
454
|
+
* const likeCount = useSyncExternalStore(
|
|
455
|
+
* liveLikes ? liveLikes.subscribe : noLikes,
|
|
456
|
+
* readLikeCount,
|
|
457
|
+
* readLikeCount,
|
|
458
|
+
* );
|
|
459
|
+
*
|
|
460
|
+
* return likeCount === undefined ? null : <span>{likeCount} likes</span>;
|
|
461
|
+
* }
|
|
462
|
+
* ```
|
|
463
|
+
*/
|
|
341
464
|
subscribe(listener: () => void): () => void;
|
|
342
465
|
}
|
|
343
466
|
//#endregion
|