@openrails/contentkit-ui 0.104.0-rc.1 → 0.104.0-rc.2

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 (210) hide show
  1. package/README.md +6 -6
  2. package/dist/client/beacons.js +4 -1
  3. package/dist/client/beacons.js.map +1 -1
  4. package/dist/client/contents.d.ts +7 -1
  5. package/dist/client/contents.js +8 -0
  6. package/dist/client/contents.js.map +1 -1
  7. package/dist/client/discovery.d.ts +6 -2
  8. package/dist/client/discovery.js +1 -1
  9. package/dist/client/discovery.js.map +1 -1
  10. package/dist/client/generated/routes.d.ts +41 -28
  11. package/dist/client/generated/routes.js +63 -61
  12. package/dist/client/generated/routes.js.map +1 -1
  13. package/dist/client/generated/wire.d.ts +36 -74
  14. package/dist/client/generated/wire.js.map +1 -1
  15. package/dist/client/index.d.ts +1 -1
  16. package/dist/client/media/windows.d.ts +2 -0
  17. package/dist/client/media/windows.js +4 -1
  18. package/dist/client/media/windows.js.map +1 -1
  19. package/dist/client/stats.d.ts +4 -20
  20. package/dist/client/stats.js +0 -11
  21. package/dist/client/stats.js.map +1 -1
  22. package/dist/client/versions.d.ts +8 -6
  23. package/dist/client/versions.js +15 -10
  24. package/dist/client/versions.js.map +1 -1
  25. package/dist/components/admin/bulk-drafts.d.ts +17 -0
  26. package/dist/components/admin/bulk-drafts.js +41 -0
  27. package/dist/components/admin/bulk-drafts.js.map +1 -0
  28. package/dist/components/admin/content-admin.d.ts +1 -1
  29. package/dist/components/admin/content-admin.js.map +1 -1
  30. package/dist/components/admin/content-manager.d.ts +11 -3
  31. package/dist/components/admin/content-manager.js +739 -380
  32. package/dist/components/admin/content-manager.js.map +1 -1
  33. package/dist/components/admin/group-manager.d.ts +8 -3
  34. package/dist/components/admin/group-manager.js +218 -146
  35. package/dist/components/admin/group-manager.js.map +1 -1
  36. package/dist/components/admin/page-notices.d.ts +16 -0
  37. package/dist/components/admin/page-notices.js +113 -0
  38. package/dist/components/admin/page-notices.js.map +1 -0
  39. package/dist/components/admin/page-picker.d.ts +38 -0
  40. package/dist/components/admin/page-picker.js +159 -0
  41. package/dist/components/admin/page-picker.js.map +1 -0
  42. package/dist/components/admin/reader-content-editor.js +537 -500
  43. package/dist/components/admin/reader-content-editor.js.map +1 -1
  44. package/dist/components/admin/reader-manifest.js +181 -179
  45. package/dist/components/admin/reader-manifest.js.map +1 -1
  46. package/dist/components/admin/shell.d.ts +10 -2
  47. package/dist/components/admin/shell.js +114 -42
  48. package/dist/components/admin/shell.js.map +1 -1
  49. package/dist/components/admin/stats-dashboard.d.ts +4 -9
  50. package/dist/components/admin/stats-dashboard.js +300 -202
  51. package/dist/components/admin/stats-dashboard.js.map +1 -1
  52. package/dist/components/admin/upload-queue.d.ts +14 -0
  53. package/dist/components/admin/upload-queue.js +115 -98
  54. package/dist/components/admin/upload-queue.js.map +1 -1
  55. package/dist/components/content/card.d.ts +31 -3
  56. package/dist/components/content/card.js +324 -158
  57. package/dist/components/content/card.js.map +1 -1
  58. package/dist/components/content/daily-releases.js +14 -12
  59. package/dist/components/content/daily-releases.js.map +1 -1
  60. package/dist/components/content/editor-save.js +27 -25
  61. package/dist/components/content/editor-save.js.map +1 -1
  62. package/dist/components/content/editors.js +274 -253
  63. package/dist/components/content/editors.js.map +1 -1
  64. package/dist/components/content/favorites.d.ts +1 -1
  65. package/dist/components/content/favorites.js +36 -22
  66. package/dist/components/content/favorites.js.map +1 -1
  67. package/dist/components/content/grid.d.ts +11 -4
  68. package/dist/components/content/grid.js +52 -43
  69. package/dist/components/content/grid.js.map +1 -1
  70. package/dist/components/content/history.js +83 -63
  71. package/dist/components/content/history.js.map +1 -1
  72. package/dist/components/content/index.d.ts +5 -3
  73. package/dist/components/content/listing.d.ts +14 -3
  74. package/dist/components/content/listing.js +65 -56
  75. package/dist/components/content/listing.js.map +1 -1
  76. package/dist/components/content/offer-fields.js +6 -6
  77. package/dist/components/content/paged-grid.d.ts +10 -0
  78. package/dist/components/content/paged-grid.js +116 -0
  79. package/dist/components/content/paged-grid.js.map +1 -0
  80. package/dist/components/content/pagination.d.ts +19 -0
  81. package/dist/components/content/pagination.js +97 -0
  82. package/dist/components/content/pagination.js.map +1 -0
  83. package/dist/components/content/paywall.d.ts +9 -0
  84. package/dist/components/content/paywall.js +27 -3
  85. package/dist/components/content/paywall.js.map +1 -1
  86. package/dist/components/content/post-list.d.ts +37 -0
  87. package/dist/components/content/post-list.js +203 -0
  88. package/dist/components/content/post-list.js.map +1 -0
  89. package/dist/components/content/reader-settings.d.ts +2 -0
  90. package/dist/components/content/reader-settings.js +1 -1
  91. package/dist/components/content/reader-settings.js.map +1 -1
  92. package/dist/components/groups/banner.d.ts +6 -2
  93. package/dist/components/groups/banner.js +79 -61
  94. package/dist/components/groups/banner.js.map +1 -1
  95. package/dist/components/groups/directory.d.ts +12 -2
  96. package/dist/components/groups/directory.js +168 -105
  97. package/dist/components/groups/directory.js.map +1 -1
  98. package/dist/components/groups/editor.js +10 -10
  99. package/dist/components/groups/editor.js.map +1 -1
  100. package/dist/components/groups/entity-chips.d.ts +61 -0
  101. package/dist/components/groups/entity-chips.js +382 -0
  102. package/dist/components/groups/entity-chips.js.map +1 -0
  103. package/dist/components/groups/group-members.d.ts +29 -0
  104. package/dist/components/groups/group-members.js +474 -0
  105. package/dist/components/groups/group-members.js.map +1 -0
  106. package/dist/components/groups/header.js +53 -45
  107. package/dist/components/groups/header.js.map +1 -1
  108. package/dist/components/groups/index.d.ts +3 -1
  109. package/dist/components/groups/memberships.d.ts +3 -36
  110. package/dist/components/groups/memberships.js +105 -480
  111. package/dist/components/groups/memberships.js.map +1 -1
  112. package/dist/components/groups/scoped.d.ts +23 -0
  113. package/dist/components/groups/scoped.js +92 -0
  114. package/dist/components/groups/scoped.js.map +1 -0
  115. package/dist/components/media-folder-editor.d.ts +5 -0
  116. package/dist/components/media-folder-editor.js +418 -230
  117. package/dist/components/media-folder-editor.js.map +1 -1
  118. package/dist/components/sortable-list.d.ts +5 -1
  119. package/dist/components/sortable-list.js +97 -81
  120. package/dist/components/sortable-list.js.map +1 -1
  121. package/dist/index.d.ts +1 -1
  122. package/dist/index.js +41 -37
  123. package/dist/locales/admin/de.js +78 -45
  124. package/dist/locales/admin/de.js.map +1 -1
  125. package/dist/locales/admin/en.d.ts +74 -41
  126. package/dist/locales/admin/en.js +78 -45
  127. package/dist/locales/admin/en.js.map +1 -1
  128. package/dist/locales/admin/es.js +78 -45
  129. package/dist/locales/admin/es.js.map +1 -1
  130. package/dist/locales/admin/ja.js +78 -45
  131. package/dist/locales/admin/ja.js.map +1 -1
  132. package/dist/locales/admin/ko.js +78 -45
  133. package/dist/locales/admin/ko.js.map +1 -1
  134. package/dist/locales/admin/zh.js +78 -45
  135. package/dist/locales/admin/zh.js.map +1 -1
  136. package/dist/locales/de.js +1 -0
  137. package/dist/locales/de.js.map +1 -1
  138. package/dist/locales/discovery/de.js +25 -1
  139. package/dist/locales/discovery/de.js.map +1 -1
  140. package/dist/locales/discovery/en.d.ts +24 -0
  141. package/dist/locales/discovery/en.js +25 -1
  142. package/dist/locales/discovery/en.js.map +1 -1
  143. package/dist/locales/discovery/es.js +25 -1
  144. package/dist/locales/discovery/es.js.map +1 -1
  145. package/dist/locales/discovery/ja.js +25 -1
  146. package/dist/locales/discovery/ja.js.map +1 -1
  147. package/dist/locales/discovery/ko.js +25 -1
  148. package/dist/locales/discovery/ko.js.map +1 -1
  149. package/dist/locales/discovery/zh.js +25 -1
  150. package/dist/locales/discovery/zh.js.map +1 -1
  151. package/dist/locales/en.d.ts +119 -43
  152. package/dist/locales/en.js +1 -0
  153. package/dist/locales/en.js.map +1 -1
  154. package/dist/locales/es.js +1 -0
  155. package/dist/locales/es.js.map +1 -1
  156. package/dist/locales/groups/de.js +22 -4
  157. package/dist/locales/groups/de.js.map +1 -1
  158. package/dist/locales/groups/en.d.ts +20 -2
  159. package/dist/locales/groups/en.js +22 -4
  160. package/dist/locales/groups/en.js.map +1 -1
  161. package/dist/locales/groups/es.js +22 -4
  162. package/dist/locales/groups/es.js.map +1 -1
  163. package/dist/locales/groups/ja.js +22 -4
  164. package/dist/locales/groups/ja.js.map +1 -1
  165. package/dist/locales/groups/ko.js +22 -4
  166. package/dist/locales/groups/ko.js.map +1 -1
  167. package/dist/locales/groups/zh.js +22 -4
  168. package/dist/locales/groups/zh.js.map +1 -1
  169. package/dist/locales/ja.js +1 -0
  170. package/dist/locales/ja.js.map +1 -1
  171. package/dist/locales/ko.js +1 -0
  172. package/dist/locales/ko.js.map +1 -1
  173. package/dist/locales/zh.js +1 -0
  174. package/dist/locales/zh.js.map +1 -1
  175. package/dist/react/discovery.d.ts +16 -0
  176. package/dist/react/discovery.js +69 -37
  177. package/dist/react/discovery.js.map +1 -1
  178. package/dist/react/groups.d.ts +19 -3
  179. package/dist/react/groups.js +49 -22
  180. package/dist/react/groups.js.map +1 -1
  181. package/dist/react/index.d.ts +6 -4
  182. package/dist/react/page-notices.d.ts +13 -0
  183. package/dist/react/page-notices.js +38 -0
  184. package/dist/react/page-notices.js.map +1 -0
  185. package/dist/react/post-reads.d.ts +23 -0
  186. package/dist/react/post-reads.js +90 -0
  187. package/dist/react/post-reads.js.map +1 -0
  188. package/dist/react/remembered-sort.d.ts +5 -0
  189. package/dist/react/remembered-sort.js +29 -0
  190. package/dist/react/remembered-sort.js.map +1 -0
  191. package/dist/react/resources.js +2 -2
  192. package/dist/react/resources.js.map +1 -1
  193. package/dist/react/stats.d.ts +3 -7
  194. package/dist/react/stats.js +2 -6
  195. package/dist/react/stats.js.map +1 -1
  196. package/dist/react/use-engagement.d.ts +2 -0
  197. package/dist/react/use-engagement.js +8 -3
  198. package/dist/react/use-engagement.js.map +1 -1
  199. package/dist/react.js +29 -27
  200. package/dist/styles.css +1 -1
  201. package/dist/urls/index.d.ts +1 -1
  202. package/dist/urls.js +2 -2
  203. package/dist/urls.js.map +1 -1
  204. package/package.json +1 -1
  205. package/dist/components/admin/page-review.d.ts +0 -13
  206. package/dist/components/admin/page-review.js +0 -225
  207. package/dist/components/admin/page-review.js.map +0 -1
  208. package/dist/react/page-review.d.ts +0 -14
  209. package/dist/react/page-review.js +0 -37
  210. package/dist/react/page-review.js.map +0 -1
