@openrails/contentkit-ui 0.85.1 → 0.87.0-rc.1

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 (211) hide show
  1. package/README.md +28 -7
  2. package/dist/client/beacons.d.ts +13 -4
  3. package/dist/client/beacons.js +14 -7
  4. package/dist/client/beacons.js.map +1 -1
  5. package/dist/client/client.d.ts +3 -0
  6. package/dist/client/client.js +29 -27
  7. package/dist/client/client.js.map +1 -1
  8. package/dist/client/codes.d.ts +6 -1
  9. package/dist/client/codes.js +4 -1
  10. package/dist/client/codes.js.map +1 -1
  11. package/dist/client/content/types.d.ts +4 -2
  12. package/dist/client/content/types.js.map +1 -1
  13. package/dist/client/discovery.js +3 -0
  14. package/dist/client/discovery.js.map +1 -1
  15. package/dist/client/errors.d.ts +6 -0
  16. package/dist/client/errors.js +6 -2
  17. package/dist/client/errors.js.map +1 -1
  18. package/dist/client/gallery.d.ts +3 -5
  19. package/dist/client/gallery.js +16 -20
  20. package/dist/client/gallery.js.map +1 -1
  21. package/dist/client/generated/error-codes.d.ts +1 -1
  22. package/dist/client/generated/error-codes.js +9 -1
  23. package/dist/client/generated/error-codes.js.map +1 -1
  24. package/dist/client/generated/routes.d.ts +29 -3
  25. package/dist/client/generated/routes.js +44 -3
  26. package/dist/client/generated/routes.js.map +1 -1
  27. package/dist/client/generated/wire.d.ts +60 -10
  28. package/dist/client/generated/wire.js.map +1 -1
  29. package/dist/client/index.d.ts +2 -1
  30. package/dist/client/media/queue.d.ts +4 -2
  31. package/dist/client/media/queue.js +18 -12
  32. package/dist/client/media/queue.js.map +1 -1
  33. package/dist/client/media/rules.d.ts +7 -1
  34. package/dist/client/media/rules.js +27 -21
  35. package/dist/client/media/rules.js.map +1 -1
  36. package/dist/client/media/windows.js +1 -1
  37. package/dist/client/media/windows.js.map +1 -1
  38. package/dist/client/stats.d.ts +32 -0
  39. package/dist/client/stats.js +35 -0
  40. package/dist/client/stats.js.map +1 -0
  41. package/dist/client/versions.d.ts +6 -4
  42. package/dist/client/versions.js +24 -26
  43. package/dist/client/versions.js.map +1 -1
  44. package/dist/client.js +30 -29
  45. package/dist/components/admin/content-manager.js +206 -206
  46. package/dist/components/admin/content-manager.js.map +1 -1
  47. package/dist/components/admin/group-manager.js +71 -70
  48. package/dist/components/admin/group-manager.js.map +1 -1
  49. package/dist/components/admin/media-item-panel.d.ts +24 -7
  50. package/dist/components/admin/media-item-panel.js +209 -197
  51. package/dist/components/admin/media-item-panel.js.map +1 -1
  52. package/dist/components/admin/poll-manager.js +25 -25
  53. package/dist/components/admin/stats-dashboard.d.ts +22 -0
  54. package/dist/components/admin/stats-dashboard.js +257 -0
  55. package/dist/components/admin/stats-dashboard.js.map +1 -0
  56. package/dist/components/content/card.d.ts +5 -3
  57. package/dist/components/content/card.js +155 -133
  58. package/dist/components/content/card.js.map +1 -1
  59. package/dist/components/content/download-button.d.ts +26 -0
  60. package/dist/components/content/download-button.js +51 -0
  61. package/dist/components/content/download-button.js.map +1 -0
  62. package/dist/components/content/editors.js +455 -427
  63. package/dist/components/content/editors.js.map +1 -1
  64. package/dist/components/content/grid.d.ts +8 -1
  65. package/dist/components/content/grid.js +153 -104
  66. package/dist/components/content/grid.js.map +1 -1
  67. package/dist/components/content/index.d.ts +4 -2
  68. package/dist/components/content/listing.d.ts +3 -1
  69. package/dist/components/content/listing.js +34 -34
  70. package/dist/components/content/listing.js.map +1 -1
  71. package/dist/components/content/paywall.d.ts +17 -5
  72. package/dist/components/content/paywall.js +115 -100
  73. package/dist/components/content/paywall.js.map +1 -1
  74. package/dist/components/content/reader-stats.d.ts +12 -0
  75. package/dist/components/content/reader-stats.js +47 -0
  76. package/dist/components/content/reader-stats.js.map +1 -0
  77. package/dist/components/groups/banner.js +33 -33
  78. package/dist/components/groups/directory.js +11 -11
  79. package/dist/components/groups/editor.js +293 -293
  80. package/dist/components/groups/editor.js.map +1 -1
  81. package/dist/components/groups/header.js +27 -27
  82. package/dist/components/groups/header.js.map +1 -1
  83. package/dist/components/groups/memberships.js +180 -180
  84. package/dist/components/groups/parts.d.ts +0 -2
  85. package/dist/components/groups/parts.js +9 -27
  86. package/dist/components/groups/parts.js.map +1 -1
  87. package/dist/components/media-folder-editor.js +239 -189
  88. package/dist/components/media-folder-editor.js.map +1 -1
  89. package/dist/components/media-gallery.d.ts +1 -4
  90. package/dist/components/media-gallery.js +19 -34
  91. package/dist/components/media-gallery.js.map +1 -1
  92. package/dist/components/notifications.js +17 -17
  93. package/dist/components/slot-upload.d.ts +2 -2
  94. package/dist/components/slot-upload.js +84 -79
  95. package/dist/components/slot-upload.js.map +1 -1
  96. package/dist/components/social/bans.js +34 -34
  97. package/dist/components/social/comments.js +1 -1
  98. package/dist/components/social/comments.js.map +1 -1
  99. package/dist/components/social/engagement.d.ts +2 -1
  100. package/dist/components/social/engagement.js +5 -3
  101. package/dist/components/social/engagement.js.map +1 -1
  102. package/dist/components/social/moderation.js +52 -48
  103. package/dist/components/social/moderation.js.map +1 -1
  104. package/dist/components/video-player.d.ts +2 -0
  105. package/dist/components/video-player.js +318 -314
  106. package/dist/components/video-player.js.map +1 -1
  107. package/dist/i18n/context.d.ts +2 -0
  108. package/dist/i18n/context.js +23 -5
  109. package/dist/i18n/context.js.map +1 -1
  110. package/dist/index.d.ts +2 -1
  111. package/dist/index.js +13 -10
  112. package/dist/locales/admin/de.js +27 -0
  113. package/dist/locales/admin/de.js.map +1 -1
  114. package/dist/locales/admin/en.d.ts +27 -0
  115. package/dist/locales/admin/en.js +27 -0
  116. package/dist/locales/admin/en.js.map +1 -1
  117. package/dist/locales/admin/es.js +27 -0
  118. package/dist/locales/admin/es.js.map +1 -1
  119. package/dist/locales/admin/ja.js +27 -0
  120. package/dist/locales/admin/ja.js.map +1 -1
  121. package/dist/locales/admin/ko.js +27 -0
  122. package/dist/locales/admin/ko.js.map +1 -1
  123. package/dist/locales/admin/zh.js +27 -0
  124. package/dist/locales/admin/zh.js.map +1 -1
  125. package/dist/locales/content/de.js +6 -0
  126. package/dist/locales/content/de.js.map +1 -1
  127. package/dist/locales/content/en.d.ts +6 -0
  128. package/dist/locales/content/en.js +6 -0
  129. package/dist/locales/content/en.js.map +1 -1
  130. package/dist/locales/content/es.js +6 -0
  131. package/dist/locales/content/es.js.map +1 -1
  132. package/dist/locales/content/ja.js +6 -0
  133. package/dist/locales/content/ja.js.map +1 -1
  134. package/dist/locales/content/ko.js +6 -0
  135. package/dist/locales/content/ko.js.map +1 -1
  136. package/dist/locales/content/zh.js +6 -0
  137. package/dist/locales/content/zh.js.map +1 -1
  138. package/dist/locales/de.js +14 -2
  139. package/dist/locales/de.js.map +1 -1
  140. package/dist/locales/discovery/de.js +3 -0
  141. package/dist/locales/discovery/de.js.map +1 -1
  142. package/dist/locales/discovery/en.d.ts +3 -0
  143. package/dist/locales/discovery/en.js +3 -0
  144. package/dist/locales/discovery/en.js.map +1 -1
  145. package/dist/locales/discovery/es.js +3 -0
  146. package/dist/locales/discovery/es.js.map +1 -1
  147. package/dist/locales/discovery/ja.js +3 -0
  148. package/dist/locales/discovery/ja.js.map +1 -1
  149. package/dist/locales/discovery/ko.js +3 -0
  150. package/dist/locales/discovery/ko.js.map +1 -1
  151. package/dist/locales/discovery/zh.js +3 -0
  152. package/dist/locales/discovery/zh.js.map +1 -1
  153. package/dist/locales/en.d.ts +50 -2
  154. package/dist/locales/en.js +14 -2
  155. package/dist/locales/en.js.map +1 -1
  156. package/dist/locales/es.js +14 -2
  157. package/dist/locales/es.js.map +1 -1
  158. package/dist/locales/ja.js +14 -2
  159. package/dist/locales/ja.js.map +1 -1
  160. package/dist/locales/ko.js +14 -2
  161. package/dist/locales/ko.js.map +1 -1
  162. package/dist/locales/zh.js +14 -2
  163. package/dist/locales/zh.js.map +1 -1
  164. package/dist/react/admin.js +22 -23
  165. package/dist/react/admin.js.map +1 -1
  166. package/dist/react/canonical.d.ts +4 -3
  167. package/dist/react/canonical.js +34 -33
  168. package/dist/react/canonical.js.map +1 -1
  169. package/dist/react/comments.d.ts +1 -1
  170. package/dist/react/comments.js +3 -2
  171. package/dist/react/comments.js.map +1 -1
  172. package/dist/react/contents.js +144 -144
  173. package/dist/react/contents.js.map +1 -1
  174. package/dist/react/context.d.ts +1 -1
  175. package/dist/react/context.js.map +1 -1
  176. package/dist/react/detail.d.ts +12 -6
  177. package/dist/react/detail.js +31 -24
  178. package/dist/react/detail.js.map +1 -1
  179. package/dist/react/discovery.d.ts +11 -0
  180. package/dist/react/discovery.js +49 -30
  181. package/dist/react/discovery.js.map +1 -1
  182. package/dist/react/engagement.d.ts +6 -2
  183. package/dist/react/engagement.js +2 -6
  184. package/dist/react/engagement.js.map +1 -1
  185. package/dist/react/folder.d.ts +7 -2
  186. package/dist/react/folder.js +165 -147
  187. package/dist/react/folder.js.map +1 -1
  188. package/dist/react/groups.d.ts +0 -1
  189. package/dist/react/groups.js +13 -12
  190. package/dist/react/groups.js.map +1 -1
  191. package/dist/react/index.d.ts +6 -4
  192. package/dist/react/location.d.ts +11 -0
  193. package/dist/react/location.js +18 -0
  194. package/dist/react/location.js.map +1 -0
  195. package/dist/react/public.d.ts +8 -0
  196. package/dist/react/public.js +32 -27
  197. package/dist/react/public.js.map +1 -1
  198. package/dist/react/stats.d.ts +24 -0
  199. package/dist/react/stats.js +28 -0
  200. package/dist/react/stats.js.map +1 -0
  201. package/dist/react/use-resource.js +8 -7
  202. package/dist/react/use-resource.js.map +1 -1
  203. package/dist/react/versions.d.ts +25 -5
  204. package/dist/react/versions.js +61 -40
  205. package/dist/react/versions.js.map +1 -1
  206. package/dist/react.js +26 -24
  207. package/dist/styles.css +1 -1
  208. package/dist/urls/index.d.ts +35 -10
  209. package/dist/urls.js +100 -70
  210. package/dist/urls.js.map +1 -1
  211. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"groups.js","names":[],"sources":["../../src/react/groups.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport type { ContentKitClient } from \"../client/client.js\";\nimport type { ContentKitError } from \"../client/errors.js\";\nimport type {\n ContentMemberships,\n ContentModel,\n Edge,\n EdgeInput,\n Group,\n GroupCard,\n GroupDetail,\n GroupInput,\n GroupUpdate,\n MemberRef,\n Membership,\n MergeReport,\n MyGroup,\n Name,\n Edit,\n} from \"../client/generated/wire.js\";\nimport type { GroupImageSlot, MyGroupQuery } from \"../client/groups.js\";\nimport { useGuarded } from \"./context.js\";\nimport { keyOf, useContentScope, useList, useResource, type UseList } from \"./use-resource.js\";\n\nexport interface UseKinds {\n /** null until it loads (or when it fails). */\n kinds: ContentModel | null;\n loading: boolean;\n error?: ContentKitError;\n reload: () => void;\n}\n\n/** The site's content model (GET /v1/kinds): languages, tiers, kinds, group kinds and content filters; one read per client. */\nexport function useKinds(o: { client?: ContentKitClient } = {}): UseKinds {\n const { client, store } = useContentScope(o.client);\n const r = useResource<ContentModel>(store, keyOf(\"kinds\"), { type: \"kinds\" }, (s) => client.kinds(s));\n return { kinds: r.data ?? null, loading: !r.data && (r.loading || !r.loaded), error: r.error, reload: r.reload };\n}\n\nexport type GroupSort = \"name\" | \"count\" | \"newest\";\n\nexport interface GroupFilter {\n kind?: string;\n /** Children of this group. */\n parent?: string;\n /** Groups scoped by this group (characters of a series). */\n scope?: string;\n slug?: string;\n /** Sort names starting with this letter (a-z), or with anything else (\"#\"). */\n letter?: string;\n /** Names, counts and paths in this language; default the provider's. */\n language?: string;\n /** Count contents of this kind only. */\n contentKind?: string;\n /** Default \"name\". */\n sort?: GroupSort;\n /** Default 50, at most 200. */\n pageSize?: number;\n}\n\n/** Active groups with name, path, cover and count, a cursor page at a time. */\nexport function useGroups(f: GroupFilter = {}, o: { client?: ContentKitClient } = {}): UseList<GroupCard> {\n const { client, store, scope, language: provided } = useContentScope(o.client);\n const language = f.language ?? provided;\n const size = f.pageSize ?? 50;\n return useList(\n store,\n keyOf(\"groups\", scope, f.kind, f.parent, f.scope, f.slug, f.letter, language, f.contentKind, f.sort, size),\n { type: \"groups\" },\n async (cursor, signal) => {\n const page = await client.groups.list(\n { kind: f.kind, parent: f.parent, scope: f.scope, slug: f.slug, letter: f.letter, language, content_kind: f.contentKind, sort: f.sort, cursor: cursor as string | undefined, limit: size },\n signal,\n );\n return { items: page.groups, next: page.next_cursor ?? null };\n },\n );\n}\n\nexport interface UseGroup {\n /** The group as its page shows it; null before create and while loading. A merged group reads as its survivor. */\n group: GroupDetail | null;\n /** What this hook deleted, until restored: reads no longer answer for it. */\n deleted: Group | null;\n loading: boolean;\n error?: ContentKitError;\n /** Writes in flight. */\n saving: boolean;\n reload: () => void;\n /** Creates the group; the hook then shows it. */\n create: (input: GroupInput) => Promise<Group>;\n update: (patch: GroupUpdate) => Promise<Group>;\n remove: () => Promise<Group>;\n restore: () => Promise<Group>;\n /** Replaces (\"set\"), adds or removes names and aliases; a new canonical name demotes the old one to an alias. */\n names: (op: \"set\" | \"add\" | \"remove\", names: Name[]) => Promise<Name[]>;\n edges: (op: \"add\" | \"remove\", edges: EdgeInput[]) => Promise<Edge[]>;\n /** Merges the group into another of its kind; the hook then shows the survivor. */\n merge: (into: string) => Promise<MergeReport>;\n /** Uploads an image (cropped by edit) and selects it as the cover or avatar. */\n uploadImage: (slot: GroupImageSlot, file: Blob & { name?: string }, o?: { wait?: boolean; edit?: Edit }) => Promise<Group>;\n /** Shows the images uploaded here until their renditions exist. */\n previews: Partial<Record<GroupImageSlot, string>>;\n}\n\n/** One group: its page for anyone; create, edit, names, edges, cover, merge, delete and restore for staff (root:groups:write). null creates. */\nexport function useGroup(id: string | null | undefined, o: { language?: string; initial?: GroupDetail; client?: ContentKitClient } = {}): UseGroup {\n const { client, store, scope, language: provided } = useContentScope(o.client);\n const language = o.language ?? provided;\n const [created, setCreated] = useState<string | null>(null);\n const [merged, setMerged] = useState<string | null>(null);\n const [deleted, setDeleted] = useState<Group | null>(null);\n const gid = merged ?? id ?? created;\n useEffect(() => {\n setMerged(null);\n setDeleted(null);\n }, [id]);\n const key = gid && !deleted ? keyOf(\"group\", scope, gid, language) : null;\n const r = useResource<GroupDetail>(store, key, { type: \"group\", id: gid ?? undefined }, (s) => client.groups.get(gid!, language, s), { initial: o.initial });\n const guarded = useGuarded();\n const [inflight, setInflight] = useState(0);\n const run = useCallback(\n async <T>(fn: () => Promise<T>): Promise<T> => {\n setInflight((n) => n + 1);\n try {\n return await guarded(fn);\n } finally {\n setInflight((n) => n - 1);\n }\n },\n [guarded],\n );\n const need = useCallback(() => {\n if (!gid) throw new Error(\"contentkit-ui: create the group first\");\n return gid;\n }, [gid]);\n\n const [previews, setPreviews] = useState<Partial<Record<GroupImageSlot, string>>>({});\n const blobs = useRef<string[]>([]);\n useEffect(() => {\n const urls = blobs.current;\n return () => urls.forEach((u) => URL.revokeObjectURL(u));\n }, []);\n\n const group = r.data ?? null;\n return {\n group: deleted ? null : group,\n deleted,\n loading: !!key && (r.loading || (!r.loaded && o.initial === undefined)),\n error: deleted ? undefined : r.error,\n saving: inflight > 0,\n reload: r.reload,\n create: useCallback(\n (input: GroupInput) =>\n run(async () => {\n const [g] = await client.groups.create([input]);\n setCreated(g!.id);\n return g!;\n }),\n [client, run],\n ),\n update: useCallback((patch: GroupUpdate) => run(() => client.groups.update(need(), patch)), [client, run, need]),\n remove: useCallback(\n () =>\n run(async () => {\n const g = await client.groups.remove(need());\n setDeleted(g);\n return g;\n }),\n [client, run, need],\n ),\n restore: useCallback(\n () =>\n run(async () => {\n const g = await client.groups.update(need(), { state: \"active\" });\n setDeleted(null);\n return g;\n }),\n [client, run, need],\n ),\n names: useCallback((op: \"set\" | \"add\" | \"remove\", names: Name[]) => run(() => client.groups.names(need(), op, names)), [client, run, need]),\n edges: useCallback((op: \"add\" | \"remove\", edges: EdgeInput[]) => run(() => client.groups.edges(need(), op, edges)), [client, run, need]),\n merge: useCallback(\n (into: string) =>\n run(async () => {\n const report = await client.groups.merge(need(), into);\n setMerged(report.into);\n return report;\n }),\n [client, run, need],\n ),\n uploadImage: useCallback(\n (slot: GroupImageSlot, file: Blob & { name?: string }, u: { wait?: boolean; edit?: Edit } = {}) =>\n run(async () => {\n const kind = group?.kind;\n if (!kind) throw new Error(\"contentkit-ui: load the group first\");\n const g = await client.groups.uploadImage({ kind, id: need() }, slot, file, u);\n // A cropped upload's renditions show the crop; until then the file shows uncropped.\n if (typeof URL.createObjectURL === \"function\" && !u.edit) {\n const url = URL.createObjectURL(file);\n blobs.current.push(url);\n setPreviews((p) => ({ ...p, [slot]: url }));\n }\n return g;\n }),\n [client, run, need, group?.kind],\n ),\n previews: { cover: group?.cover?.image ? previews.cover : undefined, avatar: group?.avatar?.image ? previews.avatar : undefined },\n };\n}\n\n/** Groups the signed-in person owns, edits or belongs to, a cursor page at a time; nothing signed out. */\nexport function useMyGroups(q: Omit<MyGroupQuery, \"cursor\" | \"limit\"> & { pageSize?: number } = {}, o: { client?: ContentKitClient } = {}): UseList<MyGroup> {\n const { client, store, scope, viewer, language } = useContentScope(o.client);\n const { pageSize, ...rest } = q;\n const query = { language, ...rest };\n return useList(store, viewer === null ? null : keyOf(\"groups-mine\", scope, query, pageSize), { type: \"groups-mine\" }, async (cursor, signal) => {\n const page = await client.groups.mine({ ...query, cursor: cursor as string | undefined, limit: pageSize }, signal);\n return { items: page.groups, next: page.next_cursor ?? null };\n });\n}\n\n/** A membership with a stable id: (group, content, version, role) is its identity. */\nexport type Member = Membership & { id: string };\n\nexport const memberId = (m: Membership): string => [m.group_id ?? \"\", m.content_id ?? \"\", m.version_id ?? \"\", m.role ?? \"\"].join(\"|\");\n\nexport interface UseGroupMembers extends UseList<Member> {\n saving: boolean;\n /** Adds members, or updates their role's position, window and state. */\n add: (members: Membership[]) => Promise<number>;\n remove: (members: Membership[]) => Promise<number>;\n /** Orders an ordered group: the listed members first, in list order. */\n reorder: (members: MemberRef[]) => Promise<number>;\n}\n\n/** Staff: a group's memberships in member order, with writes. */\nexport function useGroupMembers(id: string | null | undefined, o: { pageSize?: number; client?: ContentKitClient } = {}): UseGroupMembers {\n const { client, store, scope } = useContentScope(o.client);\n const size = o.pageSize ?? 50;\n const list = useList<Member>(store, id ? keyOf(\"group-members\", scope, id, size) : null, { type: \"group-members\", id: id ?? undefined }, async (cursor, signal) => {\n const page = await client.groups.members(id!, { cursor: cursor as string | undefined, limit: size }, signal);\n return { items: page.members.map((m) => ({ ...m, id: memberId(m) })), next: page.next_cursor ?? null };\n });\n const guarded = useGuarded();\n const [inflight, setInflight] = useState(0);\n const write = useCallback(\n async (fn: (gid: string) => Promise<{ count: number }>) => {\n if (!id) throw new Error(\"contentkit-ui: no group\");\n setInflight((n) => n + 1);\n try {\n return (await guarded(() => fn(id))).count;\n } finally {\n setInflight((n) => n - 1);\n }\n },\n [id, guarded],\n );\n return {\n ...list,\n saving: inflight > 0,\n add: useCallback((ms: Membership[]) => write((g) => client.groups.addMembers(g, ms)), [client, write]),\n remove: useCallback((ms: Membership[]) => write((g) => client.groups.removeMembers(g, ms)), [client, write]),\n reorder: useCallback((ms: MemberRef[]) => write((g) => client.groups.reorder(g, ms)), [client, write]),\n };\n}\n\nexport interface UseContentGroups {\n memberships: Membership[];\n /** The groups the memberships name. */\n groups: ReadonlyMap<string, GroupCard>;\n loading: boolean;\n error?: ContentKitError;\n saving: boolean;\n reload: () => void;\n /** Replaces the content's memberships, its versions' included, in these group kinds (every kind its kind joins when omitted). */\n set: (memberships: Membership[], kinds?: string[]) => Promise<ContentMemberships>;\n}\n\n/** Staff: one content's memberships, its versions' included, and their replacement. */\nexport function useContentGroups(contentId: string | null | undefined, o: { language?: string; client?: ContentKitClient } = {}): UseContentGroups {\n const { client, store, scope, language: provided } = useContentScope(o.client);\n const language = o.language ?? provided;\n const key = contentId ? keyOf(\"group-memberships\", scope, contentId, language) : null;\n const r = useResource<ContentMemberships>(store, key, { type: \"group-memberships\", id: contentId ?? undefined }, (s) => client.groups.ofContent(contentId!, language, s));\n const guarded = useGuarded();\n const [inflight, setInflight] = useState(0);\n const set = useCallback(\n async (memberships: Membership[], kinds?: string[]) => {\n if (!contentId) throw new Error(\"contentkit-ui: no content\");\n setInflight((n) => n + 1);\n try {\n const out = await guarded(() => client.groups.setOfContent(contentId, { kinds, memberships }, language));\n if (key) store.set(key, out);\n return out;\n } finally {\n setInflight((n) => n - 1);\n }\n },\n [client, contentId, language, guarded, store, key],\n );\n const groups = useMemo(() => new Map((r.data?.groups ?? []).map((g) => [g.id, g])), [r.data]);\n return {\n memberships: r.data?.memberships ?? [],\n groups,\n loading: !!key && (r.loading || !r.loaded),\n error: r.error,\n saving: inflight > 0,\n reload: r.reload,\n set,\n };\n}\n"],"mappings":";;;;AAiCA,SAAgB,EAAS,IAAmC,CAAC,GAAa;CACxE,IAAM,EAAE,WAAQ,aAAU,EAAgB,EAAE,MAAM,GAC5C,IAAI,EAA0B,GAAO,EAAM,OAAO,GAAG,EAAE,MAAM,QAAQ,IAAI,MAAM,EAAO,MAAM,CAAC,CAAC;CACpG,OAAO;EAAE,OAAO,EAAE,QAAQ;EAAM,SAAS,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE;EAAS,OAAO,EAAE;EAAO,QAAQ,EAAE;CAAO;AACjH;AAwBA,SAAgB,EAAU,IAAiB,CAAC,GAAG,IAAmC,CAAC,GAAuB;CACxG,IAAM,EAAE,WAAQ,UAAO,UAAO,UAAU,MAAa,EAAgB,EAAE,MAAM,GACvE,IAAW,EAAE,YAAY,GACzB,IAAO,EAAE,YAAY;CAC3B,OAAO,EACL,GACA,EAAM,UAAU,GAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAU,EAAE,aAAa,EAAE,MAAM,CAAI,GACzG,EAAE,MAAM,SAAS,GACjB,OAAO,GAAQ,MAAW;EACxB,IAAM,IAAO,MAAM,EAAO,OAAO,KAC/B;GAAE,MAAM,EAAE;GAAM,QAAQ,EAAE;GAAQ,OAAO,EAAE;GAAO,MAAM,EAAE;GAAM,QAAQ,EAAE;GAAQ;GAAU,cAAc,EAAE;GAAa,MAAM,EAAE;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CACvG;AACF;AAeA,SAAgB,EAAiB,GAAsC,IAAsD,CAAC,GAAqB;CACjJ,IAAM,EAAE,WAAQ,UAAO,UAAO,UAAU,MAAa,EAAgB,EAAE,MAAM,GACvE,IAAW,EAAE,YAAY,GACzB,IAAM,IAAY,EAAM,qBAAqB,GAAO,GAAW,CAAQ,IAAI,MAC3E,IAAI,EAAgC,GAAO,GAAK;EAAE,MAAM;EAAqB,IAAI,KAAa,KAAA;CAAU,IAAI,MAAM,EAAO,OAAO,UAAU,GAAY,GAAU,CAAC,CAAC,GAClK,IAAU,EAAW,GACrB,CAAC,GAAU,KAAe,EAAS,CAAC,GACpC,IAAM,EACV,OAAO,GAA2B,MAAqB;EACrD,IAAI,CAAC,GAAW,MAAU,MAAM,2BAA2B;EAC3D,GAAa,MAAM,IAAI,CAAC;EACxB,IAAI;GACF,IAAM,IAAM,MAAM,QAAc,EAAO,OAAO,aAAa,GAAW;IAAE;IAAO;GAAY,GAAG,CAAQ,CAAC;GAEvG,OADI,KAAK,EAAM,IAAI,GAAK,CAAG,GACpB;EACT,UAAU;GACR,GAAa,MAAM,IAAI,CAAC;EAC1B;CACF,GACA;EAAC;EAAQ;EAAW;EAAU;EAAS;EAAO;CAAG,CACnD,GACM,IAAS,QAAc,IAAI,KAAK,EAAE,MAAM,UAAU,CAAC,EAAA,CAAG,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;CAC5F,OAAO;EACL,aAAa,EAAE,MAAM,eAAe,CAAC;EACrC;EACA,SAAS,CAAC,CAAC,MAAQ,EAAE,WAAW,CAAC,EAAE;EACnC,OAAO,EAAE;EACT,QAAQ,IAAW;EACnB,QAAQ,EAAE;EACV;CACF;AACF"}
