@wix/blog 1.0.702 → 1.0.704
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/runtime.js +2 -2
- package/_sdk-exports/context-post/runtime.d.ts +195 -115
- package/_sdk-exports/context-post/runtime.js +2 -5
- package/_sdk-exports/context-post-by-id/runtime.js +3 -3
- package/_sdk-exports/context-post-by-slug/runtime.d.ts +18 -0
- package/_sdk-exports/context-post-by-slug/runtime.js +5 -0
- package/_sdk-exports/context-post-item/runtime.d.ts +5 -6
- package/_sdk-exports/context-post-item/runtime.js +4 -4
- package/_sdk-exports/context-post-list-item/runtime.d.ts +508 -0
- package/_sdk-exports/context-post-list-item/runtime.js +5 -0
- package/_sdk-exports/context-related-posts/runtime.js +2 -2
- package/build/cjs/context-blog-feed.js +1 -1
- package/build/cjs/context-blog-feed.js.map +1 -1
- package/build/cjs/context-post-by-id.js +534 -496
- package/build/cjs/context-post-by-id.js.map +1 -1
- package/build/cjs/context-post-by-slug.d.ts +18 -0
- package/build/cjs/context-post-by-slug.js +5455 -0
- package/build/cjs/context-post-by-slug.js.map +1 -0
- package/build/cjs/context-post-item.d.ts +5 -6
- package/build/cjs/context-post-item.js +804 -788
- package/build/cjs/context-post-item.js.map +1 -1
- package/build/cjs/context-post-list-item.d.ts +508 -0
- package/build/cjs/context-post-list-item.js +3698 -0
- package/build/cjs/context-post-list-item.js.map +1 -0
- package/build/cjs/context-post.d.ts +195 -115
- package/build/cjs/context-post.js +342 -5175
- package/build/cjs/context-post.js.map +1 -1
- package/build/cjs/context-related-posts.js +1 -1
- package/build/cjs/context-related-posts.js.map +1 -1
- package/build/es/context-blog-feed.mjs +1 -1
- package/build/es/context-blog-feed.mjs.map +1 -1
- package/build/es/context-post-by-id.mjs +534 -496
- package/build/es/context-post-by-id.mjs.map +1 -1
- package/build/es/context-post-by-slug.d.mts +18 -0
- package/build/es/context-post-by-slug.mjs +5415 -0
- package/build/es/context-post-by-slug.mjs.map +1 -0
- package/build/es/context-post-item.d.mts +5 -6
- package/build/es/context-post-item.mjs +803 -798
- package/build/es/context-post-item.mjs.map +1 -1
- package/build/es/context-post-list-item.d.mts +508 -0
- package/build/es/context-post-list-item.mjs +3657 -0
- package/build/es/context-post-list-item.mjs.map +1 -0
- package/build/es/context-post.d.mts +195 -115
- package/build/es/context-post.mjs +341 -5173
- package/build/es/context-post.mjs.map +1 -1
- package/build/es/context-related-posts.mjs +1 -1
- package/build/es/context-related-posts.mjs.map +1 -1
- package/build/internal/cjs/context-post-by-slug.d.ts +18 -0
- package/build/internal/cjs/context-post-item.d.ts +5 -6
- package/build/internal/cjs/context-post-list-item.d.ts +508 -0
- package/build/internal/cjs/context-post.d.ts +195 -115
- package/build/internal/es/context-post-by-slug.d.mts +18 -0
- package/build/internal/es/context-post-item.d.mts +5 -6
- package/build/internal/es/context-post-list-item.d.mts +508 -0
- package/build/internal/es/context-post.d.mts +195 -115
- package/context/post-by-slug/package.json +3 -0
- package/context/post-list-item/package.json +3 -0
- package/package.json +26 -2
- package/post-by-slug-context-provider/package.json +3 -0
- package/post-list-item-context-provider/package.json +3 -0
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
//#region ../../node_modules/@wix/editor-react-types/dist/links.d.ts
|
|
4
|
+
type LinkTarget = '_self' | '_blank';
|
|
5
|
+
/**
|
|
6
|
+
* A link to a URL, used for navigation within components.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import type { Link } from '@wix/editor-react-types';
|
|
11
|
+
*
|
|
12
|
+
* interface MyComponentProps {
|
|
13
|
+
* link?: Link;
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
type Link = {
|
|
18
|
+
/**
|
|
19
|
+
* The link URL. For partial links (see `pageRole`), this is the router prefix
|
|
20
|
+
* (e.g. `https://www.my-site.com/prefix`) rather than a fully resolved URL.
|
|
21
|
+
*/
|
|
22
|
+
href?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Where this link should open.
|
|
25
|
+
* - `'_self'` — opens in the same page.
|
|
26
|
+
* - `'_blank'` — opens in a new tab.
|
|
27
|
+
*/
|
|
28
|
+
target?: LinkTarget; /** The `rel` attribute of the link. Accepts LinkRel values separated by a space. */
|
|
29
|
+
rel?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Page role identifier. Present only on partial links, where only the router prefix is
|
|
32
|
+
* known and the full URL format is owned by the Router/App. Applications can use such
|
|
33
|
+
* links in functions to resolve the complete URL at runtime (e.g. for binding links).
|
|
34
|
+
* Resolved links will not have this field.
|
|
35
|
+
*/
|
|
36
|
+
pageRole?: string;
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region ../../node_modules/@wix/editor-react-types/dist/image.d.ts
|
|
40
|
+
type Point = {
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
};
|
|
44
|
+
type Crop = Point & {
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* An image from Wix Media.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```tsx
|
|
53
|
+
* import type { Image } from '@wix/editor-react-types';
|
|
54
|
+
*
|
|
55
|
+
* interface MyComponentProps {
|
|
56
|
+
* image?: Image;
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* const MyComponent = ({ image }: MyComponentProps) => (
|
|
60
|
+
* <img src={image?.url} alt={image?.alt} />
|
|
61
|
+
* );
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
type Image = {
|
|
65
|
+
/** The image URI. */uri?: string; /** The image URL. */
|
|
66
|
+
url: string; /** The image file name. */
|
|
67
|
+
name?: string; /** The image height in pixels. */
|
|
68
|
+
height?: number; /** The image width in pixels. */
|
|
69
|
+
width?: number; /** Whether the image is animated (e.g. GIF). */
|
|
70
|
+
animated?: boolean; /** The crop region applied to the image. */
|
|
71
|
+
crop?: Crop; /** The image quality, as a percentage from 0 to 100. */
|
|
72
|
+
quality?: number; /** The image alt text for accessibility. */
|
|
73
|
+
alt?: string;
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region ../../node_modules/@wix/editor-react-types/dist/base.d.ts
|
|
77
|
+
/**
|
|
78
|
+
* Rich text content with resolved links.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```tsx
|
|
82
|
+
* import type { RichText } from '@wix/editor-react-types';
|
|
83
|
+
*
|
|
84
|
+
* interface MyComponentProps {
|
|
85
|
+
* description?: RichText;
|
|
86
|
+
* }
|
|
87
|
+
*
|
|
88
|
+
* const MyComponent = ({ description }: MyComponentProps) => (
|
|
89
|
+
* <div>
|
|
90
|
+
* {description?.html}
|
|
91
|
+
* {description?.linkList.map((link) => (
|
|
92
|
+
* <a key={link.href} href={link.href}>{link.href}</a>
|
|
93
|
+
* ))}
|
|
94
|
+
* </div>
|
|
95
|
+
* );
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
type RichText = {
|
|
99
|
+
/** The original rich text content. */text: string; /** The HTML content with all links resolved. */
|
|
100
|
+
html: string; /** All links present in the rich text content. */
|
|
101
|
+
linkList: Array<Link>;
|
|
102
|
+
};
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region ../../node_modules/type-fest/source/observable-like.d.ts
|
|
105
|
+
declare global {
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
107
|
+
interface SymbolConstructor {
|
|
108
|
+
readonly observable: symbol;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
@remarks
|
|
113
|
+
The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021.
|
|
114
|
+
As well, some guidance on making an `Observable` to not include `closed` property.
|
|
115
|
+
@see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
|
|
116
|
+
@see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
|
|
117
|
+
@see https://github.com/benlesh/symbol-observable#making-an-object-observable
|
|
118
|
+
|
|
119
|
+
@category Observable
|
|
120
|
+
*/
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region ../../node_modules/@wix/sdk-types/build/index.d.ts
|
|
123
|
+
declare global {
|
|
124
|
+
interface ContextualClient {}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Creates concrete types from SDK descriptors when a contextual client is
|
|
128
|
+
* available.
|
|
129
|
+
*
|
|
130
|
+
* For a REST descriptor the built (bound) API is intersected with the original
|
|
131
|
+
* descriptor, matching what `contextualizeRESTModuleV2` returns at runtime — a
|
|
132
|
+
* value callable as the bound API and still usable as a descriptor. Keeping the
|
|
133
|
+
* descriptor half lets contextual modules be passed to descriptor-constrained
|
|
134
|
+
* helpers such as `elevate` from `@wix/sdk/context` (FEDINF-14092).
|
|
135
|
+
*
|
|
136
|
+
* The `& T` is scoped to REST descriptors — the only shape codegen wraps in
|
|
137
|
+
* `MaybeContext` — so `BuildDescriptors` (used by `createClient().use`) is left
|
|
138
|
+
* unchanged and stays bound-only. The fix lives here rather than in `elevate`,
|
|
139
|
+
* which is kept strict on purpose (see #941) so it still rejects bound-only
|
|
140
|
+
* functions that are unsafe through `createRESTModule`.
|
|
141
|
+
*/
|
|
142
|
+
declare global {
|
|
143
|
+
/**
|
|
144
|
+
* A global interface to set the exposure toggle for the SDK.
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* declare global {
|
|
148
|
+
* interface SDKExposureToggle {
|
|
149
|
+
* alpha: true;
|
|
150
|
+
* }
|
|
151
|
+
* }
|
|
152
|
+
*/
|
|
153
|
+
interface SDKExposureToggle {}
|
|
154
|
+
}
|
|
155
|
+
declare global {
|
|
156
|
+
/**
|
|
157
|
+
* A global interface to set the type mode for the SDK.
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* declare global {
|
|
161
|
+
* interface SDKTypeMode {
|
|
162
|
+
* strict: true;
|
|
163
|
+
* }
|
|
164
|
+
* }
|
|
165
|
+
*/
|
|
166
|
+
interface SDKTypeMode {}
|
|
167
|
+
}
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/lib/parse-post-cover-media.d.ts
|
|
170
|
+
/** Playable file of a cover video uploaded to Wix. */
|
|
171
|
+
interface VideoSource {
|
|
172
|
+
/** URL of the video file. */
|
|
173
|
+
url: string;
|
|
174
|
+
/** Width of the video, in pixels. `undefined` when it isn't known. */
|
|
175
|
+
width?: number;
|
|
176
|
+
/** Height of the video, in pixels. `undefined` when it isn't known. */
|
|
177
|
+
height?: number;
|
|
178
|
+
}
|
|
179
|
+
/** Site that hosts an embedded cover video. */
|
|
180
|
+
type EmbedProvider =
|
|
181
|
+
/**
|
|
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.
|
|
194
|
+
*/
|
|
195
|
+
type CoverMedia = {
|
|
196
|
+
/** Image cover. */kind: 'image'; /** Cover image, with its URL, size, and alt text. */
|
|
197
|
+
image: Image;
|
|
198
|
+
} | {
|
|
199
|
+
/** Cover video uploaded to Wix. */kind: 'wixVideo'; /** Video ID. */
|
|
200
|
+
id: string;
|
|
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. */
|
|
208
|
+
posterHeight?: number;
|
|
209
|
+
/**
|
|
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.
|
|
213
|
+
*/
|
|
214
|
+
sources: VideoSource[]; /** Alt text for the cover. The post's title when the cover has no alt text. */
|
|
215
|
+
altText: string;
|
|
216
|
+
} | {
|
|
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
|
+
*/
|
|
225
|
+
embedUrl?: string;
|
|
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. */
|
|
234
|
+
altText: string;
|
|
235
|
+
};
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/extensions/post-list-context-provider/utils.d.ts
|
|
238
|
+
/** Post with its fields ready to show in a repeater item. */
|
|
239
|
+
interface PostListItem {
|
|
240
|
+
/** Post ID. */
|
|
241
|
+
_id: string;
|
|
242
|
+
/** Post's title, as plain text. */
|
|
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
|
+
*/
|
|
248
|
+
itemTitle: RichText;
|
|
249
|
+
/** Post's excerpt, as rich text. Empty when the post has no excerpt. */
|
|
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
|
+
*/
|
|
260
|
+
itemCoverImage: Image | undefined;
|
|
261
|
+
/**
|
|
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.
|
|
266
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
280
|
+
itemPublishedDate: RichText;
|
|
281
|
+
/**
|
|
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.
|
|
286
|
+
*/
|
|
287
|
+
publishedDateValue: string | undefined;
|
|
288
|
+
/**
|
|
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`.
|
|
294
|
+
*/
|
|
295
|
+
clockValue: number;
|
|
296
|
+
/**
|
|
297
|
+
* Estimated reading time, in minutes.
|
|
298
|
+
*
|
|
299
|
+
* `undefined` when the post has no estimate.
|
|
300
|
+
*/
|
|
301
|
+
minutesToReadValue: number | undefined;
|
|
302
|
+
/**
|
|
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.
|
|
307
|
+
*/
|
|
308
|
+
initialViewCount: number | undefined;
|
|
309
|
+
/**
|
|
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.
|
|
314
|
+
*/
|
|
315
|
+
initialCommentCount: number | undefined;
|
|
316
|
+
/** Name of the post's author, as rich text. Empty when the author isn't found. */
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
330
|
+
timeToRead: RichText;
|
|
331
|
+
/**
|
|
332
|
+
* Number of views as rich text in the site's language, such as "1,234 views".
|
|
333
|
+
*
|
|
334
|
+
* Empty when the count wasn't loaded with the post. In the editor, but not in Preview, a
|
|
335
|
+
* sample count instead.
|
|
336
|
+
*/
|
|
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
|
+
*/
|
|
344
|
+
commentCount: RichText;
|
|
345
|
+
/**
|
|
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.
|
|
351
|
+
*/
|
|
352
|
+
itemCategoryLabel: RichText;
|
|
353
|
+
/** Post's title and slug, as plain text. */
|
|
354
|
+
recentPostItem: {
|
|
355
|
+
/** Post's title. */title: string; /** Post's slug, the last part of the post page's URL. */
|
|
356
|
+
slug: string;
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
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.
|
|
362
|
+
*/
|
|
363
|
+
commentingEnabled: boolean | undefined;
|
|
364
|
+
}
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region src/hooks/post-likes.types.d.ts
|
|
367
|
+
interface PostLikes {
|
|
368
|
+
isLiked: boolean;
|
|
369
|
+
/** Server count adjusted by the viewer's optimistic toggle delta. */
|
|
370
|
+
likeCount: number;
|
|
371
|
+
/**
|
|
372
|
+
* False while the fresh like-count read is in flight (always false on SSR) — the
|
|
373
|
+
* Counters widget renders a skeleton instead of a possibly-stale number until it flips.
|
|
374
|
+
* A skipped read (editor, preview, no post id) and a failed read both settle to true
|
|
375
|
+
* with the baked count, so the skeleton never outlives its fetch.
|
|
376
|
+
*/
|
|
377
|
+
isLikeCountLoaded: boolean;
|
|
378
|
+
/**
|
|
379
|
+
* View and comment totals off the same metrics read, `undefined` until it lands (and for
|
|
380
|
+
* good on the editor/preview paths that skip it). Nothing bakes these into SSR HTML, so a
|
|
381
|
+
* consumer must render nothing rather than a zero while they are `undefined`.
|
|
382
|
+
*/
|
|
383
|
+
viewCount: number | undefined;
|
|
384
|
+
commentCount: number | undefined;
|
|
385
|
+
toggleLike: (pointerEvent?: PointerEvent) => Promise<void>;
|
|
386
|
+
/**
|
|
387
|
+
* The same like state, live: updated synchronously, while the fields above update in a
|
|
388
|
+
* transition. Stable identity — publish it on the context value as is.
|
|
389
|
+
*/
|
|
390
|
+
liveLikes: LiveLikes;
|
|
391
|
+
}
|
|
392
|
+
/** What `LiveLikes` reports — the `PostLikes` fields a widget renders. */
|
|
393
|
+
type LiveLikeSnapshot = Pick<PostLikes, 'isLiked' | 'likeCount' | 'isLikeCountLoaded' | 'viewCount' | 'commentCount'>;
|
|
394
|
+
/** The site visitor's like state and the post's counts, without delay. */
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
464
|
+
subscribe(listener: () => void): () => void;
|
|
465
|
+
}
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region src/extensions/post-list-item-context-provider/post-list-item-context-provider.d.ts
|
|
468
|
+
/**
|
|
469
|
+
* The cell's raw item plus its like state, for the Blog widgets that read a cell directly
|
|
470
|
+
* (Comments, Cover Media). Elements bind the Post context this provider publishes, never this.
|
|
471
|
+
*/
|
|
472
|
+
type PostItemContextType = PostListItem & Omit<PostLikes, 'likeCount' | 'viewCount' | 'commentCount'> & {
|
|
473
|
+
/**
|
|
474
|
+
* The raw counters for widgets (Counters reads `likeCountValue`). Named apart
|
|
475
|
+
* from the bindable richText labels `likeCount` / `viewCount` / `commentCount`, which
|
|
476
|
+
* `PostListItem` already carries and this provider overrides once the per-cell metadata
|
|
477
|
+
* read resolves.
|
|
478
|
+
*/
|
|
479
|
+
likeCountValue: number;
|
|
480
|
+
viewCountValue: number | undefined;
|
|
481
|
+
commentCountValue: number | undefined;
|
|
482
|
+
likeCount: RichText;
|
|
483
|
+
viewCount: RichText;
|
|
484
|
+
commentCount: RichText;
|
|
485
|
+
};
|
|
486
|
+
/**
|
|
487
|
+
* Nullable rather than throwing: the hook runs for every element inside the repeater
|
|
488
|
+
* cell, including on the editor stage before the cell is populated.
|
|
489
|
+
*/
|
|
490
|
+
declare function usePostListItemContext(): PostItemContextType | null;
|
|
491
|
+
/** Props accepted by {@link PostItemContextProvider}. */
|
|
492
|
+
interface PostItemContextProviderProps extends React.PropsWithChildren {
|
|
493
|
+
/**
|
|
494
|
+
* The current item of the `postsList` array, injected by the platform per repeater
|
|
495
|
+
* cell (the Post List manifest's `contextImplementor.propKey`). Absent on the editor's
|
|
496
|
+
* unbound template cell — the three-way branch below matches the bookings builder's
|
|
497
|
+
* service-context: item → publish it; no item → render children over nulls (the
|
|
498
|
+
* nullable hook is the "null fields"); this provider has no standalone fetch path.
|
|
499
|
+
*/
|
|
500
|
+
postData?: PostListItem;
|
|
501
|
+
}
|
|
502
|
+
/** Supplies one blog post, injected per repeater cell, to its children. */
|
|
503
|
+
declare function PostItemContextProvider({
|
|
504
|
+
postData,
|
|
505
|
+
children
|
|
506
|
+
}: PostItemContextProviderProps): React.ReactNode;
|
|
507
|
+
|
|
508
|
+
export { PostItemContextProvider, type PostItemContextProviderProps, type PostItemContextType, type PostListItem, PostItemContextProvider as default, usePostListItemContext as usePostItemContext, usePostListItemContext };
|