@openrails/contentkit-ui 0.79.0 → 0.81.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -54
- package/dist/client/beacons.d.ts +53 -0
- package/dist/client/beacons.js +72 -0
- package/dist/client/beacons.js.map +1 -0
- package/dist/client/catalog.d.ts +2 -2
- package/dist/client/catalog.js +1 -1
- package/dist/client/catalog.js.map +1 -1
- package/dist/client/client.d.ts +24 -11
- package/dist/client/client.js +37 -29
- package/dist/client/client.js.map +1 -1
- package/dist/client/content/comments.d.ts +12 -8
- package/dist/client/content/comments.js +33 -20
- package/dist/client/content/comments.js.map +1 -1
- package/dist/client/content/favorites.d.ts +24 -9
- package/dist/client/content/favorites.js +21 -22
- package/dist/client/content/favorites.js.map +1 -1
- package/dist/client/content/moderation.d.ts +1 -1
- package/dist/client/content/moderation.js.map +1 -1
- package/dist/client/content/reactions.d.ts +11 -6
- package/dist/client/content/reactions.js +23 -18
- package/dist/client/content/reactions.js.map +1 -1
- package/dist/client/content/types.d.ts +40 -21
- package/dist/client/content/types.js +5 -2
- package/dist/client/content/types.js.map +1 -1
- package/dist/client/contents.d.ts +55 -0
- package/dist/client/contents.js +144 -0
- package/dist/client/contents.js.map +1 -0
- package/dist/client/discovery.d.ts +126 -0
- package/dist/client/discovery.js +125 -0
- package/dist/client/discovery.js.map +1 -0
- package/dist/client/generated/error-codes.d.ts +1 -1
- package/dist/client/generated/error-codes.js +12 -0
- package/dist/client/generated/error-codes.js.map +1 -1
- package/dist/client/generated/routes.d.ts +1244 -370
- package/dist/client/generated/routes.js +1870 -554
- package/dist/client/generated/routes.js.map +1 -1
- package/dist/client/generated/wire.d.ts +960 -134
- package/dist/client/generated/wire.js.map +1 -1
- package/dist/client/group-fields.d.ts +25 -0
- package/dist/client/group-fields.js +63 -0
- package/dist/client/group-fields.js.map +1 -0
- package/dist/client/groups.d.ts +58 -0
- package/dist/client/groups.js +119 -0
- package/dist/client/groups.js.map +1 -0
- package/dist/client/http.d.ts +24 -12
- package/dist/client/http.js +20 -24
- package/dist/client/http.js.map +1 -1
- package/dist/client/index.d.ts +11 -6
- package/dist/client/media/api.d.ts +1 -1
- package/dist/client/media/api.js +4 -2
- package/dist/client/media/api.js.map +1 -1
- package/dist/client/media/client.d.ts +8 -9
- package/dist/client/media/client.js +58 -71
- package/dist/client/media/client.js.map +1 -1
- package/dist/client/media/ref.d.ts +30 -0
- package/dist/client/media/ref.js +10 -3
- package/dist/client/media/ref.js.map +1 -1
- package/dist/client/offers.d.ts +41 -0
- package/dist/client/offers.js +66 -0
- package/dist/client/offers.js.map +1 -0
- package/dist/client/route.d.ts +2 -0
- package/dist/client/route.js +2 -1
- package/dist/client/route.js.map +1 -1
- package/dist/client/versions.d.ts +20 -0
- package/dist/client/versions.js +53 -0
- package/dist/client/versions.js.map +1 -0
- package/dist/client.js +35 -30
- package/dist/components/admin/content-manager.d.ts +80 -0
- package/dist/components/admin/content-manager.js +591 -0
- package/dist/components/admin/content-manager.js.map +1 -0
- package/dist/components/admin/group-manager.d.ts +24 -0
- package/dist/components/admin/group-manager.js +244 -0
- package/dist/components/admin/group-manager.js.map +1 -0
- package/dist/components/admin/media-item-panel.js +1 -1
- package/dist/components/admin/media-item-panel.js.map +1 -1
- package/dist/components/content/card.d.ts +44 -0
- package/dist/components/content/card.js +285 -0
- package/dist/components/content/card.js.map +1 -0
- package/dist/components/content/editors.d.ts +40 -0
- package/dist/components/content/editors.js +764 -0
- package/dist/components/content/editors.js.map +1 -0
- package/dist/components/content/filters.d.ts +28 -0
- package/dist/components/content/filters.js +134 -0
- package/dist/components/content/filters.js.map +1 -0
- package/dist/components/content/grid.d.ts +62 -0
- package/dist/components/content/grid.js +233 -0
- package/dist/components/content/grid.js.map +1 -0
- package/dist/components/content/index.d.ts +8 -0
- package/dist/components/content/listing.d.ts +20 -0
- package/dist/components/content/listing.js +150 -0
- package/dist/components/content/listing.js.map +1 -0
- package/dist/components/content/offer-fields.d.ts +8 -0
- package/dist/components/content/offer-fields.js +127 -0
- package/dist/components/content/offer-fields.js.map +1 -0
- package/dist/components/content/paywall.d.ts +53 -0
- package/dist/components/content/paywall.js +221 -0
- package/dist/components/content/paywall.js.map +1 -0
- package/dist/components/content/search.d.ts +27 -0
- package/dist/components/content/search.js +164 -0
- package/dist/components/content/search.js.map +1 -0
- package/dist/components/groups/banner.d.ts +51 -0
- package/dist/components/groups/banner.js +194 -0
- package/dist/components/groups/banner.js.map +1 -0
- package/dist/components/groups/directory.d.ts +37 -0
- package/dist/components/groups/directory.js +117 -0
- package/dist/components/groups/directory.js.map +1 -0
- package/dist/components/groups/editor.d.ts +44 -0
- package/dist/components/groups/editor.js +860 -0
- package/dist/components/groups/editor.js.map +1 -0
- package/dist/components/groups/fields.d.ts +13 -0
- package/dist/components/groups/fields.js +68 -0
- package/dist/components/groups/fields.js.map +1 -0
- package/dist/components/groups/header.d.ts +25 -0
- package/dist/components/groups/header.js +131 -0
- package/dist/components/groups/header.js.map +1 -0
- package/dist/components/groups/index.d.ts +6 -0
- package/dist/components/groups/memberships.d.ts +55 -0
- package/dist/components/groups/memberships.js +527 -0
- package/dist/components/groups/memberships.js.map +1 -0
- package/dist/components/groups/parts.d.ts +49 -0
- package/dist/components/groups/parts.js +172 -0
- package/dist/components/groups/parts.js.map +1 -0
- package/dist/components/media-folder-editor.js +153 -152
- package/dist/components/media-folder-editor.js.map +1 -1
- package/dist/components/social/comments.d.ts +7 -5
- package/dist/components/social/comments.js +6 -2
- package/dist/components/social/comments.js.map +1 -1
- package/dist/components/social/engagement.d.ts +4 -3
- package/dist/components/social/engagement.js.map +1 -1
- package/dist/components/social/moderation.d.ts +1 -1
- package/dist/components/social/moderation.js +3 -3
- package/dist/components/social/moderation.js.map +1 -1
- package/dist/editor/rich-text-editor.d.ts +4 -4
- package/dist/editor/rich-text-editor.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +23 -9
- package/dist/locales/admin/de.js +5 -66
- package/dist/locales/admin/de.js.map +1 -1
- package/dist/locales/admin/en.d.ts +5 -66
- package/dist/locales/admin/en.js +19 -80
- package/dist/locales/admin/en.js.map +1 -1
- package/dist/locales/admin/es.js +5 -66
- package/dist/locales/admin/es.js.map +1 -1
- package/dist/locales/admin/ja.js +5 -66
- package/dist/locales/admin/ja.js.map +1 -1
- package/dist/locales/admin/ko.js +5 -66
- package/dist/locales/admin/ko.js.map +1 -1
- package/dist/locales/admin/zh.js +5 -66
- package/dist/locales/admin/zh.js.map +1 -1
- package/dist/locales/content/de.d.ts +2 -0
- package/dist/locales/content/de.js +98 -0
- package/dist/locales/content/de.js.map +1 -0
- package/dist/locales/content/en.d.ts +93 -0
- package/dist/locales/content/en.js +98 -0
- package/dist/locales/content/en.js.map +1 -0
- package/dist/locales/content/es.d.ts +2 -0
- package/dist/locales/content/es.js +98 -0
- package/dist/locales/content/es.js.map +1 -0
- package/dist/locales/content/ja.d.ts +2 -0
- package/dist/locales/content/ja.js +98 -0
- package/dist/locales/content/ja.js.map +1 -0
- package/dist/locales/content/ko.d.ts +2 -0
- package/dist/locales/content/ko.js +98 -0
- package/dist/locales/content/ko.js.map +1 -0
- package/dist/locales/content/zh.d.ts +2 -0
- package/dist/locales/content/zh.js +98 -0
- package/dist/locales/content/zh.js.map +1 -0
- package/dist/locales/de.js +11 -2
- package/dist/locales/de.js.map +1 -1
- package/dist/locales/discovery/de.d.ts +2 -0
- package/dist/locales/discovery/de.js +68 -0
- package/dist/locales/discovery/de.js.map +1 -0
- package/dist/locales/discovery/en.d.ts +63 -0
- package/dist/locales/discovery/en.js +68 -0
- package/dist/locales/discovery/en.js.map +1 -0
- package/dist/locales/discovery/es.d.ts +2 -0
- package/dist/locales/discovery/es.js +68 -0
- package/dist/locales/discovery/es.js.map +1 -0
- package/dist/locales/discovery/ja.d.ts +2 -0
- package/dist/locales/discovery/ja.js +68 -0
- package/dist/locales/discovery/ja.js.map +1 -0
- package/dist/locales/discovery/ko.d.ts +2 -0
- package/dist/locales/discovery/ko.js +68 -0
- package/dist/locales/discovery/ko.js.map +1 -0
- package/dist/locales/discovery/zh.d.ts +2 -0
- package/dist/locales/discovery/zh.js +68 -0
- package/dist/locales/discovery/zh.js.map +1 -0
- package/dist/locales/en.d.ts +288 -67
- package/dist/locales/en.js +11 -2
- package/dist/locales/en.js.map +1 -1
- package/dist/locales/es.js +11 -2
- package/dist/locales/es.js.map +1 -1
- package/dist/locales/groups/de.d.ts +2 -0
- package/dist/locales/groups/de.js +133 -0
- package/dist/locales/groups/de.js.map +1 -0
- package/dist/locales/groups/en.d.ts +128 -0
- package/dist/locales/groups/en.js +133 -0
- package/dist/locales/groups/en.js.map +1 -0
- package/dist/locales/groups/es.d.ts +2 -0
- package/dist/locales/groups/es.js +133 -0
- package/dist/locales/groups/es.js.map +1 -0
- package/dist/locales/groups/ja.d.ts +2 -0
- package/dist/locales/groups/ja.js +133 -0
- package/dist/locales/groups/ja.js.map +1 -0
- package/dist/locales/groups/ko.d.ts +2 -0
- package/dist/locales/groups/ko.js +133 -0
- package/dist/locales/groups/ko.js.map +1 -0
- package/dist/locales/groups/zh.d.ts +2 -0
- package/dist/locales/groups/zh.js +133 -0
- package/dist/locales/groups/zh.js.map +1 -0
- package/dist/locales/ja.js +11 -2
- package/dist/locales/ja.js.map +1 -1
- package/dist/locales/ko.js +11 -2
- package/dist/locales/ko.js.map +1 -1
- package/dist/locales/social/de.js +2 -1
- package/dist/locales/social/de.js.map +1 -1
- package/dist/locales/social/en.d.ts +2 -1
- package/dist/locales/social/en.js +2 -1
- package/dist/locales/social/en.js.map +1 -1
- package/dist/locales/social/es.js +2 -1
- package/dist/locales/social/es.js.map +1 -1
- package/dist/locales/social/ja.js +2 -1
- package/dist/locales/social/ja.js.map +1 -1
- package/dist/locales/social/ko.js +2 -1
- package/dist/locales/social/ko.js.map +1 -1
- package/dist/locales/social/zh.js +2 -1
- package/dist/locales/social/zh.js.map +1 -1
- package/dist/locales/zh.js +11 -2
- package/dist/locales/zh.js.map +1 -1
- package/dist/react/admin.d.ts +1 -1
- package/dist/react/admin.js +8 -6
- package/dist/react/admin.js.map +1 -1
- package/dist/react/comments.d.ts +9 -7
- package/dist/react/comments.js +42 -27
- package/dist/react/comments.js.map +1 -1
- package/dist/react/contents.d.ts +57 -0
- package/dist/react/contents.js +214 -0
- package/dist/react/contents.js.map +1 -0
- package/dist/react/context.d.ts +1 -1
- package/dist/react/context.js.map +1 -1
- package/dist/react/crop.js +45 -44
- package/dist/react/crop.js.map +1 -1
- package/dist/react/detail.d.ts +30 -0
- package/dist/react/detail.js +42 -0
- package/dist/react/detail.js.map +1 -0
- package/dist/react/discovery.d.ts +138 -0
- package/dist/react/discovery.js +299 -0
- package/dist/react/discovery.js.map +1 -0
- package/dist/react/engagement.d.ts +5 -5
- package/dist/react/engagement.js +55 -41
- package/dist/react/engagement.js.map +1 -1
- package/dist/react/folder.js +54 -53
- package/dist/react/folder.js.map +1 -1
- package/dist/react/groups.d.ts +115 -0
- package/dist/react/groups.js +229 -0
- package/dist/react/groups.js.map +1 -0
- package/dist/react/index.d.ts +5 -1
- package/dist/react/public.d.ts +6 -5
- package/dist/react/public.js +19 -22
- package/dist/react/public.js.map +1 -1
- package/dist/react/read.js +105 -106
- package/dist/react/read.js.map +1 -1
- package/dist/react/resources.d.ts +2 -2
- package/dist/react/resources.js +69 -40
- package/dist/react/resources.js.map +1 -1
- package/dist/react/store.js +41 -39
- package/dist/react/store.js.map +1 -1
- package/dist/react/upload.js +54 -53
- package/dist/react/upload.js.map +1 -1
- package/dist/react/use-resource.d.ts +2 -1
- package/dist/react/use-resource.js +1 -0
- package/dist/react/use-resource.js.map +1 -1
- package/dist/react/versions.d.ts +57 -0
- package/dist/react/versions.js +94 -0
- package/dist/react/versions.js.map +1 -0
- package/dist/react/video.js +87 -86
- package/dist/react/video.js.map +1 -1
- package/dist/react.js +9 -5
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/dist/client/content/posts.d.ts +0 -52
- package/dist/client/content/posts.js +0 -84
- package/dist/client/content/posts.js.map +0 -1
- package/dist/client/taxonomy.d.ts +0 -34
- package/dist/client/taxonomy.js +0 -84
- package/dist/client/taxonomy.js.map +0 -1
- package/dist/components/admin/post-manager.d.ts +0 -45
- package/dist/components/admin/post-manager.js +0 -602
- package/dist/components/admin/post-manager.js.map +0 -1
- package/dist/components/admin/taxonomy-manager.d.ts +0 -54
- package/dist/components/admin/taxonomy-manager.js +0 -976
- package/dist/components/admin/taxonomy-manager.js.map +0 -1
- package/dist/react/posts.d.ts +0 -61
- package/dist/react/posts.js +0 -183
- package/dist/react/posts.js.map +0 -1
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { useGuarded as e } from "./context.js";
|
|
2
|
+
import { keyOf as t, useContentScope as n, useList as r, useResource as i } from "./use-resource.js";
|
|
3
|
+
import { useCallback as a, useEffect as o, useMemo as s, useRef as c, useState as l } from "react";
|
|
4
|
+
//#region src/react/groups.ts
|
|
5
|
+
function u(e = {}) {
|
|
6
|
+
let { client: r, store: a } = n(e.client), o = i(a, t("kinds"), { type: "kinds" }, (e) => r.kinds(e));
|
|
7
|
+
return {
|
|
8
|
+
kinds: o.data ?? null,
|
|
9
|
+
loading: !o.data && (o.loading || !o.loaded),
|
|
10
|
+
error: o.error,
|
|
11
|
+
reload: o.reload
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function d(e = {}, i = {}) {
|
|
15
|
+
let { client: a, store: o, scope: s, language: c } = n(i.client), l = e.language ?? c, u = e.pageSize ?? 50;
|
|
16
|
+
return r(o, t("groups", s, e.kind, e.parent, e.scope, e.slug, e.letter, l, e.contentKind, e.sort, u), { type: "groups" }, async (t, n) => {
|
|
17
|
+
let r = await a.groups.list({
|
|
18
|
+
kind: e.kind,
|
|
19
|
+
parent: e.parent,
|
|
20
|
+
scope: e.scope,
|
|
21
|
+
slug: e.slug,
|
|
22
|
+
letter: e.letter,
|
|
23
|
+
language: l,
|
|
24
|
+
content_kind: e.contentKind,
|
|
25
|
+
sort: e.sort,
|
|
26
|
+
cursor: t,
|
|
27
|
+
limit: u
|
|
28
|
+
}, n);
|
|
29
|
+
return {
|
|
30
|
+
items: r.groups,
|
|
31
|
+
next: r.next_cursor ?? null
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function f(r, s = {}) {
|
|
36
|
+
let { client: u, store: d, scope: f, language: p } = n(s.client), m = s.language ?? p, [h, g] = l(null), [_, v] = l(null), [y, b] = l(null), x = _ ?? r ?? h;
|
|
37
|
+
o(() => {
|
|
38
|
+
v(null), b(null);
|
|
39
|
+
}, [r]);
|
|
40
|
+
let S = x && !y ? t("group", f, x, m) : null, C = i(d, S, {
|
|
41
|
+
type: "group",
|
|
42
|
+
id: x ?? void 0
|
|
43
|
+
}, (e) => u.groups.get(x, m, e), { initial: s.initial }), w = e(), [T, E] = l(0), D = a(async (e) => {
|
|
44
|
+
E((e) => e + 1);
|
|
45
|
+
try {
|
|
46
|
+
return await w(e);
|
|
47
|
+
} finally {
|
|
48
|
+
E((e) => e - 1);
|
|
49
|
+
}
|
|
50
|
+
}, [w]), O = a(() => {
|
|
51
|
+
if (!x) throw Error("contentkit-ui: create the group first");
|
|
52
|
+
return x;
|
|
53
|
+
}, [x]), [k, A] = l({}), j = c([]);
|
|
54
|
+
o(() => {
|
|
55
|
+
let e = j.current;
|
|
56
|
+
return () => e.forEach((e) => URL.revokeObjectURL(e));
|
|
57
|
+
}, []);
|
|
58
|
+
let M = C.data ?? null;
|
|
59
|
+
return {
|
|
60
|
+
group: y ? null : M,
|
|
61
|
+
deleted: y,
|
|
62
|
+
loading: !!S && (C.loading || !C.loaded && s.initial === void 0),
|
|
63
|
+
error: y ? void 0 : C.error,
|
|
64
|
+
saving: T > 0,
|
|
65
|
+
reload: C.reload,
|
|
66
|
+
create: a((e) => D(async () => {
|
|
67
|
+
let [t] = await u.groups.create([e]);
|
|
68
|
+
return g(t.id), t;
|
|
69
|
+
}), [u, D]),
|
|
70
|
+
update: a((e) => D(() => u.groups.update(O(), e)), [
|
|
71
|
+
u,
|
|
72
|
+
D,
|
|
73
|
+
O
|
|
74
|
+
]),
|
|
75
|
+
remove: a(() => D(async () => {
|
|
76
|
+
let e = await u.groups.remove(O());
|
|
77
|
+
return b(e), e;
|
|
78
|
+
}), [
|
|
79
|
+
u,
|
|
80
|
+
D,
|
|
81
|
+
O
|
|
82
|
+
]),
|
|
83
|
+
restore: a(() => D(async () => {
|
|
84
|
+
let e = await u.groups.update(O(), { state: "active" });
|
|
85
|
+
return b(null), e;
|
|
86
|
+
}), [
|
|
87
|
+
u,
|
|
88
|
+
D,
|
|
89
|
+
O
|
|
90
|
+
]),
|
|
91
|
+
names: a((e, t) => D(() => u.groups.names(O(), e, t)), [
|
|
92
|
+
u,
|
|
93
|
+
D,
|
|
94
|
+
O
|
|
95
|
+
]),
|
|
96
|
+
edges: a((e, t) => D(() => u.groups.edges(O(), e, t)), [
|
|
97
|
+
u,
|
|
98
|
+
D,
|
|
99
|
+
O
|
|
100
|
+
]),
|
|
101
|
+
merge: a((e) => D(async () => {
|
|
102
|
+
let t = await u.groups.merge(O(), e);
|
|
103
|
+
return v(t.into), t;
|
|
104
|
+
}), [
|
|
105
|
+
u,
|
|
106
|
+
D,
|
|
107
|
+
O
|
|
108
|
+
]),
|
|
109
|
+
uploadImage: a((e, t, n = {}) => D(async () => {
|
|
110
|
+
let r = M?.kind;
|
|
111
|
+
if (!r) throw Error("contentkit-ui: load the group first");
|
|
112
|
+
let i = await u.groups.uploadImage({
|
|
113
|
+
kind: r,
|
|
114
|
+
id: O()
|
|
115
|
+
}, e, t, n);
|
|
116
|
+
if (typeof URL.createObjectURL == "function" && !n.edit) {
|
|
117
|
+
let n = URL.createObjectURL(t);
|
|
118
|
+
j.current.push(n), A((t) => ({
|
|
119
|
+
...t,
|
|
120
|
+
[e]: n
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
return i;
|
|
124
|
+
}), [
|
|
125
|
+
u,
|
|
126
|
+
D,
|
|
127
|
+
O,
|
|
128
|
+
M?.kind
|
|
129
|
+
]),
|
|
130
|
+
previews: {
|
|
131
|
+
cover: M?.cover?.image ? k.cover : void 0,
|
|
132
|
+
avatar: M?.avatar?.image ? k.avatar : void 0
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function p(e = {}, i = {}) {
|
|
137
|
+
let { client: a, store: o, scope: s, viewer: c, language: l } = n(i.client), { pageSize: u, ...d } = e, f = {
|
|
138
|
+
language: l,
|
|
139
|
+
...d
|
|
140
|
+
};
|
|
141
|
+
return r(o, c === null ? null : t("groups-mine", s, f, u), { type: "groups-mine" }, async (e, t) => {
|
|
142
|
+
let n = await a.groups.mine({
|
|
143
|
+
...f,
|
|
144
|
+
cursor: e,
|
|
145
|
+
limit: u
|
|
146
|
+
}, t);
|
|
147
|
+
return {
|
|
148
|
+
items: n.groups,
|
|
149
|
+
next: n.next_cursor ?? null
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
var m = (e) => [
|
|
154
|
+
e.group_id ?? "",
|
|
155
|
+
e.content_id ?? "",
|
|
156
|
+
e.version_id ?? "",
|
|
157
|
+
e.role ?? ""
|
|
158
|
+
].join("|");
|
|
159
|
+
function h(i, o = {}) {
|
|
160
|
+
let { client: s, store: c, scope: u } = n(o.client), d = o.pageSize ?? 50, f = r(c, i ? t("group-members", u, i, d) : null, {
|
|
161
|
+
type: "group-members",
|
|
162
|
+
id: i ?? void 0
|
|
163
|
+
}, async (e, t) => {
|
|
164
|
+
let n = await s.groups.members(i, {
|
|
165
|
+
cursor: e,
|
|
166
|
+
limit: d
|
|
167
|
+
}, t);
|
|
168
|
+
return {
|
|
169
|
+
items: n.members.map((e) => ({
|
|
170
|
+
...e,
|
|
171
|
+
id: m(e)
|
|
172
|
+
})),
|
|
173
|
+
next: n.next_cursor ?? null
|
|
174
|
+
};
|
|
175
|
+
}), p = e(), [h, g] = l(0), _ = a(async (e) => {
|
|
176
|
+
if (!i) throw Error("contentkit-ui: no group");
|
|
177
|
+
g((e) => e + 1);
|
|
178
|
+
try {
|
|
179
|
+
return (await p(() => e(i))).count;
|
|
180
|
+
} finally {
|
|
181
|
+
g((e) => e - 1);
|
|
182
|
+
}
|
|
183
|
+
}, [i, p]);
|
|
184
|
+
return {
|
|
185
|
+
...f,
|
|
186
|
+
saving: h > 0,
|
|
187
|
+
add: a((e) => _((t) => s.groups.addMembers(t, e)), [s, _]),
|
|
188
|
+
remove: a((e) => _((t) => s.groups.removeMembers(t, e)), [s, _]),
|
|
189
|
+
reorder: a((e) => _((t) => s.groups.reorder(t, e)), [s, _])
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function g(r, o = {}) {
|
|
193
|
+
let { client: c, store: u, scope: d, language: f } = n(o.client), p = o.language ?? f, m = r ? t("group-memberships", d, r, p) : null, h = i(u, m, {
|
|
194
|
+
type: "group-memberships",
|
|
195
|
+
id: r ?? void 0
|
|
196
|
+
}, (e) => c.groups.ofContent(r, p, e)), g = e(), [_, v] = l(0), y = a(async (e, t) => {
|
|
197
|
+
if (!r) throw Error("contentkit-ui: no content");
|
|
198
|
+
v((e) => e + 1);
|
|
199
|
+
try {
|
|
200
|
+
let n = await g(() => c.groups.setOfContent(r, {
|
|
201
|
+
kinds: t,
|
|
202
|
+
memberships: e
|
|
203
|
+
}, p));
|
|
204
|
+
return m && u.set(m, n), n;
|
|
205
|
+
} finally {
|
|
206
|
+
v((e) => e - 1);
|
|
207
|
+
}
|
|
208
|
+
}, [
|
|
209
|
+
c,
|
|
210
|
+
r,
|
|
211
|
+
p,
|
|
212
|
+
g,
|
|
213
|
+
u,
|
|
214
|
+
m
|
|
215
|
+
]), b = s(() => new Map((h.data?.groups ?? []).map((e) => [e.id, e])), [h.data]);
|
|
216
|
+
return {
|
|
217
|
+
memberships: h.data?.memberships ?? [],
|
|
218
|
+
groups: b,
|
|
219
|
+
loading: !!m && (h.loading || !h.loaded),
|
|
220
|
+
error: h.error,
|
|
221
|
+
saving: _ > 0,
|
|
222
|
+
reload: h.reload,
|
|
223
|
+
set: y
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
//#endregion
|
|
227
|
+
export { m as memberId, g as useContentGroups, f as useGroup, h as useGroupMembers, d as useGroups, u as useKinds, p as useMyGroups };
|
|
228
|
+
|
|
229
|
+
//# sourceMappingURL=groups.js.map
|
|
@@ -0,0 +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,IA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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"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -11,7 +11,11 @@ export { useAdminComments, useCanComment, useCommentBans, useGlobalCommentBan, u
|
|
|
11
11
|
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
|
-
export {
|
|
14
|
+
export { useContent, useManagedContents, type ManageFilter, type UseContent } from './contents.js';
|
|
15
|
+
export { defaultVersion, liveVersions, useContentDetail, type UseContentDetail } from './detail.js';
|
|
16
|
+
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';
|
|
15
19
|
export { useContentScope, usePaged, type UseList, type UsePaged } from './use-resource.js';
|
|
16
20
|
export { ResourceStore, resourcesFor, type Page, type Resource } from './resources.js';
|
|
17
21
|
export { useCrop, useEncodeProgress, useUpload, useUploadQueue, type UploadQueueOptions, type UploadStatus, type UseCrop, type UseCropOptions, type UseEncodeProgress, type UseUpload, type UseUploadQueue, } from './upload.js';
|
package/dist/react/public.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ContentKitClient } from '../client/client.js';
|
|
2
2
|
import { ContentKitError } from '../client/errors.js';
|
|
3
|
-
import { ReadResult, PresetRule } from '../client/generated/wire.js';
|
|
3
|
+
import { ReadResult, RefBody, PresetRule } from '../client/generated/wire.js';
|
|
4
4
|
import { PublicPreset } from '../client/public.js';
|
|
5
5
|
export interface UsePresets {
|
|
6
6
|
/** Every kind's public presets; empty until they load (or when the server has none). */
|
|
@@ -32,8 +32,9 @@ export interface UsePublicImage {
|
|
|
32
32
|
reload: () => void;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* An item's public image for a preset ("avatar", "cover"
|
|
36
|
-
* renditions from a read's `public` (or the host's
|
|
37
|
-
* default image, else none. Reads refresh after
|
|
35
|
+
* An item's public image for a preset ("avatar", "cover", a version's
|
|
36
|
+
* "poster"): the exact renditions from a read's `public` (or the host's
|
|
37
|
+
* listing), else the kind's default image, else none. Reads refresh after
|
|
38
|
+
* commits through the same client.
|
|
38
39
|
*/
|
|
39
|
-
export declare function usePublicImage(
|
|
40
|
+
export declare function usePublicImage(item: RefBody, preset: string, o?: PublicImageOptions): UsePublicImage;
|
package/dist/react/public.js
CHANGED
|
@@ -21,31 +21,28 @@ function u(e = {}) {
|
|
|
21
21
|
error: i?.error
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
function d(a, s, c
|
|
25
|
-
let d = r(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
prefix: g,
|
|
30
|
-
read: h || !p ? null : l.read,
|
|
31
|
-
client: d
|
|
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, {
|
|
26
|
+
prefix: _,
|
|
27
|
+
read: g || !m ? null : c.read,
|
|
28
|
+
client: f
|
|
32
29
|
});
|
|
33
30
|
return {
|
|
34
31
|
...o(() => {
|
|
35
|
-
let t =
|
|
32
|
+
let t = g ? c.image : v.read?.public?.find((e) => e.preset === s);
|
|
36
33
|
if (t && t.renditions.length) return {
|
|
37
34
|
image: {
|
|
38
|
-
preset:
|
|
35
|
+
preset: s,
|
|
39
36
|
renditions: t.renditions,
|
|
40
|
-
aspect: "aspect" in t && t.aspect ||
|
|
37
|
+
aspect: "aspect" in t && t.aspect || h?.aspect
|
|
41
38
|
},
|
|
42
39
|
isDefault: !1
|
|
43
40
|
};
|
|
44
|
-
if (!
|
|
41
|
+
if (!g && !v.read) return {
|
|
45
42
|
image: null,
|
|
46
43
|
isDefault: !1
|
|
47
44
|
};
|
|
48
|
-
let n =
|
|
45
|
+
let n = h && e(h, d);
|
|
49
46
|
return n ? {
|
|
50
47
|
image: n,
|
|
51
48
|
isDefault: !0
|
|
@@ -54,17 +51,17 @@ function d(a, s, c, l = {}) {
|
|
|
54
51
|
isDefault: !1
|
|
55
52
|
};
|
|
56
53
|
}, [
|
|
54
|
+
g,
|
|
55
|
+
c.image,
|
|
56
|
+
v.read,
|
|
57
|
+
s,
|
|
57
58
|
h,
|
|
58
|
-
|
|
59
|
-
_.read,
|
|
60
|
-
c,
|
|
61
|
-
m,
|
|
62
|
-
s
|
|
59
|
+
d
|
|
63
60
|
]),
|
|
64
|
-
rule:
|
|
65
|
-
loading: !
|
|
66
|
-
error:
|
|
67
|
-
reload:
|
|
61
|
+
rule: h,
|
|
62
|
+
loading: !m || v.loading,
|
|
63
|
+
error: v.error,
|
|
64
|
+
reload: v.reload
|
|
68
65
|
};
|
|
69
66
|
}
|
|
70
67
|
//#endregion
|
package/dist/react/public.js.map
CHANGED
|
@@ -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 } 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\"): the exact
|
|
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,C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,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"}
|
package/dist/react/read.js
CHANGED
|
@@ -1,144 +1,143 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { itemRef as e } from "../client/media/ref.js";
|
|
2
|
+
import { useOptionalContentKitClient as t, useReadScope as n } from "./context.js";
|
|
3
|
+
import { chunkOffsets as r, mergeReads as i, processing as a } from "../client/media/windows.js";
|
|
4
|
+
import { readKey as o, storeFor as s } from "./store.js";
|
|
5
|
+
import { useCallback as c, useEffect as l, useMemo as u, useRef as d, useState as f, useSyncExternalStore as ee } from "react";
|
|
5
6
|
//#region src/react/read.ts
|
|
6
|
-
var te = 2500,
|
|
7
|
-
function
|
|
8
|
-
let { read:
|
|
9
|
-
prefix:
|
|
10
|
-
download:
|
|
11
|
-
editor:
|
|
12
|
-
}) + (
|
|
13
|
-
base:
|
|
7
|
+
var te = 2500, p = [];
|
|
8
|
+
function m(m, h = {}) {
|
|
9
|
+
let { read: g, client: _, prefix: v, offset: y, limit: b, download: x, editor: S, window: C, refresh: w = !0 } = h, T = h.poll ?? (S ? te : !1), E = t(_), D = n(), O = E ? s(E) : null, k = C?.chunk ?? 50, A = D + o(m, {
|
|
10
|
+
prefix: v,
|
|
11
|
+
download: x,
|
|
12
|
+
editor: S
|
|
13
|
+
}) + (C ? `#${k}` : `#${y ?? 0}:${b ?? 0}`), [j, M] = f({ base: A }), N = j.base === A ? j.n : void 0, P = C ? r(C.start, C.end, N ?? C.start + 1, k) : [], [F, I] = f({
|
|
14
|
+
base: A,
|
|
14
15
|
offsets: []
|
|
15
|
-
}),
|
|
16
|
-
|
|
17
|
-
base:
|
|
18
|
-
offsets: [.../* @__PURE__ */ new Set([...
|
|
16
|
+
}), L = F.base === A ? F.offsets : [];
|
|
17
|
+
C && (F.base !== A || P.some((e) => !L.includes(e))) && I({
|
|
18
|
+
base: A,
|
|
19
|
+
offsets: [.../* @__PURE__ */ new Set([...L, ...P])].sort((e, t) => e - t)
|
|
19
20
|
});
|
|
20
|
-
let
|
|
21
|
+
let R = C ? L.length ? L : P.length ? P : [0] : [y ?? 0], z = u(() => R.map((e) => ({
|
|
21
22
|
offset: e,
|
|
22
|
-
limit:
|
|
23
|
-
})), [
|
|
24
|
-
prefix:
|
|
25
|
-
download:
|
|
26
|
-
editor:
|
|
23
|
+
limit: C ? k : b
|
|
24
|
+
})), [R.join(","), C ? k : b]), B = u(() => z.map((e) => D + o(m, {
|
|
25
|
+
prefix: v,
|
|
26
|
+
download: x,
|
|
27
|
+
editor: S,
|
|
27
28
|
offset: e.offset,
|
|
28
29
|
limit: e.limit
|
|
29
30
|
})), [
|
|
30
|
-
E,
|
|
31
|
-
R,
|
|
32
|
-
p.kind,
|
|
33
|
-
p.id,
|
|
34
|
-
_,
|
|
35
|
-
b,
|
|
36
|
-
x
|
|
37
|
-
]), [B, V] = u(null), [H, U] = u(null), W = B?.base === k && B.given === h ? B : null, G = !!D && (h === void 0 || !!W), K = o((e) => {
|
|
38
|
-
if (!D || !G) return () => {};
|
|
39
|
-
let t = z.map((t, n) => D.subscribe(t, {
|
|
40
|
-
kind: p.kind,
|
|
41
|
-
id: p.id
|
|
42
|
-
}, {
|
|
43
|
-
prefix: _,
|
|
44
|
-
download: b,
|
|
45
|
-
editor: x,
|
|
46
|
-
...R[n]
|
|
47
|
-
}, e, {
|
|
48
|
-
poll: w,
|
|
49
|
-
refresh: C
|
|
50
|
-
}, E));
|
|
51
|
-
return () => t.forEach((e) => e());
|
|
52
|
-
}, [
|
|
53
31
|
D,
|
|
54
|
-
G,
|
|
55
32
|
z,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
33
|
+
m.kind,
|
|
34
|
+
m.id,
|
|
35
|
+
m.version,
|
|
36
|
+
v,
|
|
37
|
+
x,
|
|
38
|
+
S
|
|
39
|
+
]), [V, H] = f(null), [U, W] = f(null), G = V?.base === A && V.given === g ? V : null, K = !!O && (g === void 0 || !!G), ne = c((t) => {
|
|
40
|
+
if (!O || !K) return () => {};
|
|
41
|
+
let n = B.map((n, r) => O.subscribe(n, e(m), {
|
|
42
|
+
prefix: v,
|
|
43
|
+
download: x,
|
|
44
|
+
editor: S,
|
|
45
|
+
...z[r]
|
|
46
|
+
}, t, {
|
|
47
|
+
poll: T,
|
|
48
|
+
refresh: w
|
|
49
|
+
}, D));
|
|
50
|
+
return () => n.forEach((e) => e());
|
|
51
|
+
}, [
|
|
52
|
+
O,
|
|
53
|
+
K,
|
|
54
|
+
B,
|
|
55
|
+
T,
|
|
56
|
+
w
|
|
57
|
+
]), q = d(p), J = c(() => {
|
|
58
|
+
if (!O || !K) return p;
|
|
59
|
+
let e = B.map((e) => O.snapshot(e)), t = q.current;
|
|
61
60
|
return t.length === e.length && t.every((t, n) => t === e[n]) ? t : q.current = e;
|
|
62
61
|
}, [
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
]), Y =
|
|
67
|
-
|
|
68
|
-
if (
|
|
62
|
+
O,
|
|
63
|
+
K,
|
|
64
|
+
B
|
|
65
|
+
]), Y = ee(ne, J, J);
|
|
66
|
+
l(() => {
|
|
67
|
+
if (O && K) for (let e of B) O.load(e, G ? "reload" : "initial");
|
|
69
68
|
}, [
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
O,
|
|
70
|
+
K,
|
|
71
|
+
B,
|
|
72
|
+
G
|
|
74
73
|
]);
|
|
75
|
-
let X =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
base:
|
|
74
|
+
let X = u(() => i(Y.map((e) => e.read)), [Y]);
|
|
75
|
+
l(() => {
|
|
76
|
+
C && X && X.total !== N && M({
|
|
77
|
+
base: A,
|
|
79
78
|
n: X.total
|
|
80
79
|
});
|
|
81
80
|
}, [
|
|
82
|
-
|
|
81
|
+
C,
|
|
83
82
|
X,
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
N,
|
|
84
|
+
A
|
|
86
85
|
]);
|
|
87
|
-
let
|
|
88
|
-
if (
|
|
89
|
-
base:
|
|
90
|
-
given:
|
|
86
|
+
let re = c(() => {
|
|
87
|
+
if (g !== void 0) H({
|
|
88
|
+
base: A,
|
|
89
|
+
given: g
|
|
91
90
|
});
|
|
92
|
-
else if (
|
|
93
|
-
|
|
91
|
+
else if (O) for (let e of B) O.load(e, "reload");
|
|
92
|
+
W(null);
|
|
94
93
|
}, [
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
]),
|
|
100
|
-
if (
|
|
101
|
-
base:
|
|
102
|
-
given:
|
|
94
|
+
O,
|
|
95
|
+
B,
|
|
96
|
+
A,
|
|
97
|
+
g
|
|
98
|
+
]), ie = c(() => {
|
|
99
|
+
if (g !== void 0 && !G) H({
|
|
100
|
+
base: A,
|
|
101
|
+
given: g
|
|
103
102
|
});
|
|
104
|
-
else if (
|
|
103
|
+
else if (O) for (let e of B) O.load(e, "refresh");
|
|
105
104
|
}, [
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
]),
|
|
112
|
-
if (
|
|
113
|
-
else
|
|
114
|
-
base:
|
|
115
|
-
given:
|
|
105
|
+
O,
|
|
106
|
+
B,
|
|
107
|
+
A,
|
|
108
|
+
g,
|
|
109
|
+
G
|
|
110
|
+
]), ae = c((e) => {
|
|
111
|
+
if (O && K) for (let t of B) O.set(t, e);
|
|
112
|
+
else W({
|
|
113
|
+
base: A,
|
|
114
|
+
given: g,
|
|
116
115
|
read: e
|
|
117
116
|
});
|
|
118
117
|
}, [
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
118
|
+
O,
|
|
119
|
+
K,
|
|
120
|
+
B,
|
|
121
|
+
A,
|
|
122
|
+
g
|
|
124
123
|
]), Z, Q = !1, $;
|
|
125
|
-
if (
|
|
126
|
-
else if (!Y.length) Z =
|
|
124
|
+
if (U && U.base === A && U.given === g) Z = U.read;
|
|
125
|
+
else if (!Y.length) Z = g ?? null;
|
|
127
126
|
else {
|
|
128
127
|
let e = Y.every((e) => e.loaded);
|
|
129
|
-
Z = X ?? (e ? null :
|
|
128
|
+
Z = X ?? (e ? null : g ?? null), Q = Y.some((e) => e.loading || !e.loaded), $ = Y.find((e) => e.error)?.error;
|
|
130
129
|
}
|
|
131
130
|
return {
|
|
132
131
|
read: Z,
|
|
133
132
|
loading: Q,
|
|
134
133
|
error: $,
|
|
135
|
-
processing:
|
|
136
|
-
reload:
|
|
137
|
-
refresh:
|
|
138
|
-
set:
|
|
134
|
+
processing: a(Z),
|
|
135
|
+
reload: re,
|
|
136
|
+
refresh: ie,
|
|
137
|
+
set: ae
|
|
139
138
|
};
|
|
140
139
|
}
|
|
141
140
|
//#endregion
|
|
142
|
-
export {
|
|
141
|
+
export { m as useMediaRead };
|
|
143
142
|
|
|
144
143
|
//# sourceMappingURL=read.js.map
|