1
+ {"version":3,"file":"groups.js","names":[],"sources":["../../src/react/groups.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport type { ContentKitClient } from \"../client/client.js\";\nimport type { ContentKitError } from \"../client/errors.js\";\nimport type {\n ContentMemberships,\n ContentModel,\n Edge,\n EdgeInput,\n Group,\n GroupCard,\n GroupDetail,\n GroupInput,\n GroupUpdate,\n MemberRef,\n Membership,\n MergeReport,\n MyGroup,\n Name,\n Edit,\n} from \"../client/generated/wire.js\";\nimport type { GroupImageSlot, MyGroupQuery } from \"../client/groups.js\";\nimport { useGuarded } from \"./context.js\";\nimport { keyOf, useContentScope, useList, useResource, type UseList } from \"./use-resource.js\";\n\nexport interface UseKinds {\n /** null until it loads (or when it fails). */\n kinds: ContentModel | null;\n loading: boolean;\n error?: ContentKitError;\n reload: () => void;\n}\n\n/** The site's content model (GET /v1/kinds): languages, tiers, kinds, group kinds and content filters; one read per client. */\nexport function useKinds(o: { client?: ContentKitClient } = {}): UseKinds {\n const { client, store } = useContentScope(o.client);\n const r = useResource<ContentModel>(store, keyOf(\"kinds\"), { type: \"kinds\" }, (s) => client.kinds(s));\n return { kinds: r.data ?? null, loading: !r.data && (r.loading || !r.loaded), error: r.error, reload: r.reload };\n}\n\nexport type GroupSort = \"name\" | \"count\" | \"newest\";\n\nexport interface GroupFilter {\n kind?: string;\n /** Children of this group. */\n parent?: string;\n /** Groups scoped by this group (characters of a series). */\n scope?: string;\n slug?: string;\n /** Sort names starting with this letter (a-z), or with anything else (\"#\"). */\n letter?: string;\n /** Names, counts and paths in this language; default the provider's. */\n language?: string;\n /** Count contents of this kind only. */\n contentKind?: string;\n /** Default \"name\". */\n sort?: GroupSort;\n /** Default 50, at most 200. */\n pageSize?: number;\n}\n\n/** Active groups with name, path, cover and count, a cursor page at a time. */\nexport function useGroups(f: GroupFilter = {}, o: { client?: ContentKitClient } = {}): UseList<GroupCard> {\n const { client, store, scope, language: provided } = useContentScope(o.client);\n const language = f.language ?? provided;\n const size = f.pageSize ?? 50;\n return useList(\n store,\n keyOf(\"groups\", scope, f.kind, f.parent, f.scope, f.slug, f.letter, language, f.contentKind, f.sort, size),\n { type: \"groups\" },\n async (cursor, signal) => {\n const page = await client.groups.list(\n { kind: f.kind, parent: f.parent, scope: f.scope, slug: f.slug, letter: f.letter, language, content_kind: f.contentKind, sort: f.sort, cursor: cursor as string | undefined, limit: size },\n signal,\n );\n return { items: page.groups, next: page.next_cursor ?? null };\n },\n );\n}\n\nexport interface UseGroup {\n /** The group as its page shows it; null before create and while loading. A merged group reads as its survivor. */\n group: GroupDetail | null;\n /** What this hook deleted, until restored: reads no longer answer for it. */\n deleted: Group | null;\n loading: boolean;\n error?: ContentKitError;\n /** Writes in flight. */\n saving: boolean;\n reload: () => void;\n /** Creates the group; the hook then shows it. */\n create: (input: GroupInput) => Promise<Group>;\n update: (patch: GroupUpdate) => Promise<Group>;\n remove: () => Promise<Group>;\n restore: () => Promise<Group>;\n /** Replaces (\"set\"), adds or removes names and aliases; a new canonical name demotes the old one to an alias. */\n names: (op: \"set\" | \"add\" | \"remove\", names: Name[]) => Promise<Name[]>;\n edges: (op: \"add\" | \"remove\", edges: EdgeInput[]) => Promise<Edge[]>;\n /** Merges the group into another of its kind; the hook then shows the survivor. */\n merge: (into: string) => Promise<MergeReport>;\n /** Uploads an image (cropped by edit) and selects it as the cover or avatar. */\n uploadImage: (slot: GroupImageSlot, file: Blob & { name?: string }, o?: { wait?: boolean; edit?: Edit }) => Promise<Group>;\n /** Shows the images uploaded here until their renditions exist. */\n previews: Partial<Record<GroupImageSlot, string>>;\n}\n\n/** One group: its page for anyone; create, edit, names, edges, cover, merge, delete and restore for staff (root:groups:write). null creates. */\nexport function useGroup(id: string | null | undefined, o: { language?: string; initial?: GroupDetail; client?: ContentKitClient } = {}): UseGroup {\n const { client, store, scope, language: provided } = useContentScope(o.client);\n const language = o.language ?? provided;\n const [created, setCreated] = useState<string | null>(null);\n const [merged, setMerged] = useState<string | null>(null);\n const [deleted, setDeleted] = useState<Group | null>(null);\n const gid = merged ?? id ?? created;\n useEffect(() => {\n setMerged(null);\n setDeleted(null);\n }, [id]);\n const key = gid && !deleted ? keyOf(\"group\", scope, gid, language) : null;\n const r = useResource<GroupDetail>(store, key, { type: \"group\", id: gid ?? undefined }, (s) => client.groups.get(gid!, language, s), { initial: o.initial });\n const guarded = useGuarded();\n const [inflight, setInflight] = useState(0);\n const run = useCallback(\n async <T>(fn: () => Promise<T>): Promise<T> => {\n setInflight((n) => n + 1);\n try {\n return await guarded(fn);\n } finally {\n setInflight((n) => n - 1);\n }\n },\n [guarded],\n );\n const need = useCallback(() => {\n if (!gid) throw new Error(\"contentkit-ui: create the group first\");\n return gid;\n }, [gid]);\n\n const [previews, setPreviews] = useState<Partial<Record<GroupImageSlot, string>>>({});\n const blobs = useRef<string[]>([]);\n useEffect(() => {\n const urls = blobs.current;\n return () => urls.forEach((u) => URL.revokeObjectURL(u));\n }, []);\n\n const group = r.data ?? null;\n return {\n group: deleted ? null : group,\n deleted,\n loading: !!key && (r.loading || (!r.loaded && o.initial === undefined)),\n error: deleted ? undefined : r.error,\n saving: inflight > 0,\n reload: r.reload,\n create: useCallback(\n (input: GroupInput) =>\n run(async () => {\n const [g] = await client.groups.create([input]);\n setCreated(g!.id);\n return g!;\n }),\n [client, run],\n ),\n update: useCallback((patch: GroupUpdate) => run(() => client.groups.update(need(), patch)), [client, run, need]),\n remove: useCallback(\n () =>\n run(async () => {\n const g = await client.groups.remove(need());\n setDeleted(g);\n return g;\n }),\n [client, run, need],\n ),\n restore: useCallback(\n () =>\n run(async () => {\n const g = await client.groups.update(need(), { state: \"active\" });\n setDeleted(null);\n return g;\n }),\n [client, run, need],\n ),\n names: useCallback((op: \"set\" | \"add\" | \"remove\", names: Name[]) => run(() => client.groups.names(need(), op, names)), [client, run, need]),\n edges: useCallback((op: \"add\" | \"remove\", edges: EdgeInput[]) => run(() => client.groups.edges(need(), op, edges)), [client, run, need]),\n merge: useCallback(\n (into: string) =>\n run(async () => {\n const report = await client.groups.merge(need(), into);\n setMerged(report.into);\n return report;\n }),\n [client, run, need],\n ),\n uploadImage: useCallback(\n (slot: GroupImageSlot, file: Blob & { name?: string }, u: { wait?: boolean; edit?: Edit } = {}) =>\n run(async () => {\n const kind = group?.kind;\n if (!kind) throw new Error(\"contentkit-ui: load the group first\");\n const g = await client.groups.uploadImage({ kind, id: need() }, slot, file, u);\n // A cropped upload's renditions show the crop; until then the file shows uncropped.\n if (typeof URL.createObjectURL === \"function\" && !u.edit) {\n const url = URL.createObjectURL(file);\n blobs.current.push(url);\n setPreviews((p) => ({ ...p, [slot]: url }));\n }\n return g;\n }),\n [client, run, need, group?.kind],\n ),\n previews: { cover: group?.cover?.image ? previews.cover : undefined, avatar: group?.avatar?.image ? previews.avatar : undefined },\n };\n}\n\n/** Groups the signed-in person owns, edits or belongs to, a cursor page at a time; nothing signed out. */\nexport function useMyGroups(q: Omit<MyGroupQuery, \"cursor\" | \"limit\"> & { pageSize?: number } = {}, o: { client?: ContentKitClient } = {}): UseList<MyGroup> {\n const { client, store, scope, viewer, language } = useContentScope(o.client);\n const { pageSize, ...rest } = q;\n const query = { language, ...rest };\n return useList(store, viewer === null ? null : keyOf(\"groups-mine\", scope, query, pageSize), { type: \"groups-mine\" }, async (cursor, signal) => {\n const page = await client.groups.mine({ ...query, cursor: cursor as string | undefined, limit: pageSize }, signal);\n return { items: page.groups, next: page.next_cursor ?? null };\n });\n}\n\n/** A membership with a stable id: (group, content, version, role) is its identity. */\nexport type Member = Membership & { id: string };\n\nexport const memberId = (m: Membership): string => [m.group_id ?? \"\", m.content_id ?? \"\", m.version_id ?? \"\", m.role ?? \"\"].join(\"|\");\n\nexport interface UseGroupMembers extends UseList<Member> {\n saving: boolean;\n /** Adds members, or updates their role's position, window and state. */\n add: (members: Membership[]) => Promise<number>;\n remove: (members: Membership[]) => Promise<number>;\n /** Orders an ordered group: the listed members first, in list order. */\n reorder: (members: MemberRef[]) => Promise<number>;\n}\n\n/** Staff: a group's memberships in member order, with writes. */\nexport function useGroupMembers(id: string | null | undefined, o: { pageSize?: number; client?: ContentKitClient } = {}): UseGroupMembers {\n const { client, store, scope } = useContentScope(o.client);\n const size = o.pageSize ?? 50;\n const list = useList<Member>(store, id ? keyOf(\"group-members\", scope, id, size) : null, { type: \"group-members\", id: id ?? undefined }, async (cursor, signal) => {\n const page = await client.groups.members(id!, { cursor: cursor as string | undefined, limit: size }, signal);\n return { items: page.members.map((m) => ({ ...m, id: memberId(m) })), next: page.next_cursor ?? null };\n });\n const guarded = useGuarded();\n const [inflight, setInflight] = useState(0);\n const write = useCallback(\n async (fn: (gid: string) => Promise<{ count: number }>) => {\n if (!id) throw new Error(\"contentkit-ui: no group\");\n setInflight((n) => n + 1);\n try {\n return (await guarded(() => fn(id))).count;\n } finally {\n setInflight((n) => n - 1);\n }\n },\n [id, guarded],\n );\n return {\n ...list,\n saving: inflight > 0,\n add: useCallback((ms: Membership[]) => write((g) => client.groups.addMembers(g, ms)), [client, write]),\n remove: useCallback((ms: Membership[]) => write((g) => client.groups.removeMembers(g, ms)), [client, write]),\n reorder: useCallback((ms: MemberRef[]) => write((g) => client.groups.reorder(g, ms)), [client, write]),\n };\n}\n\nexport interface UseContentGroups {\n memberships: Membership[];\n /** The groups the memberships name. */\n groups: ReadonlyMap<string, GroupCard>;\n loading: boolean;\n error?: ContentKitError;\n saving: boolean;\n reload: () => void;\n /** Replaces the content's memberships, its versions' included, in these group kinds (every kind its kind joins when omitted). */\n set: (memberships: Membership[], kinds?: string[]) => Promise<ContentMemberships>;\n}\n\n/** Staff: one content's memberships, its versions' included, and their replacement. */\nconst NO_MEMBERSHIPS: Membership[] = [];\n\nexport function useContentGroups(contentId: string | null | undefined, o: { language?: string; client?: ContentKitClient } = {}): UseContentGroups {\n const { client, store, scope, language: provided } = useContentScope(o.client);\n const language = o.language ?? provided;\n const key = contentId ? keyOf(\"group-memberships\", scope, contentId, language) : null;\n const r = useResource<ContentMemberships>(store, key, { type: \"group-memberships\", id: contentId ?? undefined }, (s) => client.groups.ofContent(contentId!, language, s));\n const guarded = useGuarded();\n const [inflight, setInflight] = useState(0);\n const set = useCallback(\n async (memberships: Membership[], kinds?: string[]) => {\n if (!contentId) throw new Error(\"contentkit-ui: no content\");\n setInflight((n) => n + 1);\n try {\n const out = await guarded(() => client.groups.setOfContent(contentId, { kinds, memberships }, language));\n if (key) store.set(key, out);\n return out;\n } finally {\n setInflight((n) => n - 1);\n }\n },\n [client, contentId, language, guarded, store, key],\n );\n const groups = useMemo(() => new Map((r.data?.groups ?? []).map((g) => [g.id, g])), [r.data]);\n // Stable while loading or failed: effects keyed on it must not see a new list every render.\n const memberships = useMemo(() => r.data?.memberships ?? NO_MEMBERSHIPS, [r.data]);\n return {\n memberships,\n groups,\n loading: !!key && (r.loading || !r.loaded),\n error: r.error,\n saving: inflight > 0,\n reload: r.reload,\n set,\n };\n}\n"],"mappings":";;;;AAiCA,SAAgB,EAAS,IAAmC,CAAC,GAAa;CACxE,IAAM,EAAE,WAAQ,aAAU,EAAgB,EAAE,MAAM,GAC5C,IAAI,EAA0B,GAAO,EAAM,OAAO,GAAG,EAAE,MAAM,QAAQ,IAAI,MAAM,EAAO,MAAM,CAAC,CAAC;CACpG,OAAO;EAAE,OAAO,EAAE,QAAQ;EAAM,SAAS,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE;EAAS,OAAO,EAAE;EAAO,QAAQ,EAAE;CAAO;AACjH;AAwBA,SAAgB,EAAU,IAAiB,CAAC,GAAG,IAAmC,CAAC,GAAuB;CACxG,IAAM,EAAE,WAAQ,UAAO,UAAO,UAAU,MAAa,EAAgB,EAAE,MAAM,GACvE,IAAW,EAAE,YAAY,GACzB,IAAO,EAAE,YAAY;CAC3B,OAAO,EACL,GACA,EAAM,UAAU,GAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAU,EAAE,aAAa,EAAE,MAAM,CAAI,GACzG,EAAE,MAAM,SAAS,GACjB,OAAO,GAAQ,MAAW;EACxB,IAAM,IAAO,MAAM,EAAO,OAAO,KAC/B;GAAE,MAAM,EAAE;GAAM,QAAQ,EAAE;GAAQ,OAAO,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
@@ -3,7 +3,7 @@ export { useContentKit, useContentKitClient, useContentURLs, useErrorReporter, u
3
3
  export { useMediaRead, type MediaReadOptions, type ReadWindow, type UseMediaRead } from './read.js';
4
4
  export { nameIn, thumbnailOf, useMediaFolder, type FolderGroup, type MediaFolderOptions, type UseMediaFolder } from './folder.js';
5
5
  export { useEditorCrop, type EditorCropOptions, type EditorCropState, type UseEditorCrop } from './crop.js';
6
- export { usePresets, usePublicImage, type PublicImageOptions, type UsePresets, type UsePublicImage } from './public.js';
6
+ export { useAvatar, usePresets, usePublicImage, type PublicImageOptions, type UsePresets, type UsePublicImage } from './public.js';
7
7
  export { useCanonicalContent, type CanonicalContent, type CanonicalContentOptions } from './canonical.js';
8
8
  export { useNearViewport, type NearViewportOptions } from './viewport.js';
9
9
  export { useAdminLocation, useFlowClient, useStaffAccess, type AdminLocation, type AdminNavigation, type AdminQuery, type ContentKitAuth, type FlowClientOptions, type StaffAccess, type StaffArea, } from './admin.js';
@@ -12,10 +12,12 @@ export { useContentConfig, type UseContentConfig } from './config.js';
12
12
  export { useFavorite, useReaction, type UseFavorite, type UseReaction } from './engagement.js';
13
13
  export { usePoll, usePollEditor, usePolls, withVote, type PollFilter, type PollImages, type UsePoll, type UsePollEditor } from './polls.js';
14
14
  export { useContent, useManagedContents, type ManageFilter, type UseContent } from './contents.js';
15
- export { defaultVersion, liveVersions, useContentDetail, type UseContentDetail } from './detail.js';
15
+ export { useActivity, useMyStats, useTopContents, type UseStats } from './stats.js';
16
+ export { defaultVersion, findVersion, liveVersions, useContentDetail, type ContentDetailOptions, type UseContentDetail } from './detail.js';
17
+ export { useVersionParam } from './location.js';
16
18
  export { memberId, useContentGroups, useGroup, useGroupMembers, useGroups, useKinds, useMyGroups, type GroupFilter, type GroupSort, type Member, type UseContentGroups, type UseGroup, type UseGroupMembers, type UseKinds, } from './groups.js';
17
- export { beaconsFor, useBeacons, useContentFilters, useContents, useExposure, useHistory, useMyFavorites, useMyReactions, useRecentSearches, useRecommendations, useReleaseDates, useSearch, useSimilar, useTypeahead, useViewSignal, type ExposureOptions, type MyInteraction, type ReleaseDate, type UseContentFilters, type UseExposure, type UseHistory, type UseRail, type UseRecentSearches, type UseTypeahead, } from './discovery.js';
18
- export { nextRelease, useReaderPlan, useSegmentPages, useVersionDownload, type ReaderPage, type UseReaderPlan, type UseSegmentPages, type UseVersionDownload, } from './versions.js';
19
+ export { beaconsFor, useBeacons, useContentFilters, useContents, useExposure, useHistory, useLockedCount, useMyFavorites, useMyReactions, useRecentSearches, useRecommendations, useReleaseDates, useSearch, useSimilar, useTypeahead, useViewSignal, type ExposureOptions, type MyInteraction, type ReleaseDate, type UseContentFilters, type UseExposure, type UseHistory, type UseRail, type UseRecentSearches, type UseTypeahead, } from './discovery.js';
20
+ export { downloadMessage, nextRelease, startDownload, useReaderPlan, useSegmentPages, useVersionDownload, type ReaderPage, type UseReaderPlan, type UseSegmentPages, type UseVersionDownload, } from './versions.js';
19
21
  export { useContentScope, usePaged, type UseList, type UsePaged } from './use-resource.js';
20
22
  export { ResourceStore, resourcesFor, type Page, type Resource } from './resources.js';
21
23
  export { useCrop, useEncodeProgress, useUpload, useUploadQueue, type UploadQueueOptions, type UploadStatus, type UseCrop, type UseCropOptions, type UseEncodeProgress, type UseUpload, type UseUploadQueue, } from './upload.js';
@@ -0,0 +1,11 @@
1
+ /** Dispatched after a history write, so location readers look again. */
2
+ export declare const MOVED = "ckui:navigate";
3
+ export declare const subscribeHistory: (cb: () => void) => () => void;
4
+ /**
5
+ * The page's ?v= version code (null when it names none) and a setter that
6
+ * writes it, null removing it: through the provider's navigate (a replace),
7
+ * else the browser history. location overrides window.location.
8
+ */
9
+ export declare function useVersionParam(o?: {
10
+ location?: string;
11
+ }): [string | null, (code: string | null) => void];
@@ -0,0 +1,18 @@
1
+ import { ContentKitContext as e } from "./context.js";
2
+ import { versionParam as t, withVersion as n } from "../urls.js";
3
+ import { useCallback as r, useContext as i, useSyncExternalStore as a } from "react";
4
+ //#region src/react/location.ts
5
+ var o = "ckui:navigate", s = (e) => (addEventListener("popstate", e), addEventListener(o, e), () => {
6
+ removeEventListener("popstate", e), removeEventListener(o, e);
7
+ }), c = () => location.pathname + location.search + location.hash;
8
+ function l(l = {}) {
9
+ let u = i(e)?.navigate, d = a(s, c, () => ""), f = l.location ?? d, p = r((e) => {
10
+ let t = n(l.location ?? c(), e);
11
+ u ? u(t, { replace: !0 }) : history.replaceState(history.state, "", t), dispatchEvent(new Event(o));
12
+ }, [u, l.location]);
13
+ return [t(f), p];
14
+ }
15
+ //#endregion
16
+ export { o as MOVED, s as subscribeHistory, l as useVersionParam };
17
+
18
+ //# sourceMappingURL=location.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"location.js","names":[],"sources":["../../src/react/location.ts"],"sourcesContent":["import { useCallback, useContext, useSyncExternalStore } from \"react\";\nimport { versionParam, withVersion } from \"../urls/index.js\";\nimport { ContentKitContext } from \"./context.js\";\n\n/** Dispatched after a history write, so location readers look again. */\nexport const MOVED = \"ckui:navigate\";\n\nexport const subscribeHistory = (cb: () => void) => {\n addEventListener(\"popstate\", cb);\n addEventListener(MOVED, cb);\n return () => {\n removeEventListener(\"popstate\", cb);\n removeEventListener(MOVED, cb);\n };\n};\n\nconst here = () => location.pathname + location.search + location.hash;\n\n/**\n * The page's ?v= version code (null when it names none) and a setter that\n * writes it, null removing it: through the provider's navigate (a replace),\n * else the browser history. location overrides window.location.\n */\nexport function useVersionParam(o: { location?: string } = {}): [string | null, (code: string | null) => void] {\n const navigate = useContext(ContentKitContext)?.navigate;\n const current = useSyncExternalStore(subscribeHistory, here, () => \"\");\n const at = o.location ?? current;\n const set = useCallback(\n (code: string | null) => {\n const to = withVersion(o.location ?? here(), code);\n if (navigate) navigate(to, { replace: true });\n else history.replaceState(history.state, \"\", to);\n dispatchEvent(new Event(MOVED));\n },\n [navigate, o.location],\n );\n return [versionParam(at), set];\n}\n"],"mappings":";;;;AAKA,IAAa,IAAQ,iBAER,KAAoB,OAC/B,iBAAiB,YAAY,CAAE,GAC/B,iBAAiB,GAAO,CAAE,SACb;CAEX,AADA,oBAAoB,YAAY,CAAE,GAClC,oBAAoB,GAAO,CAAE;AAC/B,IAGI,UAAa,SAAS,WAAW,SAAS,SAAS,SAAS;AAOlE,SAAgB,EAAgB,IAA2B,CAAC,GAAmD;CAC7G,IAAM,IAAW,EAAW,CAAiB,CAAC,EAAE,UAC1C,IAAU,EAAqB,GAAkB,SAAY,EAAE,GAC/D,IAAK,EAAE,YAAY,GACnB,IAAM,GACT,MAAwB;EACvB,IAAM,IAAK,EAAY,EAAE,YAAY,EAAK,GAAG,CAAI;EAGjD,AAFI,IAAU,EAAS,GAAI,EAAE,SAAS,GAAK,CAAC,IACvC,QAAQ,aAAa,QAAQ,OAAO,IAAI,CAAE,GAC/C,cAAc,IAAI,MAAM,CAAK,CAAC;CAChC,GACA,CAAC,GAAU,EAAE,QAAQ,CACvB;CACA,OAAO,CAAC,EAAa,CAAE,GAAG,CAAG;AAC/B"}
@@ -38,3 +38,11 @@ export interface UsePublicImage {
38
38
  * commits through the same client.
39
39
  */
40
40
  export declare function usePublicImage(item: RefBody, preset: string, o?: PublicImageOptions): UsePublicImage;
41
+ /**
42
+ * A person's avatar (the content model's `avatars`, a Stable preset): URLs
43
+ * built from their id on this site's media host, showing their image or
44
+ * the default. null while the model loads or when the site shows none.
45
+ */
46
+ export declare function useAvatar(userId: string | null | undefined, o?: {
47
+ client?: ContentKitClient;
48
+ }): PublicPreset | null;
@@ -1,38 +1,39 @@
1
- import { defaultImage as e, isPattern as t, ruleDir as n } from "../client/media/rules.js";
2
- import { useOptionalContentKitClient as r } from "./context.js";
3
- import { useMediaRead as i } from "./read.js";
4
- import { useEffect as a, useMemo as o, useState as s } from "react";
1
+ import { defaultImage as e, isPattern as t, ruleDir as n, stableImage as r } from "../client/media/rules.js";
2
+ import { useOptionalContentKitClient as i } from "./context.js";
3
+ import { useKinds as a } from "./groups.js";
4
+ import { useMediaRead as o } from "./read.js";
5
+ import { useEffect as s, useMemo as c, useState as l } from "react";
5
6
  //#region src/react/public.ts
6
- var c = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap();
7
- function u(e = {}) {
8
- let t = r(e.client), [, n] = s(0), i = t ? c.get(t) : void 0;
9
- return a(() => {
10
- if (!t || c.has(t)) return;
11
- let e = !0, r = l.get(t);
12
- return r || (r = t.media.presets().then((e) => void c.set(t, { presets: e }), (e) => void c.set(t, {
7
+ var u = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new WeakMap();
8
+ function f(e = {}) {
9
+ let t = i(e.client), [, n] = l(0), r = t ? u.get(t) : void 0;
10
+ return s(() => {
11
+ if (!t || u.has(t)) return;
12
+ let e = !0, r = d.get(t);
13
+ return r || (r = t.media.presets().then((e) => void u.set(t, { presets: e }), (e) => void u.set(t, {
13
14
  presets: [],
14
15
  error: e
15
- })).finally(() => l.delete(t)), l.set(t, r)), r.then(() => e && n((e) => e + 1)), () => {
16
+ })).finally(() => d.delete(t)), d.set(t, r)), r.then(() => e && n((e) => e + 1)), () => {
16
17
  e = !1;
17
18
  };
18
19
  }, [t]), {
19
- presets: i?.presets ?? [],
20
- loaded: !!i || !t,
21
- error: i?.error
20
+ presets: r?.presets ?? [],
21
+ loaded: !!r || !t,
22
+ error: r?.error
22
23
  };
23
24
  }
24
- function d(a, s, c = {}) {
25
- let { kind: l, id: d } = a, f = r(c.client), { presets: p, loaded: m } = u({ client: f }), h = p.find((e) => e.kind === l && e.name === s), g = c.image !== void 0, _ = h ? t(h.from) ? n(h.from) : h.from : void 0, v = i(a, {
25
+ function p(r, a, s = {}) {
26
+ let { kind: l, id: u } = r, d = i(s.client), { presets: p, loaded: m } = f({ client: d }), h = p.find((e) => e.kind === l && e.name === a), g = s.image !== void 0, _ = h ? t(h.from) ? n(h.from) : h.from : void 0, v = o(r, {
26
27
  prefix: _,
27
- read: g || !m ? null : c.read,
28
- client: f
28
+ read: g || !m ? null : s.read,
29
+ client: d
29
30
  });
30
31
  return {
31
- ...o(() => {
32
- let t = g ? c.image : v.read?.public?.find((e) => e.preset === s);
32
+ ...c(() => {
33
+ let t = g ? s.image : v.read?.public?.find((e) => e.preset === a);
33
34
  if (t && t.renditions.length) return {
34
35
  image: {
35
- preset: s,
36
+ preset: a,
36
37
  renditions: t.renditions,
37
38
  aspect: "aspect" in t && t.aspect || h?.aspect
38
39
  },
@@ -42,7 +43,7 @@ function d(a, s, c = {}) {
42
43
  image: null,
43
44
  isDefault: !1
44
45
  };
45
- let n = h && e(h, d);
46
+ let n = h && e(h, u);
46
47
  return n ? {
47
48
  image: n,
48
49
  isDefault: !0
@@ -52,11 +53,11 @@ function d(a, s, c = {}) {
52
53
  };
53
54
  }, [
54
55
  g,
55
- c.image,
56
+ s.image,
56
57
  v.read,
57
- s,
58
+ a,
58
59
  h,
59
- d
60
+ u
60
61
  ]),
61
62
  rule: h,
62
63
  loading: !m || v.loading,
@@ -64,7 +65,11 @@ function d(a, s, c = {}) {
64
65
  reload: v.reload
65
66
  };
66
67
  }
68
+ function m(e, t = {}) {
69
+ let { kinds: n } = a(t), i = n?.avatars;
70
+ return c(() => i && e ? r(i, e) : null, [i, e]);
71
+ }
67
72
  //#endregion
68
- export { u as usePresets, d as usePublicImage };
73
+ export { m as useAvatar, f as usePresets, p as usePublicImage };
69
74
 
70
75
  //# sourceMappingURL=public.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"public.js","names":[],"sources":["../../src/react/public.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from \"react\";\nimport type { ContentKitClient } from \"../client/client.js\";\nimport type { ContentKitError } from \"../client/errors.js\";\nimport type { ReadResult, RefBody } from \"../client/generated/wire.js\";\nimport type { PresetRule } from \"../client/generated/wire.js\";\nimport { defaultImage, isPattern, ruleDir } from \"../client/media/rules.js\";\nimport type { PublicPreset } from \"../client/public.js\";\nimport { useOptionalContentKitClient } from \"./context.js\";\nimport { useMediaRead } from \"./read.js\";\n\nexport interface UsePresets {\n /** Every kind's public presets; empty until they load (or when the server has none). */\n presets: PresetRule[];\n loaded: boolean;\n error?: ContentKitError;\n}\n\nconst settled = new WeakMap<ContentKitClient, { presets: PresetRule[]; error?: ContentKitError }>();\nconst inflight = new WeakMap<ContentKitClient, Promise<void>>();\n\n/** The public presets (`GET /media/presets`), fetched once per client. */\nexport function usePresets(o: { client?: ContentKitClient | null } = {}): UsePresets {\n const client = useOptionalContentKitClient(o.client);\n const [, rerender] = useState(0);\n const done = client ? settled.get(client) : undefined;\n useEffect(() => {\n if (!client || settled.has(client)) return;\n let live = true;\n let load = inflight.get(client);\n if (!load) {\n load = client.media.presets().then(\n (presets) => void settled.set(client, { presets }),\n (error: ContentKitError) => void settled.set(client, { presets: [], error }),\n ).finally(() => inflight.delete(client));\n inflight.set(client, load);\n }\n void load.then(() => live && rerender((n) => n + 1));\n return () => {\n live = false;\n };\n }, [client]);\n return { presets: done?.presets ?? [], loaded: !!done || !client, error: done?.error };\n}\n\nexport interface PublicImageOptions {\n /** The host's listing of the item's image (its API's): shown without a read. */\n image?: PublicPreset | null;\n /** A read of the item the host already has. */\n read?: ReadResult | null;\n /** Overrides the provider's client. */\n client?: ContentKitClient | null;\n}\n\nexport interface UsePublicImage {\n /** The item's current renditions; else the kind's default image (when the preset has one); null while unknown or when there is neither. */\n image: PublicPreset | null;\n /** The preset's rules (aspect, widths, min_width) once the presets load. */\n rule?: PresetRule;\n /** image is the kind's default, not the item's own. */\n isDefault: boolean;\n loading: boolean;\n error?: ContentKitError;\n reload: () => void;\n}\n\n/**\n * An item's public image for a preset (\"avatar\", \"cover\", a version's\n * \"poster\"): the exact renditions from a read's `public` (or the host's\n * listing), else the kind's default image, else none. Reads refresh after\n * commits through the same client.\n */\nexport function usePublicImage(item: RefBody, preset: string, o: PublicImageOptions = {}): UsePublicImage {\n const { kind, id } = item;\n const client = useOptionalContentKitClient(o.client);\n const { presets, loaded } = usePresets({ client });\n const rule = presets.find((p) => p.kind === kind && p.name === preset);\n const listed = o.image !== undefined;\n // The read waits for the presets, so it lists only the preset's upload.\n const prefix = rule ? (isPattern(rule.from) ? ruleDir(rule.from) : rule.from) : undefined;\n const r = useMediaRead(item, { prefix, read: listed || !loaded ? null : o.read, client });\n const image = useMemo((): { image: PublicPreset | null; isDefault: boolean } => {\n const own = listed ? o.image : r.read?.public?.find((p) => p.preset === preset);\n if (own && own.renditions.length) return { image: { preset, renditions: own.renditions, aspect: (\"aspect\" in own && own.aspect) || rule?.aspect }, isDefault: false };\n if (!listed && !r.read) return { image: null, isDefault: false };\n const def = rule && defaultImage(rule, id);\n return def ? { image: def, isDefault: true } : { image: null, isDefault: false };\n }, [listed, o.image, r.read, preset, rule, id]);\n return { ...image, rule, loading: !loaded || r.loading, error: r.error, reload: r.reload };\n}\n"],"mappings":";;;;;AAiBA,IAAM,oBAAU,IAAI,QAA8E,GAC5F,oBAAW,IAAI,QAAyC;AAG9D,SAAgB,EAAW,IAA0C,CAAC,GAAe;CACnF,IAAM,IAAS,EAA4B,EAAE,MAAM,GAC7C,GAAG,KAAY,EAAS,CAAC,GACzB,IAAO,IAAS,EAAQ,IAAI,CAAM,IAAI,KAAA;CAiB5C,OAhBA,QAAgB;EACd,IAAI,CAAC,KAAU,EAAQ,IAAI,CAAM,GAAG;EACpC,IAAI,IAAO,IACP,IAAO,EAAS,IAAI,CAAM;EAS9B,OARK,MACH,IAAO,EAAO,MAAM,QAAQ,CAAC,CAAC,MAC3B,MAAY,KAAK,EAAQ,IAAI,GAAQ,EAAE,WAAQ,CAAC,IAChD,MAA2B,KAAK,EAAQ,IAAI,GAAQ;GAAE,SAAS,CAAC;GAAG;EAAM,CAAC,CAC7E,CAAC,CAAC,cAAc,EAAS,OAAO,CAAM,CAAC,GACvC,EAAS,IAAI,GAAQ,CAAI,IAE3B,EAAU,WAAW,KAAQ,GAAU,MAAM,IAAI,CAAC,CAAC,SACtC;GACX,IAAO;EACT;CACF,GAAG,CAAC,CAAM,CAAC,GACJ;EAAE,SAAS,GAAM,WAAW,CAAC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\"react\";\nimport type { ContentKitClient } from \"../client/client.js\";\nimport type { ContentKitError } from \"../client/errors.js\";\nimport type { ReadResult, RefBody } from \"../client/generated/wire.js\";\nimport type { PresetRule } from \"../client/generated/wire.js\";\nimport { defaultImage, isPattern, ruleDir, stableImage } from \"../client/media/rules.js\";\nimport type { PublicPreset } from \"../client/public.js\";\nimport { useOptionalContentKitClient } from \"./context.js\";\nimport { useKinds } from \"./groups.js\";\nimport { useMediaRead } from \"./read.js\";\n\nexport interface UsePresets {\n /** Every kind's public presets; empty until they load (or when the server has none). */\n presets: PresetRule[];\n loaded: boolean;\n error?: ContentKitError;\n}\n\nconst settled = new WeakMap<ContentKitClient, { presets: PresetRule[]; error?: ContentKitError }>();\nconst inflight = new WeakMap<ContentKitClient, Promise<void>>();\n\n/** The public presets (`GET /media/presets`), fetched once per client. */\nexport function usePresets(o: { client?: ContentKitClient | null } = {}): UsePresets {\n const client = useOptionalContentKitClient(o.client);\n const [, rerender] = useState(0);\n const done = client ? settled.get(client) : undefined;\n useEffect(() => {\n if (!client || settled.has(client)) return;\n let live = true;\n let load = inflight.get(client);\n if (!load) {\n load = client.media.presets().then(\n (presets) => void settled.set(client, { presets }),\n (error: ContentKitError) => void settled.set(client, { presets: [], error }),\n ).finally(() => inflight.delete(client));\n inflight.set(client, load);\n }\n void load.then(() => live && rerender((n) => n + 1));\n return () => {\n live = false;\n };\n }, [client]);\n return { presets: done?.presets ?? [], loaded: !!done || !client, error: done?.error };\n}\n\nexport interface PublicImageOptions {\n /** The host's listing of the item's image (its API's): shown without a read. */\n image?: PublicPreset | null;\n /** A read of the item the host already has. */\n read?: ReadResult | null;\n /** Overrides the provider's client. */\n client?: ContentKitClient | null;\n}\n\nexport interface UsePublicImage {\n /** The item's current renditions; else the kind's default image (when the preset has one); null while unknown or when there is neither. */\n image: PublicPreset | null;\n /** The preset's rules (aspect, widths, min_width) once the presets load. */\n rule?: PresetRule;\n /** image is the kind's default, not the item's own. */\n isDefault: boolean;\n loading: boolean;\n error?: ContentKitError;\n reload: () => void;\n}\n\n/**\n * An item's public image for a preset (\"avatar\", \"cover\", a version's\n * \"poster\"): the exact renditions from a read's `public` (or the host's\n * listing), else the kind's default image, else none. Reads refresh after\n * commits through the same client.\n */\nexport function usePublicImage(item: RefBody, preset: string, o: PublicImageOptions = {}): UsePublicImage {\n const { kind, id } = item;\n const client = useOptionalContentKitClient(o.client);\n const { presets, loaded } = usePresets({ client });\n const rule = presets.find((p) => p.kind === kind && p.name === preset);\n const listed = o.image !== undefined;\n // The read waits for the presets, so it lists only the preset's upload.\n const prefix = rule ? (isPattern(rule.from) ? ruleDir(rule.from) : rule.from) : undefined;\n const r = useMediaRead(item, { prefix, read: listed || !loaded ? null : o.read, client });\n const image = useMemo((): { image: PublicPreset | null; isDefault: boolean } => {\n const own = listed ? o.image : r.read?.public?.find((p) => p.preset === preset);\n if (own && own.renditions.length) return { image: { preset, renditions: own.renditions, aspect: (\"aspect\" in own && own.aspect) || rule?.aspect }, isDefault: false };\n if (!listed && !r.read) return { image: null, isDefault: false };\n const def = rule && defaultImage(rule, id);\n return def ? { image: def, isDefault: true } : { image: null, isDefault: false };\n }, [listed, o.image, r.read, preset, rule, id]);\n return { ...image, rule, loading: !loaded || r.loading, error: r.error, reload: r.reload };\n}\n\n/**\n * A person's avatar (the content model's `avatars`, a Stable preset): URLs\n * built from their id on this site's media host, showing their image or\n * the default. null while the model loads or when the site shows none.\n */\nexport function useAvatar(userId: string | null | undefined, o: { client?: ContentKitClient } = {}): PublicPreset | null {\n const { kinds } = useKinds(o);\n const rule = kinds?.avatars;\n return useMemo(() => (rule && userId ? stableImage(rule, userId) : null), [rule, userId]);\n}\n"],"mappings":";;;;;;AAkBA,IAAM,oBAAU,IAAI,QAA8E,GAC5F,oBAAW,IAAI,QAAyC;AAG9D,SAAgB,EAAW,IAA0C,CAAC,GAAe;CACnF,IAAM,IAAS,EAA4B,EAAE,MAAM,GAC7C,GAAG,KAAY,EAAS,CAAC,GACzB,IAAO,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W,QAAQ,OAAO;IAAE,OAAO;KAAE;KAAQ,YAAY,EAAI;KAAY,QAAS,YAAY,KAAO,EAAI,UAAW,GAAM;IAAO;IAAG,WAAW;GAAM;GACpK,IAAI,CAAC,KAAU,CAAC,EAAE,MAAM,OAAO;IAAE,OAAO;IAAM,WAAW;GAAM;GAC/D,IAAM,IAAM,KAAQ,EAAa,GAAM,CAAE;GACzC,OAAO,IAAM;IAAE,OAAO;IAAK,WAAW;GAAK,IAAI;IAAE,OAAO;IAAM,WAAW;GAAM;EACjF,GAAG;GAAC;GAAQ,EAAE;GAAO,EAAE;GAAM;GAAQ;GAAM;EAAE,CACjC;EAAO;EAAM,SAAS,CAAC,KAAU,EAAE;EAAS,OAAO,EAAE;EAAO,QAAQ,EAAE;CAAO;AAC3F;AAOA,SAAgB,EAAU,GAAmC,IAAmC,CAAC,GAAwB;CACvH,IAAM,EAAE,aAAU,EAAS,CAAC,GACtB,IAAO,GAAO;CACpB,OAAO,QAAe,KAAQ,IAAS,EAAY,GAAM,CAAM,IAAI,MAAO,CAAC,GAAM,CAAM,CAAC;AAC1F"}
@@ -0,0 +1,24 @@
1
+ import { ContentKitClient } from '../client/client.js';
2
+ import { ContentKitError } from '../client/errors.js';
3
+ import { Activity, MyStats, TopContents } from '../client/generated/wire.js';
4
+ import { ActivityQuery, TopQuery } from '../client/stats.js';
5
+ export interface UseStats<T> {
6
+ data: T | null;
7
+ loading: boolean;
8
+ error?: ContentKitError;
9
+ /** The site runs without the signal plane (not_configured). */
10
+ unavailable: boolean;
11
+ reload: () => void;
12
+ }
13
+ /** Staff: a kind's views per UTC day, newest first; null reads nothing. */
14
+ export declare function useActivity(q: ActivityQuery | null, o?: {
15
+ client?: ContentKitClient;
16
+ }): UseStats<Activity>;
17
+ /** Staff: a kind's content ranked by views or comments over a period; null reads nothing. */
18
+ export declare function useTopContents(q: TopQuery | null, o?: {
19
+ client?: ContentKitClient;
20
+ }): UseStats<TopContents>;
21
+ /** The signed-in reader's statistics; nothing signed out. */
22
+ export declare function useMyStats(o?: {
23
+ client?: ContentKitClient;
24
+ }): UseStats<MyStats>;
@@ -0,0 +1,28 @@
1
+ import { keyOf as e, useContentScope as t, useResource as n } from "./use-resource.js";
2
+ //#region src/react/stats.ts
3
+ function r(e, r, i) {
4
+ let { client: a, store: o } = t(i.client), s = n(o, e, { type: "stats" }, (e) => r(a, e)), c = s.error?.code === "not_configured";
5
+ return {
6
+ data: s.data ?? null,
7
+ loading: !!e && (s.loading || !s.loaded),
8
+ error: c ? void 0 : s.error,
9
+ unavailable: c,
10
+ reload: s.reload
11
+ };
12
+ }
13
+ function i(n, i = {}) {
14
+ let { scope: a } = t(i.client);
15
+ return r(n ? e("stats", a, "activity", n.kind, n.days) : null, (e, t) => e.stats.activity(n, t), i);
16
+ }
17
+ function a(n, i = {}) {
18
+ let { scope: a } = t(i.client);
19
+ return r(n ? e("stats", a, "top", n) : null, (e, t) => e.stats.top(n, t), i);
20
+ }
21
+ function o(n = {}) {
22
+ let { scope: i, viewer: a } = t(n.client);
23
+ return r(a === null ? null : e("stats", i, "me"), (e, t) => e.stats.mine(t), n);
24
+ }
25
+ //#endregion
26
+ export { i as useActivity, o as useMyStats, a as useTopContents };
27
+
28
+ //# sourceMappingURL=stats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stats.js","names":[],"sources":["../../src/react/stats.ts"],"sourcesContent":["import type { ContentKitClient } from \"../client/client.js\";\nimport type { ContentKitError } from \"../client/errors.js\";\nimport type { Activity, MyStats, TopContents } from \"../client/generated/wire.js\";\nimport type { ActivityQuery, TopQuery } from \"../client/stats.js\";\nimport { keyOf, useContentScope, useResource } from \"./use-resource.js\";\n\nexport interface UseStats<T> {\n data: T | null;\n loading: boolean;\n error?: ContentKitError;\n /** The site runs without the signal plane (not_configured). */\n unavailable: boolean;\n reload: () => void;\n}\n\nfunction useStats<T>(key: string | null, fetch: (c: ContentKitClient, signal: AbortSignal) => Promise<T>, o: { client?: ContentKitClient }): UseStats<T> {\n const { client, store } = useContentScope(o.client);\n const r = useResource<T>(store, key, { type: \"stats\" }, (signal) => fetch(client, signal));\n const unavailable = r.error?.code === \"not_configured\";\n return { data: r.data ?? null, loading: !!key && (r.loading || !r.loaded), error: unavailable ? undefined : r.error, unavailable, reload: r.reload };\n}\n\n/** Staff: a kind's views per UTC day, newest first; null reads nothing. */\nexport function useActivity(q: ActivityQuery | null, o: { client?: ContentKitClient } = {}): UseStats<Activity> {\n const { scope } = useContentScope(o.client);\n return useStats(q ? keyOf(\"stats\", scope, \"activity\", q.kind, q.days) : null, (c, s) => c.stats.activity(q!, s), o);\n}\n\n/** Staff: a kind's content ranked by views or comments over a period; null reads nothing. */\nexport function useTopContents(q: TopQuery | null, o: { client?: ContentKitClient } = {}): UseStats<TopContents> {\n const { scope } = useContentScope(o.client);\n return useStats(q ? keyOf(\"stats\", scope, \"top\", q) : null, (c, s) => c.stats.top(q!, s), o);\n}\n\n/** The signed-in reader's statistics; nothing signed out. */\nexport function useMyStats(o: { client?: ContentKitClient } = {}): UseStats<MyStats> {\n const { scope, viewer } = useContentScope(o.client);\n return useStats(viewer === null ? null : keyOf(\"stats\", scope, \"me\"), (c, s) => c.stats.mine(s), o);\n}\n"],"mappings":";;AAeA,SAAS,EAAY,GAAoB,GAAiE,GAA+C;CACvJ,IAAM,EAAE,WAAQ,aAAU,EAAgB,EAAE,MAAM,GAC5C,IAAI,EAAe,GAAO,GAAK,EAAE,MAAM,QAAQ,IAAI,MAAW,EAAM,GAAQ,CAAM,CAAC,GACnF,IAAc,EAAE,OAAO,SAAS;CACtC,OAAO;EAAE,MAAM,EAAE,QAAQ;EAAM,SAAS,CAAC,CAAC,MAAQ,EAAE,WAAW,CAAC,EAAE;EAAS,OAAO,IAAc,KAAA,IAAY,EAAE;EAAO;EAAa,QAAQ,EAAE;CAAO;AACrJ;AAGA,SAAgB,EAAY,GAAyB,IAAmC,CAAC,GAAuB;CAC9G,IAAM,EAAE,aAAU,EAAgB,EAAE,MAAM;CAC1C,OAAO,EAAS,IAAI,EAAM,SAAS,GAAO,YAAY,EAAE,MAAM,EAAE,IAAI,IAAI,OAAO,GAAG,MAAM,EAAE,MAAM,SAAS,GAAI,CAAC,GAAG,CAAC;AACpH;AAGA,SAAgB,EAAe,GAAoB,IAAmC,CAAC,GAA0B;CAC/G,IAAM,EAAE,aAAU,EAAgB,EAAE,MAAM;CAC1C,OAAO,EAAS,IAAI,EAAM,SAAS,GAAO,OAAO,CAAC,IAAI,OAAO,GAAG,MAAM,EAAE,MAAM,IAAI,GAAI,CAAC,GAAG,CAAC;AAC7F;AAGA,SAAgB,EAAW,IAAmC,CAAC,GAAsB;CACnF,IAAM,EAAE,UAAO,cAAW,EAAgB,EAAE,MAAM;CAClD,OAAO,EAAS,MAAW,OAAO,OAAO,EAAM,SAAS,GAAO,IAAI,IAAI,GAAG,MAAM,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC;AACpG"}
@@ -44,10 +44,11 @@ function f(e, t, r, a, l = {}) {
44
44
  reload: y
45
45
  };
46
46
  }
47
- function p(e, t, n, r) {
47
+ var p = [];
48
+ function m(e, t, n, r) {
48
49
  let a = f(e, t, n, (e) => r(void 0, e), { more: (e, t) => r(e, t) }), o = i(() => t ? e.loadMore(t) : Promise.resolve(), [e, t]);
49
50
  return {
50
- items: a.data?.items ?? [],
51
+ items: a.data?.items ?? p,
51
52
  loading: a.loading || !!t && !a.loaded,
52
53
  loadingMore: !!a.loadingMore,
53
54
  error: a.error,
@@ -56,7 +57,7 @@ function p(e, t, n, r) {
56
57
  reload: a.reload
57
58
  };
58
59
  }
59
- function m(e, t, n = !1) {
60
+ function h(e, t, n = !1) {
60
61
  return async (r, i) => {
61
62
  let a = typeof r == "number" ? r : 0, o = await t({
62
63
  limit: e,
@@ -68,8 +69,8 @@ function m(e, t, n = !1) {
68
69
  };
69
70
  };
70
71
  }
71
- var h = (...e) => JSON.stringify(e);
72
- function g(e, t, n, r, i, a) {
72
+ var g = (...e) => JSON.stringify(e);
73
+ function _(e, t, n, r, i, a) {
73
74
  let o = (Math.max(1, r) - 1) * i, s = f(e, t === null ? null : `${t}#${o}`, n, async (e) => {
74
75
  let t = await a({
75
76
  limit: i + 1,
@@ -81,7 +82,7 @@ function g(e, t, n, r, i, a) {
81
82
  };
82
83
  });
83
84
  return {
84
- items: s.data?.items ?? [],
85
+ items: s.data?.items ?? p,
85
86
  loading: s.loading || !!t && !s.loaded,
86
87
  error: s.error,
87
88
  hasNext: s.data ? s.data.next !== null : !1,
@@ -89,6 +90,6 @@ function g(e, t, n, r, i, a) {
89
90
  };
90
91
  }
91
92
  //#endregion
92
- export { h as keyOf, m as offsetPages, l as useContentScope, p as useList, g as usePaged, f as useResource };
93
+ export { g as keyOf, h as offsetPages, l as useContentScope, m as useList, _ as usePaged, f as useResource };
93
94
 
94
95
  //# sourceMappingURL=use-resource.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-resource.js","names":[],"sources":["../../src/react/use-resource.ts"],"sourcesContent":["import { useCallback, useContext, useEffect, useRef, useSyncExternalStore } from \"react\";\nimport type { ContentKitClient } from \"../client/client.js\";\nimport type { ContentKitError } from \"../client/errors.js\";\nimport { ContentKitContext, useContentKitClient, useReadScope } from \"./context.js\";\nimport { resourcesFor, type Fetcher, type Page, type Resource, type ResourceStore, type Tag } from \"./resources.js\";\n\n/** The client, its shared store, and the provider's viewer, language and sign-in. */\nexport function useContentScope(own?: ContentKitClient | null) {\n const ctx = useContext(ContentKitContext);\n const client = useContentKitClient(own);\n return { client, store: resourcesFor(client), scope: useReadScope(), viewer: ctx?.viewer, language: ctx?.language, onSignIn: ctx?.onSignIn };\n}\n\nconst IDLE: Resource<never> = { data: undefined, loading: false, loaded: false };\nconst none = () => () => {};\n\n/** A shared read: fetched once per key while shown; initial is shown (and seeds the store) until it loads. */\nexport function useResource<T>(\n store: ResourceStore,\n key: string | null,\n tag: Tag,\n fetcher: Fetcher<T>,\n o: { initial?: T; more?: (cursor: string | number, signal: AbortSignal) => Promise<Page<unknown>> } = {},\n): Resource<T> & { reload: () => void } {\n const scope = useReadScope();\n const fetch = useRef(fetcher);\n const more = useRef(o.more);\n const initial = useRef(o.initial);\n useEffect(() => {\n fetch.current = fetcher;\n more.current = o.more;\n initial.current = o.initial;\n });\n const subscribe = useCallback(\n (l: () => void) => (key ? store.subscribe(key, { ...tag, readScope: scope }, l) : none()),\n // The tag is part of the key.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [store, key, scope],\n );\n const snapshot = useCallback(() => (key ? store.snapshot<T>(key) : IDLE), [store, key]);\n const entry = useSyncExternalStore(subscribe, snapshot, snapshot);\n useEffect(() => {\n if (!key) return;\n store.bind(key, (s) => fetch.current(s), more.current && ((c, s) => more.current!(c, s)));\n if (initial.current !== undefined && !store.snapshot(key).loaded && !store.snapshot(key).loading) store.set(key, initial.current);\n else store.load(key);\n }, [store, key]);\n const reload = useCallback(() => key && store.load(key, true), [store, key]);\n if (!entry.loaded && o.initial !== undefined) return { ...entry, data: o.initial, reload };\n return { ...entry, reload };\n}\n\n/** A shared list, a page at a time. */\nexport interface UseList<T> {\n items: T[];\n /** The first page is loading (also on reload). */\n loading: boolean;\n loadingMore: boolean;\n error?: ContentKitError;\n hasMore: boolean;\n loadMore: () => Promise<void>;\n reload: () => void;\n}\n\nexport type PageFetcher<T> = (cursor: string | number | undefined, signal: AbortSignal) => Promise<Page<T>>;\n\nexport function useList<T extends { id: string }>(store: ResourceStore, key: string | null, tag: Tag, page: PageFetcher<T>): UseList<T> {\n const r = useResource<Page<T>>(store, key, tag, (s) => page(undefined, s), { more: (c, s) => page(c, s) });\n const loadMore = useCallback(() => (key ? store.loadMore(key) : Promise.resolve()), [store, key]);\n return {\n items: r.data?.items ?? [],\n loading: r.loading || (!!key && !r.loaded),\n loadingMore: !!r.loadingMore,\n error: r.error,\n hasMore: r.data ? r.data.next !== null : false,\n loadMore,\n reload: r.reload,\n };\n}\n\n/**\n * A limit/offset list as pages. A full page means more may follow; with\n * underfill (the latest feed drops items the caller may not see) only an\n * empty page ends it.\n */\nexport function offsetPages<T>(limit: number, list: (q: { limit: number; offset: number }, signal: AbortSignal) => Promise<T[]>, underfill = false): PageFetcher<T> {\n return async (cursor, signal) => {\n const offset = typeof cursor === \"number\" ? cursor : 0;\n const items = await list({ limit, offset }, signal);\n const end = underfill ? items.length === 0 : items.length < limit;\n return { items, next: end ? null : offset + limit };\n };\n}\n\n/** A stable store key. */\nexport const keyOf = (...parts: unknown[]) => JSON.stringify(parts);\n\n/** One numbered page of a list. */\nexport interface UsePaged<T> {\n items: T[];\n loading: boolean;\n error?: ContentKitError;\n /** Another page follows. */\n hasNext: boolean;\n reload: () => void;\n}\n\n/** Page `page` (from 1) of a limit/offset list: one read of limit + 1 tells whether another follows. */\nexport function usePaged<T extends { id: string }>(\n store: ResourceStore,\n key: string | null,\n tag: Tag,\n page: number,\n limit: number,\n list: (q: { limit: number; offset: number }, signal: AbortSignal) => Promise<T[]>,\n): UsePaged<T> {\n const offset = (Math.max(1, page) - 1) * limit;\n const r = useResource<Page<T>>(store, key === null ? null : `${key}#${offset}`, tag, async (signal) => {\n const items = await list({ limit: limit + 1, offset }, signal);\n return { items: items.slice(0, limit), next: items.length > limit ? offset + limit : null };\n });\n return { items: r.data?.items ?? [], loading: r.loading || (!!key && !r.loaded), error: r.error, hasNext: r.data ? r.data.next !== null : false, reload: r.reload };\n}\n"],"mappings":";;;;AAOA,SAAgB,EAAgB,GAA+B;CAC7D,IAAM,IAAM,EAAW,CAAiB,GAClC,IAAS,EAAoB,CAAG;CACtC,OAAO;EAAE;EAAQ,OAAO,EAAa,CAAM;EAAG,OAAO,EAAa;EAAG,QAAQ,GAAK;EAAQ,UAAU,GAAK;EAAU,UAAU,GAAK;CAAS;AAC7I;AAEA,IAAM,IAAwB;CAAE,MAAM,KAAA;CAAW,SAAS;CAAO,QAAQ;AAAM,GACzE,gBAAmB,CAAC;AAG1B,SAAgB,EACd,GACA,GACA,GACA,GACA,IAAsG,CAAC,GACjE;CACtC,IA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../src/react/use-resource.ts"],"sourcesContent":["import { useCallback, useContext, useEffect, useRef, useSyncExternalStore } from \"react\";\nimport type { ContentKitClient } from \"../client/client.js\";\nimport type { ContentKitError } from \"../client/errors.js\";\nimport { ContentKitContext, useContentKitClient, useReadScope } from \"./context.js\";\nimport { resourcesFor, type Fetcher, type Page, type Resource, type ResourceStore, type Tag } from \"./resources.js\";\n\n/** The client, its shared store, and the provider's viewer, language and sign-in. */\nexport function useContentScope(own?: ContentKitClient | null) {\n const ctx = useContext(ContentKitContext);\n const client = useContentKitClient(own);\n return { client, store: resourcesFor(client), scope: useReadScope(), viewer: ctx?.viewer, language: ctx?.language, onSignIn: ctx?.onSignIn };\n}\n\nconst IDLE: Resource<never> = { data: undefined, loading: false, loaded: false };\nconst none = () => () => {};\n\n/** A shared read: fetched once per key while shown; initial is shown (and seeds the store) until it loads. */\nexport function useResource<T>(\n store: ResourceStore,\n key: string | null,\n tag: Tag,\n fetcher: Fetcher<T>,\n o: { initial?: T; more?: (cursor: string | number, signal: AbortSignal) => Promise<Page<unknown>> } = {},\n): Resource<T> & { reload: () => void } {\n const scope = useReadScope();\n const fetch = useRef(fetcher);\n const more = useRef(o.more);\n const initial = useRef(o.initial);\n useEffect(() => {\n fetch.current = fetcher;\n more.current = o.more;\n initial.current = o.initial;\n });\n const subscribe = useCallback(\n (l: () => void) => (key ? store.subscribe(key, { ...tag, readScope: scope }, l) : none()),\n // The tag is part of the key.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [store, key, scope],\n );\n const snapshot = useCallback(() => (key ? store.snapshot<T>(key) : IDLE), [store, key]);\n const entry = useSyncExternalStore(subscribe, snapshot, snapshot);\n useEffect(() => {\n if (!key) return;\n store.bind(key, (s) => fetch.current(s), more.current && ((c, s) => more.current!(c, s)));\n if (initial.current !== undefined && !store.snapshot(key).loaded && !store.snapshot(key).loading) store.set(key, initial.current);\n else store.load(key);\n }, [store, key]);\n const reload = useCallback(() => key && store.load(key, true), [store, key]);\n if (!entry.loaded && o.initial !== undefined) return { ...entry, data: o.initial, reload };\n return { ...entry, reload };\n}\n\n/** A shared list, a page at a time. */\nexport interface UseList<T> {\n items: T[];\n /** The first page is loading (also on reload). */\n loading: boolean;\n loadingMore: boolean;\n error?: ContentKitError;\n hasMore: boolean;\n loadMore: () => Promise<void>;\n reload: () => void;\n}\n\nexport type PageFetcher<T> = (cursor: string | number | undefined, signal: AbortSignal) => Promise<Page<T>>;\n\n// The items of a list not loaded: one array, so effects keyed on items don't run every render.\nconst NO_ITEMS: never[] = [];\n\nexport function useList<T extends { id: string }>(store: ResourceStore, key: string | null, tag: Tag, page: PageFetcher<T>): UseList<T> {\n const r = useResource<Page<T>>(store, key, tag, (s) => page(undefined, s), { more: (c, s) => page(c, s) });\n const loadMore = useCallback(() => (key ? store.loadMore(key) : Promise.resolve()), [store, key]);\n return {\n items: r.data?.items ?? NO_ITEMS,\n loading: r.loading || (!!key && !r.loaded),\n loadingMore: !!r.loadingMore,\n error: r.error,\n hasMore: r.data ? r.data.next !== null : false,\n loadMore,\n reload: r.reload,\n };\n}\n\n/**\n * A limit/offset list as pages. A full page means more may follow; with\n * underfill (the latest feed drops items the caller may not see) only an\n * empty page ends it.\n */\nexport function offsetPages<T>(limit: number, list: (q: { limit: number; offset: number }, signal: AbortSignal) => Promise<T[]>, underfill = false): PageFetcher<T> {\n return async (cursor, signal) => {\n const offset = typeof cursor === \"number\" ? cursor : 0;\n const items = await list({ limit, offset }, signal);\n const end = underfill ? items.length === 0 : items.length < limit;\n return { items, next: end ? null : offset + limit };\n };\n}\n\n/** A stable store key. */\nexport const keyOf = (...parts: unknown[]) => JSON.stringify(parts);\n\n/** One numbered page of a list. */\nexport interface UsePaged<T> {\n items: T[];\n loading: boolean;\n error?: ContentKitError;\n /** Another page follows. */\n hasNext: boolean;\n reload: () => void;\n}\n\n/** Page `page` (from 1) of a limit/offset list: one read of limit + 1 tells whether another follows. */\nexport function usePaged<T extends { id: string }>(\n store: ResourceStore,\n key: string | null,\n tag: Tag,\n page: number,\n limit: number,\n list: (q: { limit: number; offset: number }, signal: AbortSignal) => Promise<T[]>,\n): UsePaged<T> {\n const offset = (Math.max(1, page) - 1) * limit;\n const r = useResource<Page<T>>(store, key === null ? null : `${key}#${offset}`, tag, async (signal) => {\n const items = await list({ limit: limit + 1, offset }, signal);\n return { items: items.slice(0, limit), next: items.length > limit ? offset + limit : null };\n });\n return { items: r.data?.items ?? NO_ITEMS, loading: r.loading || (!!key && !r.loaded), error: r.error, hasNext: r.data ? r.data.next !== null : false, reload: r.reload };\n}\n"],"mappings":";;;;AAOA,SAAgB,EAAgB,GAA+B;CAC7D,IAAM,IAAM,EAAW,CAAiB,GAClC,IAAS,EAAoB,CAAG;CACtC,OAAO;EAAE;EAAQ,OAAO,EAAa,CAAM;EAAG,OAAO,EAAa;EAAG,QAAQ,GAAK;EAAQ,UAAU,GAAK;EAAU,UAAU,GAAK;CAAS;AAC7I;AAEA,IAAM,IAAwB;CAAE,MAAM,KAAA;CAAW,SAAS;CAAO,QAAQ;AAAM,GACzE,gBAAmB,CAAC;AAG1B,SAAgB,EACd,GACA,GACA,GACA,GACA,IAAsG,CAAC,GACjE;CACtC,IAAM,IAAQ,EAAa,GACrB,IAAQ,EAAO,CAAO,GACtB,IAAO,EAAO,EAAE,IAAI,GACpB,IAAU,EAAO,EAAE,OAAO;CAChC,QAAgB;EAGd,AAFA,EAAM,UAAU,GAChB,EAAK,UAAU,EAAE,MACjB,EAAQ,UAAU,EAAE;CACtB,CAAC;CACD,IAAM,IAAY,GACf,MAAmB,IAAM,EAAM,UAAU,GAAK;EAAE,GAAG;EAAK,WAAW;CAAM,GAAG,CAAC,IAAI,EAAK,GAGvF;EAAC;EAAO;EAAK;CAAK,CACpB,GACM,IAAW,QAAmB,IAAM,EAAM,SAAY,CAAG,IAAI,GAAO,CAAC,GAAO,CAAG,CAAC,GAChF,IAAQ,EAAqB,GAAW,GAAU,CAAQ;CAChE,QAAgB;EACT,MACL,EAAM,KAAK,IAAM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AAE;GAAO,OADJ,IAAY,EAAM,WAAW,IAAI,EAAM,SAAS,KAChC,OAAO,IAAS;EAAM;CACpD;AACF;AAGA,IAAa,KAAS,GAAG,MAAqB,KAAK,UAAU,CAAK;AAalE,SAAgB,EACd,GACA,GACA,GACA,GACA,GACA,GACa;CACb,IAAM,KAAU,KAAK,IAAI,GAAG,CAAI,IAAI,KAAK,GACnC,IAAI,EAAqB,GAAO,MAAQ,OAAO,OAAO,GAAG,EAAI,GAAG,KAAU,GAAK,OAAO,MAAW;EACrG,IAAM,IAAQ,MAAM,EAAK;GAAE,OAAO,IAAQ;GAAG;EAAO,GAAG,CAAM;EAC7D,OAAO;GAAE,OAAO,EAAM,MAAM,GAAG,CAAK;GAAG,MAAM,EAAM,SAAS,IAAQ,IAAS,IAAQ;EAAK;CAC5F,CAAC;CACD,OAAO;EAAE,OAAO,EAAE,MAAM,SAAS;EAAU,SAAS,EAAE,WAAY,CAAC,CAAC,KAAO,CAAC,EAAE;EAAS,OAAO,EAAE;EAAO,SAAS,EAAE,OAAO,EAAE,KAAK,SAAS,OAAO;EAAO,QAAQ,EAAE;CAAO;AAC1K"}
@@ -1,6 +1,7 @@
1
1
  import { ContentKitClient } from '../client/client.js';
2
2
  import { ContentKitError } from '../client/errors.js';
3
- import { PlanSegment, ReaderPlan } from '../client/generated/wire.js';
3
+ import { FileDownload, PlanSegment, ReaderPlan } from '../client/generated/wire.js';
4
+ import { Translator } from '../i18n/messages.js';
4
5
  import { ReadWindow } from './read.js';
5
6
  export interface UseReaderPlan {
6
7
  /** null while loading, pending or failed. */
@@ -44,14 +45,33 @@ export declare function useSegmentPages(segment: PlanSegment | null | undefined,
44
45
  client?: ContentKitClient;
45
46
  }): UseSegmentPages;
46
47
  export interface UseVersionDownload {
47
- /** Prepares the zip (asking again while it is prepared) and resolves with it. */
48
- download: () => Promise<Blob>;
49
- /** Prepared by the server, waiting. */
48
+ /**
49
+ * Grants the download (asking again while it is prepared), starts it in the
50
+ * browser and resolves with the grant.
51
+ */
52
+ download: () => Promise<FileDownload>;
53
+ /** Being prepared by the server, or granted and starting. */
50
54
  preparing: boolean;
51
55
  error?: ContentKitError;
56
+ /** While a quota refused: when the viewer may download again (ms). */
57
+ retryAt?: number;
58
+ /**
59
+ * What to tell the viewer about the last refusal: when a quota frees, when
60
+ * a download the site holds back opens ("available to download in N
61
+ * days"), a locked version, nothing to download, or a failure.
62
+ */
63
+ message?: string;
52
64
  }
53
- /** A version's pages as a zip, charged to the viewer's download quota. */
65
+ /** Starts a granted download: the browser fetches its URL, an attachment. */
66
+ export declare function startDownload(d: FileDownload): void;
67
+ /** The viewer's line for a download refusal at now. */
68
+ export declare function downloadMessage(m: Translator, err: ContentKitError | undefined, now?: number): string | undefined;
69
+ /**
70
+ * A version's download, charged to the viewer's download quota: the
71
+ * original or rendition its kind serves, or its pages as a zip.
72
+ */
54
73
  export declare function useVersionDownload(content: string, version: string, o?: {
55
74
  poll?: number;
56
75
  client?: ContentKitClient;
76
+ start?: (d: FileDownload) => void;
57
77
  }): UseVersionDownload;