@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.
Files changed (31) hide show
  1. package/_sdk-exports/context-blog-feed-context-provider/runtime.d.ts +280 -99
  2. package/_sdk-exports/context-category-item-context-provider/runtime.d.ts +13 -14
  3. package/_sdk-exports/context-post-context-provider/runtime.d.ts +257 -81
  4. package/_sdk-exports/context-post-item-context-provider/runtime.d.ts +201 -78
  5. package/_sdk-exports/context-related-posts-context-provider/runtime.d.ts +178 -82
  6. package/_sdk-exports/context-tag-item-context-provider/runtime.d.ts +12 -11
  7. package/build/cjs/context-blog-feed-context-provider.d.ts +280 -99
  8. package/build/cjs/context-category-item-context-provider.d.ts +13 -14
  9. package/build/cjs/context-post-context-provider.d.ts +257 -81
  10. package/build/cjs/context-post-item-context-provider.d.ts +201 -78
  11. package/build/cjs/context-related-posts-context-provider.d.ts +178 -82
  12. package/build/cjs/context-tag-item-context-provider.d.ts +12 -11
  13. package/build/es/context-blog-feed-context-provider.d.mts +280 -99
  14. package/build/es/context-category-item-context-provider.d.mts +13 -14
  15. package/build/es/context-post-context-provider.d.mts +257 -81
  16. package/build/es/context-post-item-context-provider.d.mts +201 -78
  17. package/build/es/context-related-posts-context-provider.d.mts +178 -82
  18. package/build/es/context-tag-item-context-provider.d.mts +12 -11
  19. package/build/internal/cjs/context-blog-feed-context-provider.d.ts +280 -99
  20. package/build/internal/cjs/context-category-item-context-provider.d.ts +13 -14
  21. package/build/internal/cjs/context-post-context-provider.d.ts +257 -81
  22. package/build/internal/cjs/context-post-item-context-provider.d.ts +201 -78
  23. package/build/internal/cjs/context-related-posts-context-provider.d.ts +178 -82
  24. package/build/internal/cjs/context-tag-item-context-provider.d.ts +12 -11
  25. package/build/internal/es/context-blog-feed-context-provider.d.mts +280 -99
  26. package/build/internal/es/context-category-item-context-provider.d.mts +13 -14
  27. package/build/internal/es/context-post-context-provider.d.mts +257 -81
  28. package/build/internal/es/context-post-item-context-provider.d.mts +201 -78
  29. package/build/internal/es/context-related-posts-context-provider.d.mts +178 -82
  30. package/build/internal/es/context-tag-item-context-provider.d.mts +12 -11
  31. 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
- /** One playable rendition of a Wix-hosted cover video (a raw REST `VideoResolution`). */
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
- type EmbedProvider = 'youtube' | 'vimeo' | 'unknown';
179
+ /** Site that hosts an embedded cover video. */
180
+ type EmbedProvider =
177
181
  /**
178
- * The post cover as the Cover Media widget consumes it — a discriminated union over the
179
- * `post.media` oneof: a Wix-hosted image, a Wix-hosted video (`wixMedia.videoV2`), or an
180
- * externally hosted embed (`embedMedia`, YouTube/Vimeo).
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'; /** The WixMedia video id — the `wix:video://v1/<id>/...` path segment. */
199
+ /** Cover video uploaded to Wix. */kind: 'wixVideo'; /** Video ID. */
187
200
  id: string;
188
- posterUrl?: string;
189
- posterWidth?: number;
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 mp4 renditions, optimal-first. Empty when the raw REST join was
193
- * unavailable — the widget then renders the poster alone (see post-video-api.ts
194
- * for why the SDK's `videoV2` string cannot carry these).
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; /** The author-supplied external video URL, as the Blog API stores it. */
201
- videoUrl: string; /** Provider player URL for click-to-play; absent for an unrecognized provider. */
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
- thumbnailUrl?: string;
204
- thumbnailWidth?: number;
205
- thumbnailHeight?: number;
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
- /** Repeater item identity; also the manifest contract's `_id`. */
240
+ /** Post ID. */
219
241
  _id: string;
220
- /** The manifest contract's `title` (plain text, non-bindable — see `itemTitle` below). */
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
- * The cover as the Cover Media widget renders it — image OR playable video, where
227
- * `itemCoverImage` above can only ever be the image. Runtime-only by design: deliberately
228
- * absent from `POST_ITEM_CONTRACT_ITEMS` and the Post Item manifest (the runtime injects
229
- * the full item object regardless, and the manifest contract must stay text-scalars-only —
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
- * Raw values for the compact widgets (Metadata, Counters), which format for themselves
238
- * (a design-panel date/number format) instead of parsing the richText labels above.
239
- * Runtime-only like `itemCoverMedia` — never bindable items. JSON-safe on purpose (ISO
240
- * string, numbers): the item crosses the platform's per-cell prop injection, and a `Date`
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
- * The clock `itemPublishedDate` was formatted from (`useHydrationClock`) — the compact
247
- * widgets format `publishedDateValue` for themselves and must use the same one, or their
248
- * label would hydrate against a different "now" than the bound text did.
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
- /** `undefined` when absent OR 0 — the same API-artifact rule as `timeToRead` below. */
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
- * The server-side METRICS counters as raw numbers, the seed the Post Item provider
255
- * publishes as `viewCountValue`/`commentCountValue` until its client-only metrics read
256
- * lands (and for good in the editor, where that read is skipped). Same three-way rule as
257
- * the `viewCount`/`commentCount` labels: metric → canvas stand-in → `undefined`, never 0.
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
- * The remaining keys reuse the Post context's names verbatim — the registry is per app and
263
- * keyed by item path, so re-declaring a key at the same dataType on the Post Item context
264
- * costs no new registry rows (the same trick `likeCount` already relies on).
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
- * Resolved in priority order by `counterLabel`:
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
- * Blank rather than zero at step 3 because a seeded "0 views" reads as a confident wrong
277
- * number until that read lands. Step 1 exists because step 3 alone is not enough: the
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
- * The post's MAIN category label — one, not a list. blog-client's feed card renders a single
286
- * category (`post.categoryIds[0]`); its multi-category `CategoryLabelList` was built for the
287
- * feed and never shipped, and the 3-chip list lives on the post page only.
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
- /** Mirrors the Post Item manifest's nested (non-bindable) `recentPostItem` data item. */
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 the post takes new comments — the Comments widget's lock in a cell. Runtime-only
297
- * like `itemCoverMedia`; `undefined` (partial fieldset, canvas stand-in) reads as unlocked.
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