@@ -38,7 +38,39 @@ function T(e, t = {}) {
38
38
  summary: l.metadata
39
39
  };
40
40
  }
41
- function E(e, t = {}) {
41
+ var E = [];
42
+ function D(e, t, n) {
43
+ let { store: r } = a(n.client), i = s(r, e, { type: "cards" }, t);
44
+ return {
45
+ items: i.data?.contents ?? E,
46
+ summary: i.data?.summary,
47
+ loading: i.loading || !!e && !i.loaded,
48
+ error: i.error,
49
+ reload: i.reload
50
+ };
51
+ }
52
+ function O(e, t, n = {}) {
53
+ let { client: r, scope: o } = a(n.client), s = w(e), c = Math.max(1, Math.floor(t));
54
+ return D(s ? i("cards", o, "list-page", s, c) : null, (e) => r.discovery.list({
55
+ ...s,
56
+ cursor: void 0,
57
+ page: c,
58
+ summary: s.summary ?? !0
59
+ }, e), n);
60
+ }
61
+ function k(e, t, n = {}) {
62
+ let { client: r, scope: o, viewer: s } = a(n.client), c = w(e?.q.trim() ? e : null), l = Math.max(1, Math.floor(t)), u = C(r, o);
63
+ return D(c ? i("cards", o, "search-page", c, l) : null, async (e) => {
64
+ let t = await r.discovery.search({
65
+ ...c,
66
+ cursor: void 0,
67
+ page: l,
68
+ summary: c.summary ?? !0
69
+ }, e);
70
+ return l === 1 && s === null && !e.aborted && u() && r.discovery.browserSearches.record(c.q, t.contents.length), t;
71
+ }, n);
72
+ }
73
+ function A(e, t = {}) {
42
74
  let { client: n, store: r, scope: o } = a(t.client), c = w(g(() => {
43
75
  if (!e) return null;
44
76
  let { cursor: t, ...n } = e;
@@ -54,7 +86,7 @@ function E(e, t = {}) {
54
86
  loading: l.loading
55
87
  };
56
88
  }
57
- function D(e, t = {}) {
89
+ function j(e, t = {}) {
58
90
  let { client: n, store: r, scope: s, viewer: c } = a(t.client), l = w(e?.q.trim() ? e : null), u = C(n, s), d = o(r, l ? i("cards", s, "search", l) : null, { type: "cards" }, async (e, t) => {
59
91
  let r = await n.discovery.search({
60
92
  ...l,
@@ -68,7 +100,7 @@ function D(e, t = {}) {
68
100
  summary: d.metadata
69
101
  };
70
102
  }
71
- function O(e, t, n) {
103
+ function M(e, t, n) {
72
104
  let { store: r } = a(n.client), i = s(r, e, { type: "cards" }, t), o = i.error?.code === "not_configured";
73
105
  return {
74
106
  items: i.data?.contents ?? [],
@@ -79,15 +111,15 @@ function O(e, t, n) {
79
111
  reload: i.reload
80
112
  };
81
113
  }
82
- function k(e, t = {}, n = {}) {
114
+ function N(e, t = {}, n = {}) {
83
115
  let { client: r, scope: o } = a(n.client), s = w(t);
84
- return O(e ? i("cards", o, "similar", e, s) : null, (t) => r.discovery.similar(e, s, t), n);
116
+ return M(e ? i("cards", o, "similar", e, s) : null, (t) => r.discovery.similar(e, s, t), n);
85
117
  }
86
- function A(e = {}, t = {}) {
118
+ function P(e = {}, t = {}) {
87
119
  let { client: n, scope: r, viewer: o } = a(t.client), s = w(e);
88
- return O(o === null || !s ? null : i("cards", r, "recommended", s), (e) => n.discovery.recommendations(s, e), t);
120
+ return M(o === null || !s ? null : i("cards", r, "recommended", s), (e) => n.discovery.recommendations(s, e), t);
89
121
  }
90
- function j(e = {}, t = {}) {
122
+ function F(e = {}, t = {}) {
91
123
  let { client: n, store: r, scope: s } = a(t.client), c = w(e);
92
124
  return o(r, i("release-dates", s, c), { type: "release-dates" }, async (e, t) => {
93
125
  let r = await n.discovery.releaseDates({
@@ -103,7 +135,7 @@ function j(e = {}, t = {}) {
103
135
  };
104
136
  });
105
137
  }
106
- function M(e = {}, t = {}) {
138
+ function I(e = {}, t = {}) {
107
139
  let { client: n, store: r, scope: o } = a(t.client), c = w(e), l = s(r, c ? i("daily-releases", o, c) : null, { type: "daily-releases" }, (e) => n.discovery.releases(c, e));
108
140
  return {
109
141
  data: l.data,
@@ -112,7 +144,7 @@ function M(e = {}, t = {}) {
112
144
  reload: l.reload
113
145
  };
114
146
  }
115
- function N(e = {}, t = {}) {
147
+ function L(e = {}, t = {}) {
116
148
  let { client: n, store: s, scope: l, viewer: u } = a(t.client), d = w(e), p = r(), m = u === null, h = C(n, l), _ = n.guestHistory, v = d !== null, x = f((e) => m && v ? _.subscribe(e) : () => {}, [
117
149
  _,
118
150
  m,
@@ -177,7 +209,7 @@ function N(e = {}, t = {}) {
177
209
  forget: A
178
210
  };
179
211
  }
180
- function P(e = {}) {
212
+ function R(e = {}) {
181
213
  let { client: t, store: n, scope: o, viewer: c } = a(e.client), u = r(), d = C(t, o), p = c === null, h = e.enabled !== !1, _ = t.discovery.browserSearches, v = f((e) => p && h ? _.subscribe(e) : () => {}, [
182
214
  _,
183
215
  p,
@@ -226,7 +258,7 @@ function P(e = {}) {
226
258
  clear: D
227
259
  };
228
260
  }
229
- var F = (e) => ({
261
+ var z = (e) => ({
230
262
  items: e.items.map((e) => ({
231
263
  ...e,
232
264
  id: e.content?.id ?? e.entity?.id ?? ""
@@ -234,8 +266,8 @@ var F = (e) => ({
234
266
  next: e.next_cursor ?? null,
235
267
  metadata: e.summary
236
268
  });
237
- function I(e = {}, t = {}) {
238
- let { client: n, store: r, scope: s, viewer: c } = a(t.client), l = w(e), u = o(r, c === null ? null : i("favorites", s, l), { type: "favorites" }, async (e, t) => F(await n.favorites.mine({
269
+ function B(e = {}, t = {}) {
270
+ let { client: n, store: r, scope: s, viewer: c } = a(t.client), l = w(e), u = o(r, c === null ? null : i("favorites", s, l), { type: "favorites" }, async (e, t) => z(await n.favorites.mine({
239
271
  ...l,
240
272
  cursor: e,
241
273
  summary: e ? void 0 : l.summary
@@ -245,8 +277,8 @@ function I(e = {}, t = {}) {
245
277
  summary: u.metadata
246
278
  };
247
279
  }
248
- function L(e = {}, t = {}) {
249
- let { client: n, store: r, scope: s, viewer: c } = a(t.client), l = w(e), u = o(r, c === null ? null : i("reactions", s, l), { type: "reactions" }, async (e, t) => F(await n.reactions.mine({
280
+ function V(e = {}, t = {}) {
281
+ let { client: n, store: r, scope: s, viewer: c } = a(t.client), l = w(e), u = o(r, c === null ? null : i("reactions", s, l), { type: "reactions" }, async (e, t) => z(await n.reactions.mine({
250
282
  ...l,
251
283
  cursor: e,
252
284
  summary: e ? void 0 : l.summary
@@ -256,7 +288,7 @@ function L(e = {}, t = {}) {
256
288
  summary: u.metadata
257
289
  };
258
290
  }
259
- function R(t = {}) {
291
+ function H(t = {}) {
260
292
  let { client: n, store: o, scope: c, viewer: l, language: u } = a(t.client), d = t.language ?? u, p = l === null, h = n.preferences.browser, b = y(h.subscribe, h.snapshot, h.snapshot), x = i("content-filters", c, d), S = _(null), w = p && S.current?.guest && S.current.client === n && S.current.language === d ? S.current.data : void 0, T = s(o, x, { type: "content-filters" }, (e) => n.discovery.contentFilters(d, e), { initial: w });
261
293
  S.current = {
262
294
  client: n,
@@ -353,11 +385,11 @@ function R(t = {}) {
353
385
  setIncludeDeleted: F
354
386
  };
355
387
  }
356
- var z = {
388
+ var U = {
357
389
  contents: [],
358
390
  entities: []
359
391
  };
360
- function B(e, n = {}) {
392
+ function W(e, n = {}) {
361
393
  let { client: r, language: i, scope: o } = a(n.client), { debounce: s = 150, minLength: c = 1, client: l, management: u = !1, request: d, ...f } = n, p = g(() => ({
362
394
  viewerScope: o,
363
395
  management: u,
@@ -375,7 +407,7 @@ function B(e, n = {}) {
375
407
  h,
376
408
  JSON.stringify(f)
377
409
  ]), [y, b] = v({
378
- ...z,
410
+ ...U,
379
411
  query: "",
380
412
  loading: !1,
381
413
  scope: p
@@ -383,7 +415,7 @@ function B(e, n = {}) {
383
415
  return m(() => {
384
416
  if (h.length < c) {
385
417
  b({
386
- ...z,
418
+ ...U,
387
419
  query: "",
388
420
  loading: !1,
389
421
  scope: p
@@ -392,7 +424,7 @@ function B(e, n = {}) {
392
424
  }
393
425
  b((e) => ({
394
426
  ...e.scope === p ? e : {
395
- ...z,
427
+ ...U,
396
428
  query: ""
397
429
  },
398
430
  loading: !0,
@@ -418,7 +450,7 @@ function B(e, n = {}) {
418
450
  }, (n) => {
419
451
  let r = t(n);
420
452
  !e.signal.aborted && r.code !== "aborted" && b({
421
- ...z,
453
+ ...U,
422
454
  query: h,
423
455
  loading: !1,
424
456
  error: r,
@@ -439,22 +471,22 @@ function B(e, n = {}) {
439
471
  d,
440
472
  p
441
473
  ]), y.scope === p ? y : {
442
- ...z,
474
+ ...U,
443
475
  query: "",
444
476
  loading: h.length >= c
445
477
  };
446
478
  }
447
- var V = /* @__PURE__ */ new WeakMap();
448
- function H(e, t) {
449
- let n = V.get(e);
450
- return n || V.set(e, n = new u(e, t)), n;
479
+ var G = /* @__PURE__ */ new WeakMap();
480
+ function K(e, t) {
481
+ let n = G.get(e);
482
+ return n || G.set(e, n = new u(e, t)), n;
451
483
  }
452
- function U(e = {}) {
484
+ function q(e = {}) {
453
485
  let { client: t } = a(e.client);
454
- return H(t);
486
+ return K(t);
455
487
  }
456
- function W(e, t) {
457
- let { client: n, scope: r, language: i } = a(t.client), o = H(n), s = C(n, r), c = g(() => d(), [t.render, r]), l = g(() => ({
488
+ function J(e, t) {
489
+ let { client: n, scope: r, language: i } = a(t.client), o = K(n), s = C(n, r), c = g(() => d(), [t.render, r]), l = g(() => ({
458
490
  surface: t.surface,
459
491
  ranker: t.ranker,
460
492
  query_id: t.query_id,
@@ -482,7 +514,7 @@ function W(e, t) {
482
514
  if (!s()) return;
483
515
  let t = /* @__PURE__ */ new Set();
484
516
  for (let [n, r] of e.entries()) {
485
- let e = r.position, i = e !== void 0 && Number.isSafeInteger(e) && e > 0 ? e : n + 1, a = Math.floor((i - 1) / G), o = h(a);
517
+ let e = r.position, i = e !== void 0 && Number.isSafeInteger(e) && e > 0 ? e : n + 1, a = Math.floor((i - 1) / Y), o = h(a);
486
518
  o.rendered.has(r.id) || (o.rendered.set(r.id, {
487
519
  content_id: r.id,
488
520
  version_id: r.version_id ?? r.version?.id,
@@ -513,7 +545,7 @@ function W(e, t) {
513
545
  if (s()) {
514
546
  for (let t of e) {
515
547
  if (!t.isIntersecting) continue;
516
- let e = t.target, n = e.dataset.exposureContent, r = Number(e.dataset.exposurePosition), i = Math.floor((r - 1) / G), a = h(i);
548
+ let e = t.target, n = e.dataset.exposureContent, r = Number(e.dataset.exposurePosition), i = Math.floor((r - 1) / Y), a = h(i);
517
549
  a.visible.has(n) || (a.visible.set(n, a.rendered.get(n) ?? {
518
550
  content_id: n,
519
551
  position: r
@@ -562,7 +594,7 @@ function W(e, t) {
562
594
  }, [_]),
563
595
  click: f((n, r) => {
564
596
  if (!s()) return;
565
- let i = Math.floor((r - 1) / G), a = e.find((e) => e.id === n), c = a?.version_id ?? a?.version?.id;
597
+ let i = Math.floor((r - 1) / Y), a = e.find((e) => e.id === n), c = a?.version_id ?? a?.version?.id;
566
598
  o.click(n, {
567
599
  render_id: p(i),
568
600
  surface: t.surface,
@@ -580,8 +612,8 @@ function W(e, t) {
580
612
  ])
581
613
  };
582
614
  }
583
- var G = 32;
615
+ var Y = 32;
584
616
  //#endregion
585
- export { H as beaconsFor, U as useBeacons, R as useContentFilters, T as useContents, M as useDailyReleases, W as useExposure, N as useHistory, E as useLockedCount, I as useMyFavorites, L as useMyReactions, P as useRecentSearches, A as useRecommendations, j as useReleaseDates, D as useSearch, k as useSimilar, B as useTypeahead };
617
+ export { K as beaconsFor, q as useBeacons, H as useContentFilters, T as useContents, O as useContentsPage, I as useDailyReleases, J as useExposure, L as useHistory, A as useLockedCount, B as useMyFavorites, V as useMyReactions, R as useRecentSearches, P as useRecommendations, F as useReleaseDates, j as useSearch, k as useSearchPage, N as useSimilar, W as useTypeahead };
586
618
 
587
619
  //# sourceMappingURL=discovery.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.js","names":[],"sources":["../../src/react/discovery.ts"],"sourcesContent":["import { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from \"react\";\nimport { Beacons, eventId, type BeaconOptions } from \"../client/beacons.js\";\nimport type { ContentKitClient } from \"../client/client.js\";\nimport type { MineQuery } from \"../client/content/favorites.js\";\nimport type { ContentQuery, DailyReleasesQuery, HistoryQuery, RailQuery, ReleaseDatesQuery, SearchQuery, TypeaheadQuery } from \"../client/discovery.js\";\nimport { ContentKitError, toContentKitError } from \"../client/errors.js\";\nimport type { Card, ContentFilters, ContentFiltersUpdate, ContentPage, DailyReleases, DateCount, GroupCard, Interaction, InteractionPage, RecentSearch, Typeahead } from \"../client/generated/wire.js\";\nimport { ContentKitContext, useGuarded } from \"./context.js\";\nimport { keyOf, useContentScope, useList, useResource, type UseList } from \"./use-resource.js\";\nimport { guestStanding, type GuestReadingItem } from \"../client/guest-reading-history.js\";\nimport { recentSearchLimit } from \"../client/browser-search-history.js\";\n\nconst page = (p: ContentPage) => ({ items: p.contents, next: p.next_cursor ?? null, metadata: p.summary });\nexport interface UseContents extends UseList<Card, ContentPage[\"summary\"]> { summary?: ContentPage[\"summary\"] }\nconst NO_SEARCHES: RecentSearch[] = [];\nconst NO_READING: readonly GuestReadingItem[] = Object.freeze([]);\n\n// A new identity even after A → B → A, so late requests cannot write into the new visit.\nfunction useCurrentDiscoveryScope(client: ContentKitClient, scope: string): () => boolean {\n const owner = useMemo(() => ({ client, scope }), [client, scope]);\n const current = useRef<typeof owner | null>(owner);\n useLayoutEffect(() => {\n current.current = owner;\n return () => { current.current = null; };\n }, [owner]);\n return useCallback(() => current.current === owner, [owner]);\n}\n\n/** Titles, names and paths in the provider's language unless the query says otherwise. */\nfunction useDisplay<T extends { display_language?: string }>(q: T | null): T | null {\n const language = useContext(ContentKitContext)?.language;\n return useMemo(() => (q && !q.display_language && language ? { ...q, display_language: language } : q), [q, language]);\n}\n\n/** Contents as cards, a cursor page at a time; null reads nothing. */\nexport function useContents(q: ContentQuery | null, o: { client?: ContentKitClient } = {}): UseContents {\n const { client, store, scope } = useContentScope(o.client);\n const query = useDisplay(q);\n const list = useList(store, query ? keyOf(\"cards\", scope, \"list\", query) : null, { type: \"cards\" }, async (cursor, signal) =>\n page(await client.discovery.list({ ...query, cursor: cursor as string | undefined, summary: cursor ? undefined : query?.summary }, signal)),\n );\n return { ...list, summary: list.metadata };\n}\n\n/** Locked contents in the same full selection, including its activity window. */\nexport function useLockedCount(q: ContentQuery | null, o: { client?: ContentKitClient } = {}): { count?: number; loading: boolean } {\n const { client, store, scope } = useContentScope(o.client);\n const filter = useMemo(() => {\n if (!q) return null;\n const { cursor: _cursor, ...rest } = q;\n return { ...rest, mode: \"lock\" as const, limit: 1, summary: true };\n }, [q]);\n const query = useDisplay(filter);\n const r = useResource<number>(store, query ? keyOf(\"cards\", scope, \"locked-summary\", query) : null, { type: \"cards\" }, async (signal) => {\n const out = await client.discovery.list(query!, signal);\n return out.summary?.locked_count ?? 0;\n });\n return { count: r.data, loading: r.loading };\n}\n\n/** Keyword search results as cards; nothing while q.q is empty. */\nexport function useSearch(q: SearchQuery | null, o: { client?: ContentKitClient } = {}): UseContents {\n const { client, store, scope, viewer } = useContentScope(o.client);\n const query = useDisplay(q?.q.trim() ? q : null);\n const isCurrent = useCurrentDiscoveryScope(client, scope);\n const list = useList(store, query ? keyOf(\"cards\", scope, \"search\", query) : null, { type: \"cards\" }, async (cursor, signal) => {\n const out = await client.discovery.search({ ...query!, cursor: cursor as string | undefined, summary: cursor ? undefined : query?.summary }, signal);\n if (!cursor && viewer === null && !signal.aborted && isCurrent()) client.discovery.browserSearches.record(query!.q, out.contents.length);\n return page(out);\n });\n return { ...list, summary: list.metadata };\n}\n\nexport interface UseRail {\n items: Card[];\n summary?: ContentPage[\"summary\"];\n loading: boolean;\n error?: ContentKitError;\n /** The site runs without the signal plane (not_configured): leave the rail out. */\n unavailable: boolean;\n reload: () => void;\n}\n\nfunction useRail(key: string | null, fetch: (signal: AbortSignal) => Promise<ContentPage>, o: { client?: ContentKitClient }): UseRail {\n const { store } = useContentScope(o.client);\n const r = useResource<ContentPage>(store, key, { type: \"cards\" }, fetch);\n const unavailable = r.error?.code === \"not_configured\";\n return { items: r.data?.contents ?? [], summary: r.data?.summary, loading: !!key && (r.loading || !r.loaded), error: unavailable ? undefined : r.error, unavailable, reload: r.reload };\n}\n\n/** Contents like one: co-engagement, or the site's configured source. */\nexport function useSimilar(id: string | null | undefined, q: RailQuery = {}, o: { client?: ContentKitClient } = {}): UseRail {\n const { client, scope } = useContentScope(o.client);\n const query = useDisplay(q)!;\n return useRail(id ? keyOf(\"cards\", scope, \"similar\", id, query) : null, (s) => client.discovery.similar(id!, query, s), o);\n}\n\n/** Contents for the signed-in reader; nothing signed out, or when q is null. */\nexport function useRecommendations(q: RailQuery | null = {}, o: { client?: ContentKitClient } = {}): UseRail {\n const { client, scope, viewer } = useContentScope(o.client);\n const query = useDisplay(q);\n return useRail(viewer === null || !query ? null : keyOf(\"cards\", scope, \"recommended\", query), (s) => client.discovery.recommendations(query!, s), o);\n}\n\n/** A release date bucket, keyed by its date. */\nexport type ReleaseDate = DateCount & { id: string };\n\n/** The release date index: per month or day, newest first. */\nexport function useReleaseDates(q: ReleaseDatesQuery = {}, o: { client?: ContentKitClient } = {}): UseList<ReleaseDate> {\n const { client, store, scope } = useContentScope(o.client);\n const query = useDisplay(q)!;\n return useList(store, keyOf(\"release-dates\", scope, query), { type: \"release-dates\" }, async (cursor, signal) => {\n const r = await client.discovery.releaseDates({ ...query, cursor: cursor as string | undefined }, signal);\n return { items: r.dates.map((d) => ({ ...d, id: d.date })), next: r.next_cursor ?? null };\n });\n}\n\nexport interface UseDailyReleases {\n data?: DailyReleases;\n loading: boolean;\n error?: ContentKitError;\n reload: () => void;\n}\n\n/** One complete calendar window, shared by all readers of the same query. */\nexport function useDailyReleases(q: DailyReleasesQuery | null = {}, o: { client?: ContentKitClient } = {}): UseDailyReleases {\n const { client, store, scope } = useContentScope(o.client);\n const query = useDisplay(q);\n const r = useResource<DailyReleases>(store, query ? keyOf(\"daily-releases\", scope, query) : null, { type: \"daily-releases\" }, (signal) => client.discovery.releases(query!, signal));\n return { data: r.data, loading: !!query && (r.loading || !r.loaded), error: r.error, reload: r.reload };\n}\n\nexport interface UseHistory extends UseContents {\n /** A status-filtered guest selection has hidden candidates whose current version facts cannot be inspected. */\n filterSummaryUnknown?: boolean;\n /** Erases the reader's history: of one content item, one kind, or (no argument) everything. */\n forget: (o?: { kind?: string; content_id?: string }) => Promise<void>;\n}\n\n/** Account history is authoritative; signed-out reading stays in this browser across tabs. */\nexport function useHistory(q: HistoryQuery | null = {}, o: { client?: ContentKitClient } = {}): UseHistory {\n const { client, store, scope, viewer } = useContentScope(o.client);\n const query = useDisplay(q);\n const guarded = useGuarded();\n const guest = viewer === null;\n const isCurrent = useCurrentDiscoveryScope(client, scope);\n const browser = client.guestHistory;\n const enabled = query !== null;\n const subscribe = useCallback((listener: () => void) => guest && enabled ? browser.subscribe(listener) : () => {}, [browser, guest, enabled]);\n const snapshot = useCallback(() => guest && enabled ? browser.snapshot() : NO_READING, [browser, guest, enabled]);\n const local = useSyncExternalStore(subscribe, snapshot, () => NO_READING);\n const selected = useMemo(() => local.filter(row => !query?.kind || row.kind === query.kind).slice(0, 100), [local, query?.kind]);\n const localRevision = guest ? selected.map(row => [row.id, row.at, row.checkpoints.map(checkpoint => [checkpoint.visit_id, checkpoint.segment_id, checkpoint.revision])]) : undefined;\n const list = useList(store, !query || viewer === undefined ? null : keyOf(\"history\", scope, query, localRevision), { type: \"history\" }, async (cursor, signal) => {\n if (!guest) return page(await client.discovery.history({ ...query, cursor: cursor as string | undefined, summary: cursor ? undefined : query?.summary }, signal));\n const offset = typeof cursor === \"number\" ? cursor : 0;\n const limit = Math.max(1, Math.min(100, query?.limit ?? 50));\n const batch = selected.slice(offset, offset + limit);\n if (!batch.length) return { items: [], next: null };\n // Public hydration enforces current hard-domain rules, access and optional preferences.\n const out = await client.discovery.list({ ids: (query?.summary && !cursor ? selected : batch).map(row => row.id), summary: !cursor ? query?.summary : undefined, kind: query?.kind, language: query?.language,\n display_language: query?.display_language, mode: query?.mode, card_entities: query?.card_entities, limit: 100 }, signal);\n const cards = new Map(out.contents.map(card => [card.id, card]));\n const items = batch.flatMap(row => {\n const card = cards.get(row.id); if (!card) return [];\n const viewer = guestStanding(card, row);\n if (query?.status === \"seen\" && !viewer.seen || query?.status === \"in_progress\" && (!viewer.seen || viewer.completed) || query?.status === \"completed\" && !viewer.completed) return [];\n return [{ ...card, viewer }];\n });\n return { items, next: offset + batch.length < selected.length ? offset + batch.length : null, metadata: out.summary };\n });\n const forget = useCallback((filter: { kind?: string; content_id?: string } = {}) => {\n if (!isCurrent()) return Promise.resolve();\n if (guest) { browser.clear(filter); return Promise.resolve(); }\n return guarded(() => client.discovery.forgetHistory(filter));\n }, [browser, client, guest, guarded, isCurrent]);\n const uncertain = guest && !!query?.status;\n return { ...list, summary: uncertain ? undefined : list.metadata, filterSummaryUnknown: uncertain && (list.metadata?.filtered_count ?? 0) > 0, forget };\n}\n\nexport interface UseRecentSearches {\n searches: RecentSearch[];\n loading: boolean;\n error?: ContentKitError;\n /** Clears one query, or every recent search. */\n clear: (query?: string) => Promise<void>;\n}\n\n/** Guest history stays in this browser; account history comes only from the server. enabled false reads nothing yet. */\nexport function useRecentSearches(o: { limit?: number; enabled?: boolean; client?: ContentKitClient } = {}): UseRecentSearches {\n const { client, store, scope, viewer } = useContentScope(o.client);\n const guarded = useGuarded();\n const isCurrent = useCurrentDiscoveryScope(client, scope);\n const guest = viewer === null;\n const enabled = o.enabled !== false;\n const browser = client.discovery.browserSearches;\n const subscribe = useCallback((listener: () => void) => guest && enabled ? browser.subscribe(listener) : () => {}, [browser, guest, enabled]);\n const snapshot = useCallback(() => guest && enabled ? browser.snapshot() : NO_SEARCHES, [browser, guest, enabled]);\n const local = useSyncExternalStore(subscribe, snapshot, () => NO_SEARCHES);\n const searches = useMemo(() => local.slice(0, recentSearchLimit(o.limit)), [local, o.limit]);\n const key = !enabled || guest ? null : keyOf(\"searches\", scope, o.limit ?? 10);\n const r = useResource<RecentSearch[]>(store, key, { type: \"searches\" }, async (s) => (await client.discovery.recentSearches({ limit: o.limit }, s)).searches);\n useEffect(() => {\n if (!key) return;\n const reload = () => { if (!store.snapshot(key).loading) store.load(key, true); };\n // Reopening a panel must not leave an already-cached account list stale.\n if (store.snapshot(key).loaded) reload();\n const visible = () => { if (document.visibilityState === \"visible\") reload(); };\n if (typeof window !== \"undefined\") window.addEventListener(\"focus\", reload);\n if (typeof document !== \"undefined\") document.addEventListener(\"visibilitychange\", visible);\n return () => {\n if (typeof window !== \"undefined\") window.removeEventListener(\"focus\", reload);\n if (typeof document !== \"undefined\") document.removeEventListener(\"visibilitychange\", visible);\n };\n }, [key, store]);\n const clear = useCallback(async (query?: string) => {\n if (!isCurrent()) return;\n if (guest) { browser.clear(query); return; }\n await guarded(() => isCurrent() ? client.discovery.clearSearches(query ? { query } : {}) : Promise.resolve());\n }, [browser, client, guest, guarded, isCurrent]);\n return guest\n ? { searches: enabled ? searches : NO_SEARCHES, loading: false, clear }\n : { searches: r.data ?? NO_SEARCHES, loading: !!key && (r.loading || !r.loaded), error: r.error, clear };\n}\n\n/** A favorite or reaction with its content's or group's id. */\nexport type MyInteraction = Interaction & { id: string };\n\nconst interactions = (p: InteractionPage) => ({ items: p.items.map((x) => ({ ...x, id: x.content?.id ?? x.entity?.id ?? \"\" })), next: p.next_cursor ?? null, metadata: p.summary });\n\nexport interface UseInteractions extends UseList<MyInteraction, InteractionPage[\"summary\"]> { summary?: InteractionPage[\"summary\"] }\n\n/** The signed-in reader's favorites, most recent first: content cards or groups. */\nexport function useMyFavorites(q: MineQuery = {}, o: { client?: ContentKitClient } = {}): UseInteractions {\n const { client, store, scope, viewer } = useContentScope(o.client);\n const query = useDisplay(q)!;\n const list = useList(store, viewer === null ? null : keyOf(\"favorites\", scope, query), { type: \"favorites\" }, async (cursor, signal) =>\n interactions(await client.favorites.mine({ ...query, cursor: cursor as string | undefined, summary: cursor ? undefined : query.summary }, signal)),\n );\n return { ...list, summary: list.metadata };\n}\n\n/** What the signed-in reader liked (or, with value, disliked), most recent first. */\nexport function useMyReactions(q: MineQuery & { value?: \"like\" | \"dislike\" } = {}, o: { client?: ContentKitClient } = {}): UseInteractions {\n const { client, store, scope, viewer } = useContentScope(o.client);\n const query = useDisplay(q)!;\n const list = useList(store, viewer === null ? null : keyOf(\"reactions\", scope, query), { type: \"reactions\" }, async (cursor, signal) =>\n interactions(await client.reactions.mine({ ...query, cursor: cursor as string | undefined, summary: cursor ? undefined : query.summary }, signal)),\n );\n return { ...list, summary: list.metadata };\n}\n\nexport interface UseContentFilters {\n filters: ContentFilters | null;\n loading: boolean;\n error?: ContentKitError;\n saving: boolean;\n /** Atomically changes submitted entity choices; other choices are preserved. */\n save: (update: ContentFiltersUpdate) => Promise<ContentFilters>;\n setVisible: (entityId: string, visible: boolean) => Promise<ContentFilters>;\n setIncludeDeleted: (include: boolean) => Promise<ContentFilters>;\n}\n\n/** One current-domain control per entity, shared by all applies_to kinds. */\nexport function useContentFilters(o: { language?: string; client?: ContentKitClient } = {}): UseContentFilters {\n const { client, store, scope, viewer, language: provided } = useContentScope(o.client);\n const language = o.language ?? provided;\n const guest = viewer === null;\n const browser = client.preferences.browser;\n const local = useSyncExternalStore(browser.subscribe, browser.snapshot, browser.snapshot);\n const key = keyOf(\"content-filters\", scope, language);\n const previous = useRef<{\n client: ContentKitClient;\n language?: string;\n guest: boolean;\n data?: ContentFilters;\n } | null>(null);\n const initial =\n guest && previous.current?.guest && previous.current.client === client && previous.current.language === language\n ? previous.current.data\n : undefined;\n const r = useResource<ContentFilters>(\n store,\n key,\n { type: \"content-filters\" },\n (signal) => client.discovery.contentFilters(language, signal),\n { initial },\n );\n previous.current = { client, language, guest, data: r.data };\n const applyGuest = useCallback(\n (source: ContentFilters, choices = local): ContentFilters => {\n const values = new Map(choices.filters.map((row) => [row.entity_id, row]));\n return {\n ...source,\n include_deleted: false,\n filters: source.filters.map((row) => {\n const choice = values.get(row.entity.id);\n return { ...row, visible: choice?.visible ?? row.default_visible, overridden: choice?.visible !== undefined };\n }),\n };\n },\n [local],\n );\n const displayed = useMemo(() => (r.data && guest ? applyGuest(r.data) : r.data), [r.data, guest, applyGuest]);\n const guarded = useGuarded();\n const isCurrent = useCurrentDiscoveryScope(client, scope);\n const [inflight, setInflight] = useState(0);\n const current = useRef(displayed);\n current.current = displayed;\n useEffect(() => {\n setInflight(0);\n }, [client, scope]);\n const save = useCallback(\n async (update: ContentFiltersUpdate) => {\n if (!isCurrent()) throw new ContentKitError(\"aborted\", \"The account changed.\");\n if (guest) {\n const source = current.current;\n if (!source) throw new ContentKitError(\"invalid_request\", \"Content filters have not loaded.\");\n const allowed = new Set(source.filters.map((row) => row.entity.id));\n const updates: import(\"../client/browser-reader-preferences.js\").ReaderFilterChoice[] = [];\n const seen = new Set<string>();\n for (const row of update.filters ?? []) {\n if (!allowed.has(row.entity_id) || seen.has(row.entity_id))\n throw new ContentKitError(\"invalid_request\", \"This content filter is not configured or is set twice.\");\n seen.add(row.entity_id);\n if (row.default === true && row.visible === undefined)\n updates.push({ entity_id: row.entity_id, default: true });\n else if (row.default === undefined && typeof row.visible === \"boolean\")\n updates.push({ entity_id: row.entity_id, visible: row.visible });\n else throw new ContentKitError(\"invalid_request\", \"A content filter needs visible or default:true.\");\n }\n client.preferences.setGuestFilters(updates);\n return applyGuest(source, browser.snapshot());\n }\n const submitted = new Set((update.filters ?? []).map((row) => row.entity_id));\n const changesDeleted = typeof update.include_deleted === \"boolean\";\n setInflight((n) => n + 1);\n try {\n const out = await guarded(() => {\n if (!isCurrent()) throw new ContentKitError(\"aborted\", \"The account changed.\");\n return client.discovery.setContentFilters(update, language);\n });\n if (isCurrent()) {\n const rows = new Map(out.filters.map((row) => [row.entity.id, row]));\n // Another control may already have applied a newer response. Merge\n // only this request's choices, never its stale unrelated snapshot.\n store.set<ContentFilters>(key, (previous) => previous ? {\n ...previous,\n filters: previous.filters.flatMap((row) => {\n if (!submitted.has(row.entity.id)) return [row];\n const next = rows.get(row.entity.id);\n return next ? [next] : [];\n }),\n include_deleted: changesDeleted ? out.include_deleted : previous.include_deleted,\n } : out);\n }\n return out;\n } finally {\n setInflight((n) => Math.max(0, n - 1));\n }\n },\n [client, guarded, language, key, store, isCurrent, guest, browser, applyGuest],\n );\n const setVisible = useCallback(\n (entityId: string, visible: boolean) => save({ filters: [{ entity_id: entityId, visible }] }),\n [save],\n );\n const setIncludeDeleted = useCallback((include: boolean) => save({ include_deleted: include }), [save]);\n return {\n filters: displayed ?? null,\n loading: r.loading || !r.loaded,\n error: r.error,\n saving: inflight > 0,\n save,\n setVisible,\n setIncludeDeleted,\n };\n}\n\nexport interface UseTypeahead {\n contents: Card[];\n entities: GroupCard[];\n /** The query the suggestions answer (trimmed). */\n query: string;\n loading: boolean;\n error?: ContentKitError;\n}\n\nconst NONE: Pick<UseTypeahead, \"contents\" | \"entities\"> = { contents: [], entities: [] };\n\n/** Suggestions while the reader types: debounced, the stale ones abandoned. */\nexport function useTypeahead(\n text: string,\n o: Omit<TypeaheadQuery, \"q\"> & { debounce?: number; minLength?: number; client?: ContentKitClient; management?: boolean; request?: (query: TypeaheadQuery, signal: AbortSignal) => Promise<Typeahead> } = {},\n): UseTypeahead {\n const { client, language, scope: viewerScope } = useContentScope(o.client);\n const { debounce = 150, minLength = 1, client: _own, management = false, request, ...rest } = o;\n const scope = useMemo(() => ({ viewerScope, management, request }), [viewerScope, management, request]);\n const q = text.trim();\n const query = useMemo(() => ({ display_language: language, ...rest, q }), [language, q, JSON.stringify(rest)]); // eslint-disable-line react-hooks/exhaustive-deps\n const [state, setState] = useState<UseTypeahead & { scope: typeof scope }>({ ...NONE, query: \"\", loading: false, scope });\n useEffect(() => {\n if (q.length < minLength) {\n setState({ ...NONE, query: \"\", loading: false, scope });\n return;\n }\n setState((s) => ({ ...(s.scope === scope ? s : { ...NONE, query: \"\" }), loading: true, scope }));\n const ctl = new AbortController();\n const timer = setTimeout(() => {\n const pending = request ? request(query, ctl.signal) : management\n ? client.entities.manage({ q, kind: query.entity_kinds?.[0], language: query.display_language, limit: query.limit ?? 10 }, ctl.signal)\n .then((page) => ({ contents: [], entities: page.entities }))\n : client.discovery.typeahead(query, ctl.signal);\n pending.then(\n (r) => { if (!ctl.signal.aborted) setState({ contents: r.contents, entities: r.entities, query: q, loading: false, scope }); },\n (e) => {\n const error = toContentKitError(e);\n if (!ctl.signal.aborted && error.code !== \"aborted\") setState({ ...NONE, query: q, loading: false, error, scope });\n },\n );\n }, debounce);\n return () => {\n clearTimeout(timer);\n ctl.abort();\n };\n }, [client, query, q, debounce, minLength, management, request, scope]);\n return state.scope === scope ? state : { ...NONE, query: \"\", loading: q.length >= minLength };\n}\n\nconst beacons = new WeakMap<ContentKitClient, Beacons>();\n\n/** The client's signal and exposure batcher: one per client. */\nexport function beaconsFor(client: ContentKitClient, o?: BeaconOptions): Beacons {\n let b = beacons.get(client);\n if (!b) beacons.set(client, (b = new Beacons(client, o)));\n return b;\n}\n\nexport function useBeacons(o: { client?: ContentKitClient } = {}): Beacons {\n const { client } = useContentScope(o.client);\n return beaconsFor(client);\n}\n\nexport interface ExposureOptions {\n /** Where the list is: \"home\", \"search\", \"similar\". */\n surface: string;\n /** Changes with what the list shows: a new render id. */\n render: string;\n ranker?: string;\n query_id?: string;\n language?: string;\n client?: ContentKitClient;\n}\n\nexport interface UseExposure {\n /** The first bounded segment; click() selects the matching segment for later positions. */\n render_id: string;\n /** A card's ref: reports it shown once at least half of it is in view. */\n track: (content: string, position: number) => (el: Element | null) => void;\n /** Reports a click on the card at position. */\n click: (content: string, position: number) => void;\n}\n\n/** A rendered result list: each page rendered, each card shown, clicks attributed to the render. */\nexport function useExposure(items: readonly { id: string; position?: number; version_id?: string; version?: { id: string } | null }[], o: ExposureOptions): UseExposure {\n const { client, scope, language } = useContentScope(o.client);\n const b = beaconsFor(client);\n const isCurrent = useCurrentDiscoveryScope(client, scope);\n const renderId = useMemo(() => eventId(), [o.render, scope]); // eslint-disable-line react-hooks/exhaustive-deps\n const base = useMemo(() => ({ surface: o.surface, ranker: o.ranker, query_id: o.query_id, language: o.language ?? language }), [o.surface, o.ranker, o.query_id, o.language, language]);\n const state = useMemo(() => ({ segments: new Map<number, ExposureSegment>(), pending: new Set<number>(), timer: undefined as ReturnType<typeof setTimeout> | undefined }), [renderId]); // eslint-disable-line react-hooks/exhaustive-deps\n const segmentID = useCallback((index: number) => index === 0 ? renderId : `${renderId}-${index}`, [renderId]);\n const segmentFor = useCallback((index: number) => {\n let segment = state.segments.get(index);\n if (!segment) {\n segment = { rendered: new Map(), visible: new Map(), renderedRevision: 0, visibleRevision: 0 };\n state.segments.set(index, segment);\n }\n return segment;\n }, [state]);\n useEffect(() => {\n if (!isCurrent()) return;\n const changed = new Set<number>();\n for (const [i, item] of items.entries()) {\n const supplied = item.position;\n const position = supplied !== undefined && Number.isSafeInteger(supplied) && supplied > 0 ? supplied : i + 1;\n const index = Math.floor((position - 1) / EXPOSURE_SEGMENT_SIZE), segment = segmentFor(index);\n if (segment.rendered.has(item.id)) continue;\n segment.rendered.set(item.id, { content_id: item.id, version_id: item.version_id ?? item.version?.id, position });\n changed.add(index);\n }\n for (const index of changed) {\n const segment = segmentFor(index);\n b.exposure({ ...base, render_id: segmentID(index), stage: \"rendered\", revision: ++segment.renderedRevision,\n occurred_at: segment.renderedAt ??= new Date().toISOString(), shown: [...segment.rendered.values()] });\n }\n }, [b, base, items, state, segmentFor, segmentID, isCurrent]);\n const observer = useMemo(() => {\n if (typeof IntersectionObserver !== \"function\") return null;\n return new IntersectionObserver((entries) => {\n if (!isCurrent()) return;\n for (const e of entries) {\n if (!e.isIntersecting) continue;\n const el = e.target as HTMLElement, content = el.dataset.exposureContent!;\n const position = Number(el.dataset.exposurePosition), index = Math.floor((position - 1) / EXPOSURE_SEGMENT_SIZE);\n const segment = segmentFor(index);\n if (segment.visible.has(content)) continue;\n segment.visible.set(content, segment.rendered.get(content) ?? { content_id: content, position });\n state.pending.add(index);\n }\n if (!state.pending.size) return;\n state.timer ??= setTimeout(() => {\n state.timer = undefined;\n if (!isCurrent()) return;\n for (const index of state.pending) {\n const segment = segmentFor(index);\n b.exposure({ ...base, render_id: segmentID(index), stage: \"visible\", revision: ++segment.visibleRevision,\n occurred_at: segment.visibleAt ??= new Date().toISOString(), shown: [...segment.visible.values()] });\n }\n state.pending.clear();\n }, 300);\n }, { threshold: 0.5 });\n }, [b, base, state, segmentFor, segmentID, isCurrent]);\n useEffect(() => () => { observer?.disconnect(); clearTimeout(state.timer); }, [observer, state]);\n useEffect(() => {\n for (const index of state.segments.keys()) b.beginExposure(segmentID(index));\n return () => { for (const index of state.segments.keys()) b.endExposure(segmentID(index)); };\n }, [b, state, segmentID]);\n const track = useCallback((content: string, position: number) => (el: Element | null) => {\n if (!el || !observer) return;\n (el as HTMLElement).dataset.exposureContent = content;\n (el as HTMLElement).dataset.exposurePosition = String(position);\n observer.observe(el);\n }, [observer]);\n const click = useCallback((content: string, position: number) => {\n if (!isCurrent()) return;\n const index = Math.floor((position - 1) / EXPOSURE_SEGMENT_SIZE);\n const item = items.find((item) => item.id === content);\n const version = item?.version_id ?? item?.version?.id;\n b.click(content, { render_id: segmentID(index), surface: o.surface, position, version_id: version, language: base.language });\n }, [b, items, segmentID, o.surface, base.language, isCurrent]);\n return { render_id: renderId, track, click };\n}\n\ntype ObservedPlacement = { content_id: string; version_id?: string; position: number };\ntype ExposureSegment = {\n rendered: Map<string, ObservedPlacement>;\n visible: Map<string, ObservedPlacement>;\n renderedRevision: number;\n visibleRevision: number;\n renderedAt?: string;\n visibleAt?: string;\n};\nconst EXPOSURE_SEGMENT_SIZE = 32;\n"],"mappings":";;;;;;;;AAYA,IAAM,KAAQ,OAAoB;CAAE,OAAO,EAAE;CAAU,MAAM,EAAE,eAAe;CAAM,UAAU,EAAE;AAAQ,IAElG,IAA8B,CAAC,GAC/B,IAA0C,OAAO,OAAO,CAAC,CAAC;AAGhE,SAAS,EAAyB,GAA0B,GAA8B;CACxF,IAAM,IAAQ,SAAe;EAAE;EAAQ;CAAM,IAAI,CAAC,GAAQ,CAAK,CAAC,GAC1D,IAAU,EAA4B,CAAK;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S,CAAC;CAmBrD,OAlBA,cAAsB;EAA0B,AAAxB,GAAU,WAAW,GAAG,aAAa,EAAM,KAAK;CAAG,GAAG,CAAC,GAAU,CAAK,CAAC,GAC/F,QAAgB;EACd,KAAK,IAAM,KAAS,EAAM,SAAS,KAAK,GAAG,EAAE,cAAc,EAAU,CAAK,CAAC;EAC3E,aAAa;GAAE,KAAK,IAAM,KAAS,EAAM,SAAS,KAAK,GAAG,EAAE,YAAY,EAAU,CAAK,CAAC;EAAG;CAC7F,GAAG;EAAC;EAAG;EAAO;CAAS,CAAC,GAcjB;EAAE,WAAW;EAAU,OAbhB,GAAa,GAAiB,OAAsB,MAAuB;GACnF,AAAC,KAAO,MACZ,EAAoB,QAAQ,kBAAkB,GAC9C,EAAoB,QAAQ,mBAAmB,OAAO,CAAQ,GAC9D,EAAS,QAAQ,CAAE;EACrB,GAAG,CAAC,CAAQ,CAQkB;EAAO,OAPvB,GAAa,GAAiB,MAAqB;GAC/D,IAAI,CAAC,EAAU,GAAG;GAClB,IAAM,IAAQ,KAAK,OAAO,IAAW,KAAK,CAAqB,GACzD,IAAO,EAAM,MAAM,MAAS,EAAK,OAAO,CAAO,GAC/C,IAAU,GAAM,cAAc,GAAM,SAAS;GACnD,EAAE,MAAM,GAAS;IAAE,WAAW,EAAU,CAAK;IAAG,SAAS,EAAE;IAAS;IAAU,YAAY;IAAS,UAAU,EAAK;GAAS,CAAC;EAC9H,GAAG;GAAC;GAAG;GAAO;GAAW,EAAE;GAAS,EAAK;GAAU;EAAS,CACvB;CAAM;AAC7C;AAWA,IAAM,IAAwB"}
1
+ {"version":3,"file":"discovery.js","names":[],"sources":["../../src/react/discovery.ts"],"sourcesContent":["import { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from \"react\";\nimport { Beacons, eventId, type BeaconOptions } from \"../client/beacons.js\";\nimport type { ContentKitClient } from \"../client/client.js\";\nimport type { MineQuery } from \"../client/content/favorites.js\";\nimport type { ContentQuery, DailyReleasesQuery, HistoryQuery, RailQuery, ReleaseDatesQuery, SearchQuery, TypeaheadQuery } from \"../client/discovery.js\";\nimport { ContentKitError, toContentKitError } from \"../client/errors.js\";\nimport type { Card, ContentFilters, ContentFiltersUpdate, ContentPage, DailyReleases, DateCount, GroupCard, Interaction, InteractionPage, RecentSearch, Typeahead } from \"../client/generated/wire.js\";\nimport { ContentKitContext, useGuarded } from \"./context.js\";\nimport { keyOf, useContentScope, useList, useResource, type UseList } from \"./use-resource.js\";\nimport { guestStanding, type GuestReadingItem } from \"../client/guest-reading-history.js\";\nimport { recentSearchLimit } from \"../client/browser-search-history.js\";\n\nconst page = (p: ContentPage) => ({ items: p.contents, next: p.next_cursor ?? null, metadata: p.summary });\nexport interface UseContents extends UseList<Card, ContentPage[\"summary\"]> { summary?: ContentPage[\"summary\"] }\nconst NO_SEARCHES: RecentSearch[] = [];\nconst NO_READING: readonly GuestReadingItem[] = Object.freeze([]);\n\n// A new identity even after A → B → A, so late requests cannot write into the new visit.\nfunction useCurrentDiscoveryScope(client: ContentKitClient, scope: string): () => boolean {\n const owner = useMemo(() => ({ client, scope }), [client, scope]);\n const current = useRef<typeof owner | null>(owner);\n useLayoutEffect(() => {\n current.current = owner;\n return () => { current.current = null; };\n }, [owner]);\n return useCallback(() => current.current === owner, [owner]);\n}\n\n/** Titles, names and paths in the provider's language unless the query says otherwise. */\nfunction useDisplay<T extends { display_language?: string }>(q: T | null): T | null {\n const language = useContext(ContentKitContext)?.language;\n return useMemo(() => (q && !q.display_language && language ? { ...q, display_language: language } : q), [q, language]);\n}\n\n/** Contents as cards, a cursor page at a time; null reads nothing. */\nexport function useContents(q: ContentQuery | null, o: { client?: ContentKitClient } = {}): UseContents {\n const { client, store, scope } = useContentScope(o.client);\n const query = useDisplay(q);\n const list = useList(store, query ? keyOf(\"cards\", scope, \"list\", query) : null, { type: \"cards\" }, async (cursor, signal) =>\n page(await client.discovery.list({ ...query, cursor: cursor as string | undefined, summary: cursor ? undefined : query?.summary }, signal)),\n );\n return { ...list, summary: list.metadata };\n}\n\n/** One numbered page of a list or search: its cards and the selection's summary (total included). */\nexport interface UseContentsPage {\n items: Card[];\n summary?: ContentPage[\"summary\"];\n loading: boolean;\n error?: ContentKitError;\n reload: () => void;\n}\n\nconst NO_CARDS: Card[] = [];\n\nfunction useNumbered(key: string | null, fetch: (signal: AbortSignal) => Promise<ContentPage>, o: { client?: ContentKitClient }): UseContentsPage {\n const { store } = useContentScope(o.client);\n const r = useResource<ContentPage>(store, key, { type: \"cards\" }, fetch);\n return { items: r.data?.contents ?? NO_CARDS, summary: r.data?.summary, loading: r.loading || (!!key && !r.loaded), error: r.error, reload: r.reload };\n}\n\n/** Page `page` (from 1) of a list, with its summary; null reads nothing. */\nexport function useContentsPage(q: ContentQuery | null, page: number, o: { client?: ContentKitClient } = {}): UseContentsPage {\n const { client, scope } = useContentScope(o.client);\n const query = useDisplay(q);\n const n = Math.max(1, Math.floor(page));\n return useNumbered(query ? keyOf(\"cards\", scope, \"list-page\", query, n) : null, (signal) => client.discovery.list({ ...query!, cursor: undefined, page: n, summary: query!.summary ?? true }, signal), o);\n}\n\n/** Page `page` (from 1) of a search, with its summary; nothing until the query has text. */\nexport function useSearchPage(q: SearchQuery | null, page: number, o: { client?: ContentKitClient } = {}): UseContentsPage {\n const { client, scope, viewer } = useContentScope(o.client);\n const query = useDisplay(q?.q.trim() ? q : null);\n const n = Math.max(1, Math.floor(page));\n const isCurrent = useCurrentDiscoveryScope(client, scope);\n return useNumbered(\n query ? keyOf(\"cards\", scope, \"search-page\", query, n) : null,\n async (signal) => {\n const out = await client.discovery.search({ ...query!, cursor: undefined, page: n, summary: query!.summary ?? true }, signal);\n if (n === 1 && viewer === null && !signal.aborted && isCurrent()) client.discovery.browserSearches.record(query!.q, out.contents.length);\n return out;\n },\n o,\n );\n}\n\n/** Locked contents in the same full selection, including its activity window. */\nexport function useLockedCount(q: ContentQuery | null, o: { client?: ContentKitClient } = {}): { count?: number; loading: boolean } {\n const { client, store, scope } = useContentScope(o.client);\n const filter = useMemo(() => {\n if (!q) return null;\n const { cursor: _cursor, ...rest } = q;\n return { ...rest, mode: \"lock\" as const, limit: 1, summary: true };\n }, [q]);\n const query = useDisplay(filter);\n const r = useResource<number>(store, query ? keyOf(\"cards\", scope, \"locked-summary\", query) : null, { type: \"cards\" }, async (signal) => {\n const out = await client.discovery.list(query!, signal);\n return out.summary?.locked_count ?? 0;\n });\n return { count: r.data, loading: r.loading };\n}\n\n/** Keyword search results as cards; nothing while q.q is empty. */\nexport function useSearch(q: SearchQuery | null, o: { client?: ContentKitClient } = {}): UseContents {\n const { client, store, scope, viewer } = useContentScope(o.client);\n const query = useDisplay(q?.q.trim() ? q : null);\n const isCurrent = useCurrentDiscoveryScope(client, scope);\n const list = useList(store, query ? keyOf(\"cards\", scope, \"search\", query) : null, { type: \"cards\" }, async (cursor, signal) => {\n const out = await client.discovery.search({ ...query!, cursor: cursor as string | undefined, summary: cursor ? undefined : query?.summary }, signal);\n if (!cursor && viewer === null && !signal.aborted && isCurrent()) client.discovery.browserSearches.record(query!.q, out.contents.length);\n return page(out);\n });\n return { ...list, summary: list.metadata };\n}\n\nexport interface UseRail {\n items: Card[];\n summary?: ContentPage[\"summary\"];\n loading: boolean;\n error?: ContentKitError;\n /** The site runs without the signal plane (not_configured): leave the rail out. */\n unavailable: boolean;\n reload: () => void;\n}\n\nfunction useRail(key: string | null, fetch: (signal: AbortSignal) => Promise<ContentPage>, o: { client?: ContentKitClient }): UseRail {\n const { store } = useContentScope(o.client);\n const r = useResource<ContentPage>(store, key, { type: \"cards\" }, fetch);\n const unavailable = r.error?.code === \"not_configured\";\n return { items: r.data?.contents ?? [], summary: r.data?.summary, loading: !!key && (r.loading || !r.loaded), error: unavailable ? undefined : r.error, unavailable, reload: r.reload };\n}\n\n/** Contents like one: co-engagement, or the site's configured source. */\nexport function useSimilar(id: string | null | undefined, q: RailQuery = {}, o: { client?: ContentKitClient } = {}): UseRail {\n const { client, scope } = useContentScope(o.client);\n const query = useDisplay(q)!;\n return useRail(id ? keyOf(\"cards\", scope, \"similar\", id, query) : null, (s) => client.discovery.similar(id!, query, s), o);\n}\n\n/** Contents for the signed-in reader; nothing signed out, or when q is null. */\nexport function useRecommendations(q: RailQuery | null = {}, o: { client?: ContentKitClient } = {}): UseRail {\n const { client, scope, viewer } = useContentScope(o.client);\n const query = useDisplay(q);\n return useRail(viewer === null || !query ? null : keyOf(\"cards\", scope, \"recommended\", query), (s) => client.discovery.recommendations(query!, s), o);\n}\n\n/** A release date bucket, keyed by its date. */\nexport type ReleaseDate = DateCount & { id: string };\n\n/** The release date index: per month or day, newest first. */\nexport function useReleaseDates(q: ReleaseDatesQuery = {}, o: { client?: ContentKitClient } = {}): UseList<ReleaseDate> {\n const { client, store, scope } = useContentScope(o.client);\n const query = useDisplay(q)!;\n return useList(store, keyOf(\"release-dates\", scope, query), { type: \"release-dates\" }, async (cursor, signal) => {\n const r = await client.discovery.releaseDates({ ...query, cursor: cursor as string | undefined }, signal);\n return { items: r.dates.map((d) => ({ ...d, id: d.date })), next: r.next_cursor ?? null };\n });\n}\n\nexport interface UseDailyReleases {\n data?: DailyReleases;\n loading: boolean;\n error?: ContentKitError;\n reload: () => void;\n}\n\n/** One complete calendar window, shared by all readers of the same query. */\nexport function useDailyReleases(q: DailyReleasesQuery | null = {}, o: { client?: ContentKitClient } = {}): UseDailyReleases {\n const { client, store, scope } = useContentScope(o.client);\n const query = useDisplay(q);\n const r = useResource<DailyReleases>(store, query ? keyOf(\"daily-releases\", scope, query) : null, { type: \"daily-releases\" }, (signal) => client.discovery.releases(query!, signal));\n return { data: r.data, loading: !!query && (r.loading || !r.loaded), error: r.error, reload: r.reload };\n}\n\nexport interface UseHistory extends UseContents {\n /** A status-filtered guest selection has hidden candidates whose current version facts cannot be inspected. */\n filterSummaryUnknown?: boolean;\n /** Erases the reader's history: of one content item, one kind, or (no argument) everything. */\n forget: (o?: { kind?: string; content_id?: string }) => Promise<void>;\n}\n\n/** Account history is authoritative; signed-out reading stays in this browser across tabs. */\nexport function useHistory(q: HistoryQuery | null = {}, o: { client?: ContentKitClient } = {}): UseHistory {\n const { client, store, scope, viewer } = useContentScope(o.client);\n const query = useDisplay(q);\n const guarded = useGuarded();\n const guest = viewer === null;\n const isCurrent = useCurrentDiscoveryScope(client, scope);\n const browser = client.guestHistory;\n const enabled = query !== null;\n const subscribe = useCallback((listener: () => void) => guest && enabled ? browser.subscribe(listener) : () => {}, [browser, guest, enabled]);\n const snapshot = useCallback(() => guest && enabled ? browser.snapshot() : NO_READING, [browser, guest, enabled]);\n const local = useSyncExternalStore(subscribe, snapshot, () => NO_READING);\n const selected = useMemo(() => local.filter(row => !query?.kind || row.kind === query.kind).slice(0, 100), [local, query?.kind]);\n const localRevision = guest ? selected.map(row => [row.id, row.at, row.checkpoints.map(checkpoint => [checkpoint.visit_id, checkpoint.segment_id, checkpoint.revision])]) : undefined;\n const list = useList(store, !query || viewer === undefined ? null : keyOf(\"history\", scope, query, localRevision), { type: \"history\" }, async (cursor, signal) => {\n if (!guest) return page(await client.discovery.history({ ...query, cursor: cursor as string | undefined, summary: cursor ? undefined : query?.summary }, signal));\n const offset = typeof cursor === \"number\" ? cursor : 0;\n const limit = Math.max(1, Math.min(100, query?.limit ?? 50));\n const batch = selected.slice(offset, offset + limit);\n if (!batch.length) return { items: [], next: null };\n // Public hydration enforces current hard-domain rules, access and optional preferences.\n const out = await client.discovery.list({ ids: (query?.summary && !cursor ? selected : batch).map(row => row.id), summary: !cursor ? query?.summary : undefined, kind: query?.kind, language: query?.language,\n display_language: query?.display_language, mode: query?.mode, card_entities: query?.card_entities, limit: 100 }, signal);\n const cards = new Map(out.contents.map(card => [card.id, card]));\n const items = batch.flatMap(row => {\n const card = cards.get(row.id); if (!card) return [];\n const viewer = guestStanding(card, row);\n if (query?.status === \"seen\" && !viewer.seen || query?.status === \"in_progress\" && (!viewer.seen || viewer.completed) || query?.status === \"completed\" && !viewer.completed) return [];\n return [{ ...card, viewer }];\n });\n return { items, next: offset + batch.length < selected.length ? offset + batch.length : null, metadata: out.summary };\n });\n const forget = useCallback((filter: { kind?: string; content_id?: string } = {}) => {\n if (!isCurrent()) return Promise.resolve();\n if (guest) { browser.clear(filter); return Promise.resolve(); }\n return guarded(() => client.discovery.forgetHistory(filter));\n }, [browser, client, guest, guarded, isCurrent]);\n const uncertain = guest && !!query?.status;\n return { ...list, summary: uncertain ? undefined : list.metadata, filterSummaryUnknown: uncertain && (list.metadata?.filtered_count ?? 0) > 0, forget };\n}\n\nexport interface UseRecentSearches {\n searches: RecentSearch[];\n loading: boolean;\n error?: ContentKitError;\n /** Clears one query, or every recent search. */\n clear: (query?: string) => Promise<void>;\n}\n\n/** Guest history stays in this browser; account history comes only from the server. enabled false reads nothing yet. */\nexport function useRecentSearches(o: { limit?: number; enabled?: boolean; client?: ContentKitClient } = {}): UseRecentSearches {\n const { client, store, scope, viewer } = useContentScope(o.client);\n const guarded = useGuarded();\n const isCurrent = useCurrentDiscoveryScope(client, scope);\n const guest = viewer === null;\n const enabled = o.enabled !== false;\n const browser = client.discovery.browserSearches;\n const subscribe = useCallback((listener: () => void) => guest && enabled ? browser.subscribe(listener) : () => {}, [browser, guest, enabled]);\n const snapshot = useCallback(() => guest && enabled ? browser.snapshot() : NO_SEARCHES, [browser, guest, enabled]);\n const local = useSyncExternalStore(subscribe, snapshot, () => NO_SEARCHES);\n const searches = useMemo(() => local.slice(0, recentSearchLimit(o.limit)), [local, o.limit]);\n const key = !enabled || guest ? null : keyOf(\"searches\", scope, o.limit ?? 10);\n const r = useResource<RecentSearch[]>(store, key, { type: \"searches\" }, async (s) => (await client.discovery.recentSearches({ limit: o.limit }, s)).searches);\n useEffect(() => {\n if (!key) return;\n const reload = () => { if (!store.snapshot(key).loading) store.load(key, true); };\n // Reopening a panel must not leave an already-cached account list stale.\n if (store.snapshot(key).loaded) reload();\n const visible = () => { if (document.visibilityState === \"visible\") reload(); };\n if (typeof window !== \"undefined\") window.addEventListener(\"focus\", reload);\n if (typeof document !== \"undefined\") document.addEventListener(\"visibilitychange\", visible);\n return () => {\n if (typeof window !== \"undefined\") window.removeEventListener(\"focus\", reload);\n if (typeof document !== \"undefined\") document.removeEventListener(\"visibilitychange\", visible);\n };\n }, [key, store]);\n const clear = useCallback(async (query?: string) => {\n if (!isCurrent()) return;\n if (guest) { browser.clear(query); return; }\n await guarded(() => isCurrent() ? client.discovery.clearSearches(query ? { query } : {}) : Promise.resolve());\n }, [browser, client, guest, guarded, isCurrent]);\n return guest\n ? { searches: enabled ? searches : NO_SEARCHES, loading: false, clear }\n : { searches: r.data ?? NO_SEARCHES, loading: !!key && (r.loading || !r.loaded), error: r.error, clear };\n}\n\n/** A favorite or reaction with its content's or group's id. */\nexport type MyInteraction = Interaction & { id: string };\n\nconst interactions = (p: InteractionPage) => ({ items: p.items.map((x) => ({ ...x, id: x.content?.id ?? x.entity?.id ?? \"\" })), next: p.next_cursor ?? null, metadata: p.summary });\n\nexport interface UseInteractions extends UseList<MyInteraction, InteractionPage[\"summary\"]> { summary?: InteractionPage[\"summary\"] }\n\n/** The signed-in reader's favorites, most recent first: content cards or groups. */\nexport function useMyFavorites(q: MineQuery = {}, o: { client?: ContentKitClient } = {}): UseInteractions {\n const { client, store, scope, viewer } = useContentScope(o.client);\n const query = useDisplay(q)!;\n const list = useList(store, viewer === null ? null : keyOf(\"favorites\", scope, query), { type: \"favorites\" }, async (cursor, signal) =>\n interactions(await client.favorites.mine({ ...query, cursor: cursor as string | undefined, summary: cursor ? undefined : query.summary }, signal)),\n );\n return { ...list, summary: list.metadata };\n}\n\n/** What the signed-in reader liked (or, with value, disliked), most recent first. */\nexport function useMyReactions(q: MineQuery & { value?: \"like\" | \"dislike\" } = {}, o: { client?: ContentKitClient } = {}): UseInteractions {\n const { client, store, scope, viewer } = useContentScope(o.client);\n const query = useDisplay(q)!;\n const list = useList(store, viewer === null ? null : keyOf(\"reactions\", scope, query), { type: \"reactions\" }, async (cursor, signal) =>\n interactions(await client.reactions.mine({ ...query, cursor: cursor as string | undefined, summary: cursor ? undefined : query.summary }, signal)),\n );\n return { ...list, summary: list.metadata };\n}\n\nexport interface UseContentFilters {\n filters: ContentFilters | null;\n loading: boolean;\n error?: ContentKitError;\n saving: boolean;\n /** Atomically changes submitted entity choices; other choices are preserved. */\n save: (update: ContentFiltersUpdate) => Promise<ContentFilters>;\n setVisible: (entityId: string, visible: boolean) => Promise<ContentFilters>;\n setIncludeDeleted: (include: boolean) => Promise<ContentFilters>;\n}\n\n/** One current-domain control per entity, shared by all applies_to kinds. */\nexport function useContentFilters(o: { language?: string; client?: ContentKitClient } = {}): UseContentFilters {\n const { client, store, scope, viewer, language: provided } = useContentScope(o.client);\n const language = o.language ?? provided;\n const guest = viewer === null;\n const browser = client.preferences.browser;\n const local = useSyncExternalStore(browser.subscribe, browser.snapshot, browser.snapshot);\n const key = keyOf(\"content-filters\", scope, language);\n const previous = useRef<{\n client: ContentKitClient;\n language?: string;\n guest: boolean;\n data?: ContentFilters;\n } | null>(null);\n const initial =\n guest && previous.current?.guest && previous.current.client === client && previous.current.language === language\n ? previous.current.data\n : undefined;\n const r = useResource<ContentFilters>(\n store,\n key,\n { type: \"content-filters\" },\n (signal) => client.discovery.contentFilters(language, signal),\n { initial },\n );\n previous.current = { client, language, guest, data: r.data };\n const applyGuest = useCallback(\n (source: ContentFilters, choices = local): ContentFilters => {\n const values = new Map(choices.filters.map((row) => [row.entity_id, row]));\n return {\n ...source,\n include_deleted: false,\n filters: source.filters.map((row) => {\n const choice = values.get(row.entity.id);\n return { ...row, visible: choice?.visible ?? row.default_visible, overridden: choice?.visible !== undefined };\n }),\n };\n },\n [local],\n );\n const displayed = useMemo(() => (r.data && guest ? applyGuest(r.data) : r.data), [r.data, guest, applyGuest]);\n const guarded = useGuarded();\n const isCurrent = useCurrentDiscoveryScope(client, scope);\n const [inflight, setInflight] = useState(0);\n const current = useRef(displayed);\n current.current = displayed;\n useEffect(() => {\n setInflight(0);\n }, [client, scope]);\n const save = useCallback(\n async (update: ContentFiltersUpdate) => {\n if (!isCurrent()) throw new ContentKitError(\"aborted\", \"The account changed.\");\n if (guest) {\n const source = current.current;\n if (!source) throw new ContentKitError(\"invalid_request\", \"Content filters have not loaded.\");\n const allowed = new Set(source.filters.map((row) => row.entity.id));\n const updates: import(\"../client/browser-reader-preferences.js\").ReaderFilterChoice[] = [];\n const seen = new Set<string>();\n for (const row of update.filters ?? []) {\n if (!allowed.has(row.entity_id) || seen.has(row.entity_id))\n throw new ContentKitError(\"invalid_request\", \"This content filter is not configured or is set twice.\");\n seen.add(row.entity_id);\n if (row.default === true && row.visible === undefined)\n updates.push({ entity_id: row.entity_id, default: true });\n else if (row.default === undefined && typeof row.visible === \"boolean\")\n updates.push({ entity_id: row.entity_id, visible: row.visible });\n else throw new ContentKitError(\"invalid_request\", \"A content filter needs visible or default:true.\");\n }\n client.preferences.setGuestFilters(updates);\n return applyGuest(source, browser.snapshot());\n }\n const submitted = new Set((update.filters ?? []).map((row) => row.entity_id));\n const changesDeleted = typeof update.include_deleted === \"boolean\";\n setInflight((n) => n + 1);\n try {\n const out = await guarded(() => {\n if (!isCurrent()) throw new ContentKitError(\"aborted\", \"The account changed.\");\n return client.discovery.setContentFilters(update, language);\n });\n if (isCurrent()) {\n const rows = new Map(out.filters.map((row) => [row.entity.id, row]));\n // Another control may already have applied a newer response. Merge\n // only this request's choices, never its stale unrelated snapshot.\n store.set<ContentFilters>(key, (previous) => previous ? {\n ...previous,\n filters: previous.filters.flatMap((row) => {\n if (!submitted.has(row.entity.id)) return [row];\n const next = rows.get(row.entity.id);\n return next ? [next] : [];\n }),\n include_deleted: changesDeleted ? out.include_deleted : previous.include_deleted,\n } : out);\n }\n return out;\n } finally {\n setInflight((n) => Math.max(0, n - 1));\n }\n },\n [client, guarded, language, key, store, isCurrent, guest, browser, applyGuest],\n );\n const setVisible = useCallback(\n (entityId: string, visible: boolean) => save({ filters: [{ entity_id: entityId, visible }] }),\n [save],\n );\n const setIncludeDeleted = useCallback((include: boolean) => save({ include_deleted: include }), [save]);\n return {\n filters: displayed ?? null,\n loading: r.loading || !r.loaded,\n error: r.error,\n saving: inflight > 0,\n save,\n setVisible,\n setIncludeDeleted,\n };\n}\n\nexport interface UseTypeahead {\n contents: Card[];\n entities: GroupCard[];\n /** The query the suggestions answer (trimmed). */\n query: string;\n loading: boolean;\n error?: ContentKitError;\n}\n\nconst NONE: Pick<UseTypeahead, \"contents\" | \"entities\"> = { contents: [], entities: [] };\n\n/** Suggestions while the reader types: debounced, the stale ones abandoned. */\nexport function useTypeahead(\n text: string,\n o: Omit<TypeaheadQuery, \"q\"> & { debounce?: number; minLength?: number; client?: ContentKitClient; management?: boolean; request?: (query: TypeaheadQuery, signal: AbortSignal) => Promise<Typeahead> } = {},\n): UseTypeahead {\n const { client, language, scope: viewerScope } = useContentScope(o.client);\n const { debounce = 150, minLength = 1, client: _own, management = false, request, ...rest } = o;\n const scope = useMemo(() => ({ viewerScope, management, request }), [viewerScope, management, request]);\n const q = text.trim();\n const query = useMemo(() => ({ display_language: language, ...rest, q }), [language, q, JSON.stringify(rest)]); // eslint-disable-line react-hooks/exhaustive-deps\n const [state, setState] = useState<UseTypeahead & { scope: typeof scope }>({ ...NONE, query: \"\", loading: false, scope });\n useEffect(() => {\n if (q.length < minLength) {\n setState({ ...NONE, query: \"\", loading: false, scope });\n return;\n }\n setState((s) => ({ ...(s.scope === scope ? s : { ...NONE, query: \"\" }), loading: true, scope }));\n const ctl = new AbortController();\n const timer = setTimeout(() => {\n const pending = request ? request(query, ctl.signal) : management\n ? client.entities.manage({ q, kind: query.entity_kinds?.[0], language: query.display_language, limit: query.limit ?? 10 }, ctl.signal)\n .then((page) => ({ contents: [], entities: page.entities }))\n : client.discovery.typeahead(query, ctl.signal);\n pending.then(\n (r) => { if (!ctl.signal.aborted) setState({ contents: r.contents, entities: r.entities, query: q, loading: false, scope }); },\n (e) => {\n const error = toContentKitError(e);\n if (!ctl.signal.aborted && error.code !== \"aborted\") setState({ ...NONE, query: q, loading: false, error, scope });\n },\n );\n }, debounce);\n return () => {\n clearTimeout(timer);\n ctl.abort();\n };\n }, [client, query, q, debounce, minLength, management, request, scope]);\n return state.scope === scope ? state : { ...NONE, query: \"\", loading: q.length >= minLength };\n}\n\nconst beacons = new WeakMap<ContentKitClient, Beacons>();\n\n/** The client's signal and exposure batcher: one per client. */\nexport function beaconsFor(client: ContentKitClient, o?: BeaconOptions): Beacons {\n let b = beacons.get(client);\n if (!b) beacons.set(client, (b = new Beacons(client, o)));\n return b;\n}\n\nexport function useBeacons(o: { client?: ContentKitClient } = {}): Beacons {\n const { client } = useContentScope(o.client);\n return beaconsFor(client);\n}\n\nexport interface ExposureOptions {\n /** Where the list is: \"home\", \"search\", \"similar\". */\n surface: string;\n /** Changes with what the list shows: a new render id. */\n render: string;\n ranker?: string;\n query_id?: string;\n language?: string;\n client?: ContentKitClient;\n}\n\nexport interface UseExposure {\n /** The first bounded segment; click() selects the matching segment for later positions. */\n render_id: string;\n /** A card's ref: reports it shown once at least half of it is in view. */\n track: (content: string, position: number) => (el: Element | null) => void;\n /** Reports a click on the card at position. */\n click: (content: string, position: number) => void;\n}\n\n/** A rendered result list: each page rendered, each card shown, clicks attributed to the render. */\nexport function useExposure(items: readonly { id: string; position?: number; version_id?: string; version?: { id: string } | null }[], o: ExposureOptions): UseExposure {\n const { client, scope, language } = useContentScope(o.client);\n const b = beaconsFor(client);\n const isCurrent = useCurrentDiscoveryScope(client, scope);\n const renderId = useMemo(() => eventId(), [o.render, scope]); // eslint-disable-line react-hooks/exhaustive-deps\n const base = useMemo(() => ({ surface: o.surface, ranker: o.ranker, query_id: o.query_id, language: o.language ?? language }), [o.surface, o.ranker, o.query_id, o.language, language]);\n const state = useMemo(() => ({ segments: new Map<number, ExposureSegment>(), pending: new Set<number>(), timer: undefined as ReturnType<typeof setTimeout> | undefined }), [renderId]); // eslint-disable-line react-hooks/exhaustive-deps\n const segmentID = useCallback((index: number) => index === 0 ? renderId : `${renderId}-${index}`, [renderId]);\n const segmentFor = useCallback((index: number) => {\n let segment = state.segments.get(index);\n if (!segment) {\n segment = { rendered: new Map(), visible: new Map(), renderedRevision: 0, visibleRevision: 0 };\n state.segments.set(index, segment);\n }\n return segment;\n }, [state]);\n useEffect(() => {\n if (!isCurrent()) return;\n const changed = new Set<number>();\n for (const [i, item] of items.entries()) {\n const supplied = item.position;\n const position = supplied !== undefined && Number.isSafeInteger(supplied) && supplied > 0 ? supplied : i + 1;\n const index = Math.floor((position - 1) / EXPOSURE_SEGMENT_SIZE), segment = segmentFor(index);\n if (segment.rendered.has(item.id)) continue;\n segment.rendered.set(item.id, { content_id: item.id, version_id: item.version_id ?? item.version?.id, position });\n changed.add(index);\n }\n for (const index of changed) {\n const segment = segmentFor(index);\n b.exposure({ ...base, render_id: segmentID(index), stage: \"rendered\", revision: ++segment.renderedRevision,\n occurred_at: segment.renderedAt ??= new Date().toISOString(), shown: [...segment.rendered.values()] });\n }\n }, [b, base, items, state, segmentFor, segmentID, isCurrent]);\n const observer = useMemo(() => {\n if (typeof IntersectionObserver !== \"function\") return null;\n return new IntersectionObserver((entries) => {\n if (!isCurrent()) return;\n for (const e of entries) {\n if (!e.isIntersecting) continue;\n const el = e.target as HTMLElement, content = el.dataset.exposureContent!;\n const position = Number(el.dataset.exposurePosition), index = Math.floor((position - 1) / EXPOSURE_SEGMENT_SIZE);\n const segment = segmentFor(index);\n if (segment.visible.has(content)) continue;\n segment.visible.set(content, segment.rendered.get(content) ?? { content_id: content, position });\n state.pending.add(index);\n }\n if (!state.pending.size) return;\n state.timer ??= setTimeout(() => {\n state.timer = undefined;\n if (!isCurrent()) return;\n for (const index of state.pending) {\n const segment = segmentFor(index);\n b.exposure({ ...base, render_id: segmentID(index), stage: \"visible\", revision: ++segment.visibleRevision,\n occurred_at: segment.visibleAt ??= new Date().toISOString(), shown: [...segment.visible.values()] });\n }\n state.pending.clear();\n }, 300);\n }, { threshold: 0.5 });\n }, [b, base, state, segmentFor, segmentID, isCurrent]);\n useEffect(() => () => { observer?.disconnect(); clearTimeout(state.timer); }, [observer, state]);\n useEffect(() => {\n for (const index of state.segments.keys()) b.beginExposure(segmentID(index));\n return () => { for (const index of state.segments.keys()) b.endExposure(segmentID(index)); };\n }, [b, state, segmentID]);\n const track = useCallback((content: string, position: number) => (el: Element | null) => {\n if (!el || !observer) return;\n (el as HTMLElement).dataset.exposureContent = content;\n (el as HTMLElement).dataset.exposurePosition = String(position);\n observer.observe(el);\n }, [observer]);\n const click = useCallback((content: string, position: number) => {\n if (!isCurrent()) return;\n const index = Math.floor((position - 1) / EXPOSURE_SEGMENT_SIZE);\n const item = items.find((item) => item.id === content);\n const version = item?.version_id ?? item?.version?.id;\n b.click(content, { render_id: segmentID(index), surface: o.surface, position, version_id: version, language: base.language });\n }, [b, items, segmentID, o.surface, base.language, isCurrent]);\n return { render_id: renderId, track, click };\n}\n\ntype ObservedPlacement = { content_id: string; version_id?: string; position: number };\ntype ExposureSegment = {\n rendered: Map<string, ObservedPlacement>;\n visible: Map<string, ObservedPlacement>;\n renderedRevision: number;\n visibleRevision: number;\n renderedAt?: string;\n visibleAt?: string;\n};\nconst EXPOSURE_SEGMENT_SIZE = 32;\n"],"mappings":";;;;;;;;AAYA,IAAM,KAAQ,OAAoB;CAAE,OAAO,EAAE;CAAU,MAAM,EAAE,eAAe;CAAM,UAAU,EAAE;AAAQ,IAElG,IAA8B,CAAC,GAC/B,IAA0C,OAAO,OAAO,CAAC,CAAC;AAGhE,SAAS,EAAyB,GAA0B,GAA8B;CACxF,IAAM,IAAQ,SAAe;EAAE;EAAQ;CAAM,IAAI,CAAC,GAAQ,CAAK,CAAC,GAC1D,IAAU,EAA4B,CAAK;CAKjD,OAJA,SACE,EAAQ,UAAU,SACL;EAAE,EAAQ,UAAU;CAAM,IACtC,CAAC,CAAK,CAAC,GACH,QAAkB,EAAQ,YAAY,GAAO,CAAC,CAAK,CAAC;AAC7D;AAGA,SAAS,EAAoD,GAAuB;CAClF,IA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G,aAAa,EAAM,KAAK;CAAG,GAAG,CAAC,GAAU,CAAK,CAAC,GAC/F,QAAgB;EACd,KAAK,IAAM,KAAS,EAAM,SAAS,KAAK,GAAG,EAAE,cAAc,EAAU,CAAK,CAAC;EAC3E,aAAa;GAAE,KAAK,IAAM,KAAS,EAAM,SAAS,KAAK,GAAG,EAAE,YAAY,EAAU,CAAK,CAAC;EAAG;CAC7F,GAAG;EAAC;EAAG;EAAO;CAAS,CAAC,GAcjB;EAAE,WAAW;EAAU,OAbhB,GAAa,GAAiB,OAAsB,MAAuB;GACnF,AAAC,KAAO,MACZ,EAAoB,QAAQ,kBAAkB,GAC9C,EAAoB,QAAQ,mBAAmB,OAAO,CAAQ,GAC9D,EAAS,QAAQ,CAAE;EACrB,GAAG,CAAC,CAAQ,CAQkB;EAAO,OAPvB,GAAa,GAAiB,MAAqB;GAC/D,IAAI,CAAC,EAAU,GAAG;GAClB,IAAM,IAAQ,KAAK,OAAO,IAAW,KAAK,CAAqB,GACzD,IAAO,EAAM,MAAM,MAAS,EAAK,OAAO,CAAO,GAC/C,IAAU,GAAM,cAAc,GAAM,SAAS;GACnD,EAAE,MAAM,GAAS;IAAE,WAAW,EAAU,CAAK;IAAG,SAAS,EAAE;IAAS;IAAU,YAAY;IAAS,UAAU,EAAK;GAAS,CAAC;EAC9H,GAAG;GAAC;GAAG;GAAO;GAAW,EAAE;GAAS,EAAK;GAAU;EAAS,CACvB;CAAM;AAC7C;AAWA,IAAM,IAAwB"}
@@ -1,6 +1,6 @@
1
1
  import { ContentKitClient } from '../client/client.js';
2
2
  import { ContentKitError } from '../client/errors.js';
3
- import { ContentMemberships, ContentModel, Edge, EdgeInput, Group, GroupCard, GroupDetail, GroupInput, GroupUpdate, MemberRef, Membership, MergeReport, MyGroup, Name, Edit } from '../client/generated/wire.js';
3
+ import { ContentMemberships, ContentModel, Edge, EdgeInput, Group, GroupCard, GroupDetail, GroupInput, GroupUpdate, MemberRef, Membership, MergeReport, MyGroup, Name, NewEntity, Edit } from '../client/generated/wire.js';
4
4
  import { EntityImageSlot, MyEntityQuery } from '../client/entities.js';
5
5
  import { UseList } from './use-resource.js';
6
6
  export interface UseKinds {
@@ -32,7 +32,23 @@ export interface GroupFilter {
32
32
  sort?: GroupSort;
33
33
  /** Default 50, at most 200. */
34
34
  pageSize?: number;
35
+ /** Management: a canonical name, alias or slug containing this. */
36
+ query?: string;
37
+ /** Management: the deleted, restorable groups instead of active ones. */
38
+ deleted?: boolean;
35
39
  }
40
+ /** One numbered page of groups and every matching group's total. */
41
+ export interface UseGroupsPage {
42
+ items: GroupCard[];
43
+ total?: number;
44
+ loading: boolean;
45
+ error?: ContentKitError;
46
+ reload: () => void;
47
+ }
48
+ /** Page `page` (from 1) of active groups with the total. */
49
+ export declare function useGroupsPage(f: GroupFilter, page: number, o?: {
50
+ client?: ContentKitClient;
51
+ }): UseGroupsPage;
36
52
  /** Active groups with name, path, cover and count, a cursor page at a time. */
37
53
  export declare function useGroups(f?: GroupFilter, o?: {
38
54
  client?: ContentKitClient;
@@ -107,8 +123,8 @@ export interface UseContentGroups {
107
123
  error?: ContentKitError;
108
124
  saving: boolean;
109
125
  reload: () => void;
110
- /** Replaces the content's memberships, its versions' included, in these group kinds (every kind its kind joins when omitted). */
111
- set: (memberships: Membership[], kinds?: string[]) => Promise<ContentMemberships>;
126
+ /** Replaces the content's memberships, its versions' included, in these group kinds (every kind its kind joins when omitted); create links new names, creating entities of creatable kinds. */
127
+ set: (memberships: Membership[], kinds?: string[], create?: NewEntity[]) => Promise<ContentMemberships>;
112
128
  }
113
129
  export declare function useContentGroups(contentId: string | null | undefined, o?: {
114
130
  language?: string;