@openrails/contentkit-ui 0.104.0 → 0.105.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.
@@ -14,14 +14,14 @@ import { MediaFolderEditor as c, positionalName as oe } from "../media-folder-ed
14
14
  import { Badge as se } from "../../ui/badge.js";
15
15
  import { Input as ce } from "../../ui/input.js";
16
16
  import { Label as l } from "../../ui/label.js";
17
- import { Select as u, SelectContent as le, SelectItem as ue, SelectTrigger as de, SelectValue as fe } from "../../ui/select.js";
18
- import { Textarea as pe } from "../../ui/textarea.js";
19
- import { ErrorLine as d, contentError as me, useAction as he } from "../social/parts.js";
20
- import { LoadFailed as ge, Rows as _e, useConfirm as ve } from "./shell.js";
21
- import { localInput as ye } from "../social/bans.js";
22
- import { parseAttributes as be } from "../../client/group-fields.js";
23
- import { labelOf as xe } from "../groups/parts.js";
24
- import { useDraft as Se } from "../../react/use-draft.js";
17
+ import { Select as le, SelectContent as ue, SelectItem as de, SelectTrigger as fe, SelectValue as pe } from "../../ui/select.js";
18
+ import { Textarea as me } from "../../ui/textarea.js";
19
+ import { ErrorLine as u, contentError as he, useAction as ge } from "../social/parts.js";
20
+ import { LoadFailed as _e, Rows as ve, useConfirm as ye } from "./shell.js";
21
+ import { localInput as be } from "../social/bans.js";
22
+ import { parseAttributes as xe } from "../../client/group-fields.js";
23
+ import { labelOf as Se } from "../groups/parts.js";
24
+ import { useDraft as d } from "../../react/use-draft.js";
25
25
  import { EditorSaveContext as Ce, readerMediaReady as we, useEditorSaveCoordinator as Te } from "../content/editor-save.js";
26
26
  import { OfferFields as Ee } from "../content/offer-fields.js";
27
27
  import { AttributeFields as De, formOf as Oe } from "../groups/fields.js";
@@ -30,13 +30,13 @@ import { usePageNotices as Ae } from "../../react/page-notices.js";
30
30
  import { EntityChips as je } from "../groups/entity-chips.js";
31
31
  import { ReaderManifestEditor as Me } from "./reader-manifest.js";
32
32
  import { PageNotices as Ne } from "./page-notices.js";
33
- import { RuleFields as Pe, VersionsEditor as Fe, cleanRule as Ie, complete as Le, versionLabel as Re } from "../content/editors.js";
34
- import { fileTitle as ze } from "./bulk-drafts.js";
35
- import { contentStatus as Be } from "./content-manager.js";
36
- import { useEffect as f, useId as Ve, useMemo as p, useRef as m, useState as h } from "react";
37
- import { jsx as g, jsxs as _ } from "react/jsx-runtime";
33
+ import { RuleFields as Pe, VersionsEditor as Fe, allowsIndividualSales as Ie, cleanRule as Le, complete as Re, defaultAccessRule as ze, versionLabel as Be } from "../content/editors.js";
34
+ import { fileTitle as Ve } from "./bulk-drafts.js";
35
+ import { contentStatus as He } from "./content-manager.js";
36
+ import { useEffect as f, useId as Ue, useMemo as p, useRef as m, useState as h } from "react";
37
+ import { Fragment as We, jsx as g, jsxs as _ } from "react/jsx-runtime";
38
38
  //#region src/components/admin/reader-content-editor.tsx
39
- var He = {
39
+ var Ge = {
40
40
  kind: "",
41
41
  id: ""
42
42
  }, v = () => ({
@@ -44,12 +44,12 @@ var He = {
44
44
  slug: "",
45
45
  description: "",
46
46
  body: ""
47
- }), Ue = (e, t) => e?.text?.[t] ?? (e?.language === t ? {
47
+ }), Ke = (e, t) => e?.text?.[t] ?? (e?.language === t ? {
48
48
  title: e.title,
49
49
  slug: e.slug,
50
50
  description: e.description,
51
51
  body: e.body
52
- } : v()), We = (e) => ({
52
+ } : v()), qe = (e) => ({
53
53
  ...e,
54
54
  title: e.title.trim(),
55
55
  description: e.description?.trim()
@@ -65,18 +65,18 @@ function b({ title: e, label: t, children: n, className: r = "" }) {
65
65
  });
66
66
  }
67
67
  function x(x) {
68
- let { client: S, scope: Ge } = te(x.client), Ke = r(), { t: C } = Ke, w = Ve(), qe = ee(), Je = i(x.onError), T = x.model, E = T.kinds[x.kind], Ye = x.languages?.map((e) => typeof e == "string" ? {
68
+ let { client: S, scope: Je } = te(x.client), Ye = r(), { t: C } = Ye, w = Ue(), Xe = ee(), Ze = i(x.onError), T = x.model, E = T.kinds[x.kind], Qe = x.languages?.map((e) => typeof e == "string" ? {
69
69
  value: e,
70
70
  label: e
71
- } : e), D = Ye?.length ? Ye : T.languages.map((e) => ({
71
+ } : e), D = Qe?.length ? Qe : T.languages.map((e) => ({
72
72
  value: e,
73
73
  label: e
74
- })), Xe = D.map((e) => e.value).join("|"), [O, Ze] = h(D[0]?.value ?? "en"), [Qe, $e] = h(""), k = ke(x.id, x.kind, O, {
74
+ })), $e = D.map((e) => e.value).join("|"), [O, et] = h(D[0]?.value ?? "en"), [tt, nt] = h(""), k = ke(x.id, x.kind, O, {
75
75
  client: S,
76
- version: Qe || void 0
77
- }), [et, tt] = h(null), A = k.content ?? et, j = m({
76
+ version: tt || void 0
77
+ }), [rt, it] = h(null), A = k.content ?? rt, j = m({
78
78
  item: A,
79
- scope: Ge,
79
+ scope: Je,
80
80
  alive: !0
81
81
  });
82
82
  j.current.item = A, f(() => {
@@ -85,34 +85,37 @@ function x(x) {
85
85
  e.alive = !1;
86
86
  };
87
87
  }, []);
88
- let M = () => j.current.alive && j.current.scope === Ge, N = m(null), [nt, rt] = h(!1), [P, it] = h(!1), [F, I] = h(), [at, ot] = h(""), st = Se(p(() => ({ at: A?.publish_at ? ye(new Date(A.publish_at)) : "" }), [A?.publish_at])), ct = st.value.at, lt = (e) => st.edit({ at: e }), [ut, dt] = h(!1), [ft, pt] = h([]), [mt, ht] = h(!1), [L, gt] = h(null), [_t, vt] = h(null), R = p(() => [...A?.versions ?? []].sort((e, t) => e.position - t.position), [A?.versions]), z = R.find((e) => e.id === Qe) ?? R[0];
88
+ let M = () => j.current.alive && j.current.scope === Je, N = m(null), [at, ot] = h(!1), [P, st] = h(!1), [F, I] = h(), [ct, lt] = h(""), ut = d(p(() => ({ at: A?.publish_at ? be(new Date(A.publish_at)) : "" }), [A?.publish_at])), dt = ut.value.at, ft = (e) => ut.edit({ at: e }), [pt, mt] = h(!1), [ht, gt] = h([]), [_t, vt] = h(!1), [L, yt] = h(null), [bt, xt] = h(null), R = p(() => [...A?.versions ?? []].sort((e, t) => e.position - t.position), [A?.versions]), z = R.find((e) => e.id === tt) ?? R[0];
89
89
  f(() => {
90
- mt && z && pt((e) => e.includes(z.id) ? e : [...e, z.id]);
91
- }, [mt, z]);
90
+ _t && z && gt((e) => e.includes(z.id) ? e : [...e, z.id]);
91
+ }, [_t, z]);
92
92
  let B = ne(A?.id, {
93
93
  language: O,
94
94
  client: S
95
- }), yt = p(() => new Map(B.entities), [B.entities]), [bt, xt] = h(/* @__PURE__ */ new Map()), St = p(() => new Map([...bt, ...yt]), [yt, bt]), V = p(() => E.entities ?? [], [E.entities]), H = Se(p(() => Object.fromEntries(Xe.split("|").map((e) => [e, Ue(A, e)])), [A, Xe])), U = Se(p(() => ({
95
+ }), St = p(() => new Map(B.entities), [B.entities]), [Ct, wt] = h(/* @__PURE__ */ new Map()), Tt = p(() => new Map([...Ct, ...St]), [St, Ct]), V = p(() => E.entities ?? [], [E.entities]), H = d(p(() => Object.fromEntries($e.split("|").map((e) => [e, Ke(A, e)])), [A, $e])), U = d(p(() => ({
96
96
  listing: A?.listing ?? "listed",
97
- comments: A?.comments ?? "open",
97
+ comments: A?.comments ?? (!E.comment_modes?.length || E.comment_modes.includes("open") ? "open" : E.comment_modes[0]),
98
98
  attributes: Oe(E.attributes ?? {}, A?.attributes ?? {}),
99
- access: A?.access ?? { level: "public" }
99
+ access: A?.access ?? ze(T, x.kind)
100
100
  }), [
101
101
  A?.listing,
102
102
  A?.comments,
103
103
  A?.attributes,
104
104
  A?.access,
105
- E.attributes
106
- ])), W = Se(p(() => ({
105
+ E.attributes,
106
+ E.comment_modes,
107
+ T,
108
+ x.kind
109
+ ])), W = d(p(() => ({
107
110
  memberships: B.memberships.filter((e) => V.includes(B.entities.get(e.group_id ?? "")?.kind ?? "")),
108
111
  create: []
109
112
  }), [
110
113
  B.memberships,
111
114
  B.entities,
112
115
  V
113
- ])), Ct = (e, t, n) => {
116
+ ])), Et = (e, t, n) => {
114
117
  let r = T.entity_kinds[e]?.scoped_by;
115
- if (r) return new Set(t.filter((e) => St.get(e.group_id ?? "")?.kind === r).map((e) => e.group_id)).size + n.filter((e) => e.kind === r).length === 1 ? void 0 : xe(x.labels, r);
118
+ if (r) return new Set(t.filter((e) => Tt.get(e.group_id ?? "")?.kind === r).map((e) => e.group_id)).size + n.filter((e) => e.kind === r).length === 1 ? void 0 : Se(x.labels, r);
116
119
  }, G = Te(), K = m({
117
120
  texts: H,
118
121
  details: U,
@@ -125,12 +128,12 @@ function x(x) {
125
128
  associations: W,
126
129
  language: O
127
130
  };
128
- let wt = m(!1);
131
+ let Dt = m(!1);
129
132
  f(() => {
130
- if (wt.current || x.id || !x.entities?.length) return;
131
- wt.current = !0;
133
+ if (Dt.current || x.id || !x.entities?.length) return;
134
+ Dt.current = !0;
132
135
  let e = x.entities.filter((e) => V.includes(e.kind));
133
- e.length && (xt((t) => new Map([...t, ...e.map((e) => [e.id, e])])), K.current.associations.edit((t) => ({
136
+ e.length && (wt((t) => new Map([...t, ...e.map((e) => [e.id, e])])), K.current.associations.edit((t) => ({
134
137
  ...t,
135
138
  memberships: [...t.memberships, ...e.filter((e) => !t.memberships.some((t) => t.group_id === e.id)).map((e) => ({ group_id: e.id }))]
136
139
  })));
@@ -139,19 +142,19 @@ function x(x) {
139
142
  x.entities,
140
143
  V
141
144
  ]);
142
- let Tt = H.value[O] ?? v(), Et = (e) => H.edit((t) => ({
145
+ let Ot = H.value[O] ?? v(), kt = (e) => H.edit((t) => ({
143
146
  ...t,
144
147
  [O]: {
145
148
  ...t[O] ?? v(),
146
149
  ...e
147
150
  }
148
- })), Dt = (t) => {
149
- M() && (I(t instanceof y ? t.message : t), t instanceof y || Je(e(t), "content.save"));
150
- }, Ot = async (e) => {
151
+ })), At = (t) => {
152
+ M() && (I(t instanceof y ? t.message : t), t instanceof y || Ze(e(t), "content.save"));
153
+ }, jt = async (e) => {
151
154
  if (j.current.item) return j.current.item;
152
155
  if (N.current) return N.current;
153
- rt(!0);
154
- let t = K.current.language, n = K.current.texts.get()[t] ?? v(), r = n.title.trim() || ze(e ?? "") || C("readerEditor.untitled");
156
+ ot(!0);
157
+ let t = K.current.language, n = K.current.texts.get()[t] ?? v(), r = n.title.trim() || Ve(e ?? "") || C("readerEditor.untitled");
155
158
  n.title.trim() || K.current.texts.edit((e) => ({
156
159
  ...e,
157
160
  [t]: {
@@ -165,10 +168,12 @@ function x(x) {
165
168
  ...n,
166
169
  title: r
167
170
  } },
168
- owner_group_id: x.ownerGroup
171
+ owner_group_id: x.ownerGroup,
172
+ ...E.access_levels?.length ? { access: Le(K.current.details.get().access) } : {},
173
+ ...E.comment_modes?.length ? { comments: K.current.details.get().comments } : {}
169
174
  };
170
- return N.current = k.create(i).then((e) => (j.current.item = e, M() && (tt(e), x.onCreated?.(e)), e)).finally(() => {
171
- N.current = null, M() && rt(!1);
175
+ return N.current = k.create(i).then((e) => (j.current.item = e, M() && (it(e), x.onCreated?.(e)), e)).finally(() => {
176
+ N.current = null, M() && ot(!1);
172
177
  }), N.current;
173
178
  }, q = p(() => A && z ? {
174
179
  kind: x.kind,
@@ -178,16 +183,16 @@ function x(x) {
178
183
  x.kind,
179
184
  A,
180
185
  z
181
- ]), J = he("content.save", x.onError), Y = he("offer.save", x.onError), X = he("content.save", x.onError), Z = ae(q, {
186
+ ]), J = ge("content.save", x.onError), Y = ge("offer.save", x.onError), X = ge("content.save", x.onError), Z = ae(q, {
182
187
  commit: z?.live ? "manual" : "auto",
183
188
  client: S,
184
189
  onError: x.onError
185
- }), kt = m(Z);
186
- kt.current = Z;
187
- let At = Z.read.read?.files ?? [], jt = Ae(A?.id, z?.id, { client: S }).reload, Mt = q && Z.read.read ? JSON.stringify([
190
+ }), Mt = m(Z);
191
+ Mt.current = Z;
192
+ let Nt = Z.read.read?.files ?? [], Pt = Ae(A?.id, z?.id, { client: S }).reload, Ft = q && Z.read.read ? JSON.stringify([
188
193
  q.id,
189
194
  q.version,
190
- At.filter((e) => e.upload).map((e) => [
195
+ Nt.filter((e) => e.upload).map((e) => [
191
196
  e.path,
192
197
  e.size,
193
198
  e.staged,
@@ -196,66 +201,66 @@ function x(x) {
196
201
  ])
197
202
  ]) : null;
198
203
  f(() => {
199
- Mt && jt();
200
- }, [Mt, jt]);
204
+ Ft && Pt();
205
+ }, [Ft, Pt]);
201
206
  let Q = Z.groups.filter((e) => e.rule?.page).flatMap((e) => e.files.filter((e) => !a(e)));
202
207
  f(() => {
203
- L && !Q.some((e) => e.path === L.path) && gt(null);
208
+ L && !Q.some((e) => e.path === L.path) && yt(null);
204
209
  }, [L, Q]);
205
- let Nt = Z.groups.flatMap((e) => e.rule ? [e.rule] : []), Pt = z?.cover?.image ? At.find((e) => e.upload && !n(Nt, e.path)?.page && t(e.path).split("/").at(-1) === z.cover?.image) : void 0, $ = ie(q ?? He, _t?.path, {
210
+ let It = Z.groups.flatMap((e) => e.rule ? [e.rule] : []), Lt = z?.cover?.image ? Nt.find((e) => e.upload && !n(It, e.path)?.page && t(e.path).split("/").at(-1) === z.cover?.image) : void 0, $ = ie(q ?? Ge, bt?.path, {
206
211
  client: S,
207
212
  onError: x.onError,
208
- onSaved: () => vt(null)
209
- }), Ft = (e) => vt({
213
+ onSaved: () => xt(null)
214
+ }), Rt = (e) => xt({
210
215
  path: e,
211
- aspect: n(Nt, e)?.aspect ?? ""
212
- }), It = !!Z.error || Z.queue.items.some((e) => e.status === "failed") || At.some((e) => e.failed), Lt = At.some(re), Rt = Q.length, zt = Z.busy || nt || Lt || Z.read.loading || J.pending, Bt = zt || It || !!Z.read.error || Rt === 0 || G.pending || Y.pending, Vt = (e) => {
216
+ aspect: n(It, e)?.aspect ?? ""
217
+ }), zt = !!Z.error || Z.queue.items.some((e) => e.status === "failed") || Nt.some((e) => e.failed), Bt = Nt.some(re), Vt = Q.length, Ht = Z.busy || at || Bt || Z.read.loading || J.pending, Ut = Ht || zt || !!Z.read.error || Vt === 0 || G.pending || Y.pending, Wt = (e) => {
213
218
  let t = [...e];
214
- t.length && (Z.add(t), Ot(t.find((e) => /\.zip$/i.test(e.name))?.name ?? t[0]?.name).catch(Dt));
215
- }, Ht = st.dirty.length > 0 || H.dirty.length > 0 || U.dirty.length > 0 || W.dirty.length > 0 || G.dirty, Ut = Ht || Z.pending.length > 0 || Z.queue.items.some((e) => e.status === "uploaded");
219
+ t.length && (Z.add(t), jt(t.find((e) => /\.zip$/i.test(e.name))?.name ?? t[0]?.name).catch(At));
220
+ }, Gt = ut.dirty.length > 0 || H.dirty.length > 0 || U.dirty.length > 0 || W.dirty.length > 0 || G.dirty, Kt = Gt || Z.pending.length > 0 || Z.queue.items.some((e) => e.status === "uploaded");
216
221
  f(() => {
217
- if (!Ht && !Z.busy) return;
222
+ if (!Gt && !Z.busy) return;
218
223
  let e = (e) => {
219
224
  e.preventDefault(), e.returnValue = "";
220
225
  };
221
226
  return addEventListener("beforeunload", e), () => removeEventListener("beforeunload", e);
222
- }, [Ht, Z.busy]);
223
- let Wt = async (e) => {
227
+ }, [Gt, Z.busy]);
228
+ let qt = async (e) => {
224
229
  if (P) return;
225
- I(void 0), ot("");
230
+ I(void 0), lt("");
226
231
  let t = K.current;
227
232
  if (!t.texts.get()[t.language]?.title.trim()) return I(C("contentManager.titleRequired"));
228
233
  let n = G.problem();
229
234
  if (n) return I(C("readerEditor.fixSection", { section: n }));
230
- if (!Le(t.details.get().access) || t.details.get().access.level === "tier" && !t.details.get().access.tiers?.length) return I(C("readerEditor.accessRequired"));
235
+ if (!Re(t.details.get().access) || t.details.get().access.level === "tier" && !t.details.get().access.tiers?.length) return I(C("readerEditor.accessRequired"));
231
236
  let r;
232
237
  try {
233
- r = be(E.attributes ?? {}, t.details.get().attributes);
238
+ r = xe(E.attributes ?? {}, t.details.get().attributes);
234
239
  } catch (e) {
235
- return Dt(e);
240
+ return At(e);
236
241
  }
237
- if (e && Bt) return I(C("readerEditor.filesNotReady"));
238
- it(!0);
239
- let i = t.texts.checkpoint(), ee = t.details.checkpoint(), te = t.associations.checkpoint(), ne = t.texts.dirty.slice(), re = { ...t.texts.get() }, a = t.details.get(), o = t.associations.get().memberships.slice(), s = t.associations.get().create.slice(), ie = (e) => !!Ct(e.kind, o, s), ae = !0;
242
+ if (e && Ut) return I(C("readerEditor.filesNotReady"));
243
+ st(!0);
244
+ let i = t.texts.checkpoint(), ee = t.details.checkpoint(), te = t.associations.checkpoint(), ne = t.texts.dirty.slice(), re = { ...t.texts.get() }, a = t.details.get(), o = t.associations.get().memberships.slice(), s = t.associations.get().create.slice(), ie = (e) => !!Et(e.kind, o, s), ae = !0;
240
245
  try {
241
- let n = await Ot();
246
+ let n = await jt();
242
247
  if (!M()) return;
243
248
  if (B.error) throw B.error;
244
- if (await qe(async () => {
249
+ if (await Xe(async () => {
245
250
  for (let e of ne) {
246
251
  let t = String(e), r = re[t];
247
252
  if (!r?.title.trim()) throw new y(C("contentManager.titleRequired"));
248
- if (n = await S.contents.putText(n.id, t, We(r)), !M()) return;
253
+ if (n = await S.contents.putText(n.id, t, qe(r)), !M()) return;
249
254
  }
250
255
  if (n = await S.contents.get(n.id, O), M() && (n = await S.contents.update(n.id, {
251
256
  listing: a.listing,
252
257
  comments: a.comments,
253
258
  attributes: r,
254
- access: Ie(a.access),
259
+ access: Le(a.access),
255
260
  revision: n.revision
256
261
  }), M() && t.associations.dirty.length)) {
257
262
  let e = n.versions.find((e) => e.id === z?.id) ?? n.versions[0], t = o.map((t) => {
258
- let n = St.get(t.group_id ?? "")?.kind;
263
+ let n = Tt.get(t.group_id ?? "")?.kind;
259
264
  return n && T.entity_kinds[n]?.version_level && !t.version_id ? {
260
265
  ...t,
261
266
  version_id: e?.id
@@ -265,13 +270,13 @@ function x(x) {
265
270
  memberships: t,
266
271
  create: s.filter((e) => !ie(e))
267
272
  }, O);
268
- xt((e) => new Map([...e, ...r.entities.map((e) => [e.id, e])])), ae = te({
273
+ wt((e) => new Map([...e, ...r.entities.map((e) => [e.id, e])])), ae = te({
269
274
  memberships: r.memberships.filter((e) => V.includes(r.entities.find((t) => t.id === e.group_id)?.kind ?? "")),
270
275
  create: s.filter(ie)
271
276
  });
272
277
  }
273
278
  }), !M()) return;
274
- let c = kt.current;
279
+ let c = Mt.current;
275
280
  !c.busy && (c.pending.length || c.queue.items.some((e) => e.status === "uploaded")) && await c.commit();
276
281
  let oe = await G.save(M);
277
282
  if (oe) throw new y(C("readerEditor.fixSection", { section: oe }));
@@ -284,20 +289,20 @@ function x(x) {
284
289
  });
285
290
  if (e) {
286
291
  if (!se || !ce || !ae) throw new y(C("readerEditor.changedDuringSave"));
287
- let e = kt.current;
292
+ let e = Mt.current;
288
293
  if (!q || e.busy || e.error || e.queue.items.some((e) => e.status === "failed") || !await we(S, q)) throw new y(C("readerEditor.filesNotReady"));
289
294
  if ((z ? await S.contents.version(n.id, z.id, O) : null)?.state !== "published") throw new y(C("readerEditor.versionDraft"));
290
295
  if (!M()) return;
291
- let t = st.checkpoint(), r = await qe(() => S.contents.publishWhenReady(n.id, ct ? new Date(ct).toISOString() : void 0));
292
- t({ at: r.publish_at ? ye(new Date(r.publish_at)) : "" }), ot(C("contentManager.publishedNotice"));
293
- } else ot(C("pollEditor.saved"));
296
+ let t = ut.checkpoint(), r = await Xe(() => S.contents.publishWhenReady(n.id, dt ? new Date(dt).toISOString() : void 0));
297
+ t({ at: r.publish_at ? be(new Date(r.publish_at)) : "" }), lt(C("contentManager.publishedNotice"));
298
+ } else lt(C("pollEditor.saved"));
294
299
  } catch (e) {
295
- Dt(e);
300
+ At(e);
296
301
  } finally {
297
- M() && it(!1);
302
+ M() && st(!1);
298
303
  }
299
- }, Gt = async (e) => {
300
- let t = await Ot(e.name), n = t.versions.find((e) => e.id === z?.id) ?? t.versions[0];
304
+ }, Jt = async (e) => {
305
+ let t = await jt(e.name), n = t.versions.find((e) => e.id === z?.id) ?? t.versions[0];
301
306
  if (!n || !M()) return;
302
307
  let r = {
303
308
  kind: x.kind,
@@ -305,7 +310,7 @@ function x(x) {
305
310
  version: n.id
306
311
  }, i = await S.media.uploadNamed(r, e, { path: await S.media.presetPath(x.kind, "cover", e) });
307
312
  M() && await S.contents.setCover(t.id, n.id, i.name);
308
- }, Kt = async (e) => {
313
+ }, Yt = async (e) => {
309
314
  if (!q || !A || !z) return;
310
315
  let n = /\.[^./]+$/.exec(e.path)?.[0] ?? "", r = await S.media.presetPath(x.kind, "cover", new File([], `i-${crypto.randomUUID()}${n}`, { type: e.type }));
311
316
  await S.media.commit(q, [{
@@ -316,9 +321,9 @@ function x(x) {
316
321
  path: e.path
317
322
  },
318
323
  to: r
319
- }]), M() && (await S.contents.setCover(A.id, z.id, t(r).split("/").at(-1)), M() && Ft(r));
320
- }, { confirm: qt, dialog: Jt } = ve(), Yt = async () => {
321
- A && await qt({
324
+ }]), M() && (await S.contents.setCover(A.id, z.id, t(r).split("/").at(-1)), M() && Rt(r));
325
+ }, { confirm: Xt, dialog: Zt } = ye(), Qt = async () => {
326
+ A && await Xt({
322
327
  title: C("contentManager.deleteTitle", { title: A.title }),
323
328
  description: C("contentManager.deleteBody"),
324
329
  confirm: C("contentManager.delete")
@@ -326,17 +331,17 @@ function x(x) {
326
331
  Z.discard(), await S.contents.remove(A.id), M() && x.onDeleted?.(A);
327
332
  });
328
333
  };
329
- if (x.id && !A) return k.error ? /* @__PURE__ */ g(ge, {
334
+ if (x.id && !A) return k.error ? /* @__PURE__ */ g(_e, {
330
335
  error: k.error,
331
336
  message: C("contentManager.loadFailed"),
332
337
  retry: k.reload
333
- }) : /* @__PURE__ */ g(_e, {});
334
- let Xt = A ? Be(A) : "draft", Zt = z?.id, Qt = (e) => U.edit((t) => ({
338
+ }) : /* @__PURE__ */ g(ve, {});
339
+ let $t = A ? He(A) : "draft", en = z?.id, tn = (e) => U.edit((t) => ({
335
340
  ...t,
336
341
  ...e
337
- })), $t = R.map((e) => ({
342
+ })), nn = R.map((e) => ({
338
343
  id: e.id,
339
- label: Re(e, (e) => D.find((t) => t.value === e)?.label ?? e, x.labels)
344
+ label: Be(e, (e) => D.find((t) => t.value === e)?.label ?? e, x.labels)
340
345
  }));
341
346
  return /* @__PURE__ */ g(Ce.Provider, {
342
347
  value: G.context,
@@ -351,10 +356,10 @@ function x(x) {
351
356
  type: "button",
352
357
  className: "h-20 shrink-0 overflow-hidden rounded-md border border-border bg-muted disabled:cursor-default",
353
358
  style: { aspectRatio: .7071 },
354
- disabled: !Pt || P,
359
+ disabled: !Lt || P,
355
360
  title: C("readerEditor.thumbnail"),
356
361
  "aria-label": C("readerEditor.editThumbnail"),
357
- onClick: () => Pt && Ft(Pt.path),
362
+ onClick: () => Lt && Rt(Lt.path),
358
363
  "data-ckui": "editor-thumbnail",
359
364
  children: z?.cover?.url && /* @__PURE__ */ g("img", {
360
365
  src: z.cover.url,
@@ -366,16 +371,16 @@ function x(x) {
366
371
  className: "min-w-0 flex-1",
367
372
  children: [/* @__PURE__ */ g("h1", {
368
373
  className: "sr-only",
369
- children: Tt.title || C("readerEditor.new")
374
+ children: Ot.title || C("readerEditor.new")
370
375
  }), /* @__PURE__ */ _("div", {
371
376
  className: "flex items-center gap-2 text-sm text-muted-foreground",
372
377
  children: [
373
378
  /* @__PURE__ */ g(se, {
374
379
  variant: A?.live ? "default" : "outline",
375
- children: C(`contentManager.${Xt}`)
380
+ children: C(`contentManager.${$t}`)
376
381
  }),
377
- z && /* @__PURE__ */ g("span", { children: C("contentEditor.pageCount", { count: Z.read.read ? Rt : z.pages ?? 0 }) }),
378
- nt && /* @__PURE__ */ g("span", {
382
+ z && /* @__PURE__ */ g("span", { children: C("contentEditor.pageCount", { count: Z.read.read ? Vt : z.pages ?? 0 }) }),
383
+ at && /* @__PURE__ */ g("span", {
379
384
  role: "status",
380
385
  children: C("common.saving")
381
386
  })
@@ -391,29 +396,29 @@ function x(x) {
391
396
  },
392
397
  children: C(A.live ? "contentManager.view" : "readerEditor.preview")
393
398
  }),
394
- A && !Ut && !P ? /* @__PURE__ */ g("span", {
399
+ A && !Kt && !P ? /* @__PURE__ */ g("span", {
395
400
  role: "status",
396
401
  className: "text-sm text-muted-foreground",
397
402
  "data-ckui": "editor-saved",
398
403
  children: C("readerEditor.allSaved")
399
404
  }) : /* @__PURE__ */ g(o, {
400
- disabled: P || nt || !Ut,
401
- onClick: () => void Wt(!1),
405
+ disabled: P || at || !Kt,
406
+ onClick: () => void qt(!1),
402
407
  children: C(P ? "common.saving" : A?.live ? "readerEditor.saveChanges" : "readerEditor.saveDraft")
403
408
  }),
404
409
  !A?.live && /* @__PURE__ */ g(o, {
405
410
  variant: "outline",
406
- disabled: P || Bt,
407
- onClick: () => void Wt(!0),
408
- children: C(ct ? "readerEditor.schedule" : "contentManager.publish")
411
+ disabled: P || Ut,
412
+ onClick: () => void qt(!0),
413
+ children: C(dt ? "readerEditor.schedule" : "contentManager.publish")
409
414
  })
410
415
  ]
411
416
  }),
412
- F != null && /* @__PURE__ */ g(d, { children: typeof F == "string" ? F : me(Ke, e(F)) }),
413
- at && /* @__PURE__ */ g("p", {
417
+ F != null && /* @__PURE__ */ g(u, { children: typeof F == "string" ? F : he(Ye, e(F)) }),
418
+ ct && /* @__PURE__ */ g("p", {
414
419
  role: "status",
415
420
  className: "text-sm text-muted-foreground",
416
- children: at
421
+ children: ct
417
422
  }),
418
423
  /* @__PURE__ */ _("fieldset", {
419
424
  disabled: P,
@@ -435,21 +440,21 @@ function x(x) {
435
440
  id: `${w}-title`,
436
441
  required: !0,
437
442
  maxLength: 300,
438
- value: Tt.title,
439
- onChange: (e) => Et({ title: e.target.value })
443
+ value: Ot.title,
444
+ onChange: (e) => kt({ title: e.target.value })
440
445
  })]
441
446
  }), /* @__PURE__ */ _("div", {
442
447
  className: "grid gap-1.5",
443
448
  children: [/* @__PURE__ */ g(l, {
444
449
  htmlFor: `${w}-language`,
445
450
  children: C("contentManager.language")
446
- }), /* @__PURE__ */ _(u, {
451
+ }), /* @__PURE__ */ _(le, {
447
452
  value: O,
448
- onValueChange: (e) => e && Ze(e),
449
- children: [/* @__PURE__ */ g(de, {
453
+ onValueChange: (e) => e && et(e),
454
+ children: [/* @__PURE__ */ g(fe, {
450
455
  id: `${w}-language`,
451
- children: /* @__PURE__ */ g(fe, { children: D.find((e) => e.value === O)?.label ?? O })
452
- }), /* @__PURE__ */ g(le, { children: D.map((e) => /* @__PURE__ */ g(ue, {
456
+ children: /* @__PURE__ */ g(pe, { children: D.find((e) => e.value === O)?.label ?? O })
457
+ }), /* @__PURE__ */ g(ue, { children: D.map((e) => /* @__PURE__ */ g(de, {
453
458
  value: e.value,
454
459
  children: e.label
455
460
  }, e.value)) })]
@@ -461,17 +466,17 @@ function x(x) {
461
466
  children: [/* @__PURE__ */ g(l, {
462
467
  htmlFor: `${w}-description`,
463
468
  children: C("readerEditor.headerText")
464
- }), /* @__PURE__ */ g(pe, {
469
+ }), /* @__PURE__ */ g(me, {
465
470
  id: `${w}-description`,
466
471
  rows: 3,
467
- value: Tt.description ?? "",
468
- onChange: (e) => Et({ description: e.target.value })
472
+ value: Ot.description ?? "",
473
+ onChange: (e) => kt({ description: e.target.value })
469
474
  })]
470
475
  }),
471
476
  /* @__PURE__ */ g(De, {
472
477
  declared: E.attributes ?? {},
473
478
  form: U.value.attributes,
474
- onChange: (e, t) => Qt({ attributes: {
479
+ onChange: (e, t) => tn({ attributes: {
475
480
  ...U.value.attributes,
476
481
  [e]: t
477
482
  } }),
@@ -482,14 +487,14 @@ function x(x) {
482
487
  /* @__PURE__ */ _(b, {
483
488
  title: C("readerEditor.files"),
484
489
  children: [
485
- R.length > 1 && /* @__PURE__ */ _(u, {
486
- value: Zt ?? "",
487
- onValueChange: (e) => e && $e(e),
490
+ R.length > 1 && /* @__PURE__ */ _(le, {
491
+ value: en ?? "",
492
+ onValueChange: (e) => e && nt(e),
488
493
  disabled: Z.busy || Z.pending.length > 0,
489
- children: [/* @__PURE__ */ g(de, {
494
+ children: [/* @__PURE__ */ g(fe, {
490
495
  "aria-label": C("contentEditor.versions"),
491
- children: /* @__PURE__ */ g(fe, { children: $t.find((e) => e.id === Zt)?.label })
492
- }), /* @__PURE__ */ g(le, { children: $t.map((e) => /* @__PURE__ */ g(ue, {
496
+ children: /* @__PURE__ */ g(pe, { children: nn.find((e) => e.id === en)?.label })
497
+ }), /* @__PURE__ */ g(ue, { children: nn.map((e) => /* @__PURE__ */ g(de, {
493
498
  value: e.id,
494
499
  children: e.label
495
500
  }, e.id)) })]
@@ -508,31 +513,31 @@ function x(x) {
508
513
  size: "sm",
509
514
  variant: "secondary",
510
515
  disabled: J.pending || P,
511
- onClick: () => void J.run(() => Kt(L)),
516
+ onClick: () => void J.run(() => Yt(L)),
512
517
  children: C("readerEditor.setThumbnail")
513
518
  })]
514
519
  }),
515
520
  /* @__PURE__ */ g(c, {
516
521
  folder: {
517
522
  ...Z,
518
- add: Vt
523
+ add: Wt
519
524
  },
520
525
  label: !1,
521
526
  layout: "grid",
522
527
  disabled: P,
523
528
  inputLabel: C("readerEditor.files"),
524
529
  selectedPage: L?.path ?? null,
525
- onSelectPage: gt
530
+ onSelectPage: yt
526
531
  }),
527
- Z.read.error && /* @__PURE__ */ g(ge, {
532
+ Z.read.error && /* @__PURE__ */ g(_e, {
528
533
  error: Z.read.error,
529
534
  message: C("contentManager.loadFailed"),
530
535
  retry: Z.read.reload
531
536
  }),
532
- (It || zt || !Z.read.error && Rt === 0) && /* @__PURE__ */ g("p", {
537
+ (zt || Ht || !Z.read.error && Vt === 0) && /* @__PURE__ */ g("p", {
533
538
  role: "status",
534
539
  className: "text-sm text-muted-foreground",
535
- children: C(It ? "readerEditor.filesFailed" : zt ? "readerEditor.processing" : "readerEditor.addPages")
540
+ children: C(zt ? "readerEditor.filesFailed" : Ht ? "readerEditor.processing" : "readerEditor.addPages")
536
541
  }),
537
542
  A && z && /* @__PURE__ */ g(Ne, {
538
543
  content: A.id,
@@ -544,14 +549,14 @@ function x(x) {
544
549
  }),
545
550
  A && /* @__PURE__ */ _("details", {
546
551
  className: "rounded-xl border border-border bg-card p-4",
547
- onToggle: (e) => e.currentTarget.open && dt(!0),
552
+ onToggle: (e) => e.currentTarget.open && mt(!0),
548
553
  children: [/* @__PURE__ */ g("summary", {
549
554
  className: "cursor-pointer font-medium",
550
555
  children: C("readerEditor.versions")
551
- }), ut && /* @__PURE__ */ g(Fe, {
556
+ }), pt && /* @__PURE__ */ g(Fe, {
552
557
  content: A,
553
558
  media: !1,
554
- activeVersion: Zt,
559
+ activeVersion: en,
555
560
  client: S,
556
561
  labels: x.labels,
557
562
  onError: x.onError
@@ -559,11 +564,11 @@ function x(x) {
559
564
  }),
560
565
  A && z && /* @__PURE__ */ _("details", {
561
566
  className: "rounded-xl border border-border bg-card p-4",
562
- onToggle: (e) => ht(e.currentTarget.open),
567
+ onToggle: (e) => vt(e.currentTarget.open),
563
568
  children: [/* @__PURE__ */ g("summary", {
564
569
  className: "cursor-pointer font-medium",
565
570
  children: C("readerEditor.readerTools")
566
- }), ft.filter((e) => R.some((t) => t.id === e)).map((e) => /* @__PURE__ */ g("div", {
571
+ }), ht.filter((e) => R.some((t) => t.id === e)).map((e) => /* @__PURE__ */ g("div", {
567
572
  hidden: e !== z.id,
568
573
  children: /* @__PURE__ */ g(Me, {
569
574
  content: A.id,
@@ -579,26 +584,26 @@ function x(x) {
579
584
  children: [
580
585
  /* @__PURE__ */ _(b, {
581
586
  title: C("readerEditor.entities"),
582
- children: [B.error && /* @__PURE__ */ g(d, { error: B.error }), V.map((e) => {
587
+ children: [B.error && /* @__PURE__ */ g(u, { error: B.error }), V.map((e) => {
583
588
  let t = W.value.memberships.map((e, t) => ({
584
589
  a: e,
585
590
  index: t
586
- })).filter(({ a: t }) => St.get(t.group_id ?? "")?.kind === e);
591
+ })).filter(({ a: t }) => Tt.get(t.group_id ?? "")?.kind === e);
587
592
  return /* @__PURE__ */ g(je, {
588
593
  kind: e,
589
- label: xe(x.labels, e),
594
+ label: Se(x.labels, e),
590
595
  memberships: t.map(({ a: e }) => e),
591
- cards: St,
596
+ cards: Tt,
592
597
  spec: T.entity_kinds[e] ?? {},
593
598
  labels: x.labels,
594
- versions: $t,
595
- versionLabel: (e) => $t.find((t) => t.id === e)?.label ?? e,
599
+ versions: nn,
600
+ versionLabel: (e) => nn.find((t) => t.id === e)?.label ?? e,
596
601
  language: O,
597
602
  management: x.management,
598
603
  client: S,
599
604
  disabled: !!A && B.loading,
600
605
  created: W.value.create.filter((t) => t.kind === e).map((e) => e.name),
601
- needsScope: Ct(e, W.value.memberships, W.value.create),
606
+ needsScope: Et(e, W.value.memberships, W.value.create),
602
607
  onCreatedChange: (t) => W.edit((n) => ({
603
608
  ...n,
604
609
  create: [...n.create.filter((t) => t.kind !== e), ...t.map((t) => ({
@@ -619,7 +624,7 @@ function x(x) {
619
624
  memberships: n.memberships.filter((n, r) => r !== t[e].index)
620
625
  })),
621
626
  onAdd: (t) => {
622
- xt((e) => new Map(e).set(t.id, t)), W.edit((n) => ({
627
+ wt((e) => new Map(e).set(t.id, t)), W.edit((n) => ({
623
628
  ...n,
624
629
  memberships: [...n.memberships, {
625
630
  group_id: t.id,
@@ -647,32 +652,32 @@ function x(x) {
647
652
  disabled: J.pending || P,
648
653
  onChange: (e) => {
649
654
  let t = e.target.files?.[0];
650
- e.target.value = "", t && J.run(() => Gt(t));
655
+ e.target.value = "", t && J.run(() => Jt(t));
651
656
  }
652
657
  })]
653
658
  }),
654
- /* @__PURE__ */ g(d, { error: J.error })
659
+ /* @__PURE__ */ g(u, { error: J.error })
655
660
  ]
656
661
  }),
657
662
  /* @__PURE__ */ _(b, {
658
- title: C("contentEditor.accessTitle"),
663
+ title: C(Ie(T, x.kind) ? "contentEditor.accessTitle" : "contentEditor.accessOnlyTitle"),
659
664
  children: [
660
665
  /* @__PURE__ */ g(Pe, {
661
666
  value: U.value.access,
662
- onChange: (e) => Qt({ access: e }),
667
+ onChange: (e) => tn({ access: e }),
663
668
  model: T,
664
669
  kind: x.kind,
665
670
  owner: A?.owner_group_id ?? x.ownerGroup,
666
671
  labels: x.labels,
667
672
  client: S
668
673
  }),
669
- A && (U.value.access.level === "ppv" || U.value.access.level === "group_ppv" || A.offer) && /* @__PURE__ */ g(Ee, {
674
+ A && Ie(T, x.kind) && (U.value.access.level === "ppv" || U.value.access.level === "group_ppv" || A.offer) && /* @__PURE__ */ g(Ee, {
670
675
  offer: A.offer,
671
676
  pending: Y.pending,
672
677
  onSell: (e) => Y.run(() => S.offers.sell({ content: A.id }, e)),
673
678
  onWithdraw: () => void Y.run(() => S.offers.withdraw({ content: A.id }))
674
679
  }),
675
- /* @__PURE__ */ g(d, { error: Y.error })
680
+ /* @__PURE__ */ g(u, { error: Y.error })
676
681
  ]
677
682
  }),
678
683
  /* @__PURE__ */ _(b, {
@@ -686,48 +691,47 @@ function x(x) {
686
691
  }), /* @__PURE__ */ g(ce, {
687
692
  id: `${w}-publish`,
688
693
  type: "datetime-local",
689
- value: ct,
690
- onChange: (e) => lt(e.target.value)
694
+ value: dt,
695
+ onChange: (e) => ft(e.target.value)
691
696
  })]
692
697
  }),
693
698
  /* @__PURE__ */ g(l, {
694
699
  htmlFor: `${w}-listing`,
695
700
  children: C("contentEditor.listing")
696
701
  }),
697
- /* @__PURE__ */ _(u, {
702
+ /* @__PURE__ */ _(le, {
698
703
  value: U.value.listing,
699
- onValueChange: (e) => e && Qt({ listing: e }),
700
- children: [/* @__PURE__ */ g(de, {
704
+ onValueChange: (e) => e && tn({ listing: e }),
705
+ children: [/* @__PURE__ */ g(fe, {
701
706
  id: `${w}-listing`,
702
- children: /* @__PURE__ */ g(fe, { children: C(`contentEditor.listing_${U.value.listing}`) })
703
- }), /* @__PURE__ */ g(le, { children: [
707
+ children: /* @__PURE__ */ g(pe, { children: C(`contentEditor.listing_${U.value.listing}`) })
708
+ }), /* @__PURE__ */ g(ue, { children: [
704
709
  "listed",
705
710
  "members",
706
711
  "unlisted"
707
- ].map((e) => /* @__PURE__ */ g(ue, {
712
+ ].map((e) => /* @__PURE__ */ g(de, {
708
713
  value: e,
709
714
  children: C(`contentEditor.listing_${e}`)
710
715
  }, e)) })]
711
716
  }),
712
- /* @__PURE__ */ g(l, {
717
+ E.comment_modes?.length !== 1 && /* @__PURE__ */ _(We, { children: [/* @__PURE__ */ g(l, {
713
718
  htmlFor: `${w}-comments`,
714
719
  children: C("contentEditor.comments")
715
- }),
716
- /* @__PURE__ */ _(u, {
720
+ }), /* @__PURE__ */ _(le, {
717
721
  value: U.value.comments,
718
- onValueChange: (e) => e && Qt({ comments: e }),
719
- children: [/* @__PURE__ */ g(de, {
722
+ onValueChange: (e) => e && tn({ comments: e }),
723
+ children: [/* @__PURE__ */ g(fe, {
720
724
  id: `${w}-comments`,
721
- children: /* @__PURE__ */ g(fe, { children: C(`contentEditor.comments_${U.value.comments}`) })
722
- }), /* @__PURE__ */ g(le, { children: [
725
+ children: /* @__PURE__ */ g(pe, { children: C(`contentEditor.comments_${U.value.comments}`) })
726
+ }), /* @__PURE__ */ g(ue, { children: [
723
727
  "open",
724
728
  "closed",
725
729
  "hidden"
726
- ].map((e) => /* @__PURE__ */ g(ue, {
730
+ ].filter((e) => !E.comment_modes?.length || E.comment_modes.includes(e)).map((e) => /* @__PURE__ */ g(de, {
727
731
  value: e,
728
732
  children: C(`contentEditor.comments_${e}`)
729
733
  }, e)) })]
730
- }),
734
+ })] }),
731
735
  A?.state === "published" && /* @__PURE__ */ g(o, {
732
736
  variant: "outline",
733
737
  disabled: X.pending,
@@ -737,27 +741,27 @@ function x(x) {
737
741
  A && /* @__PURE__ */ g(o, {
738
742
  variant: "destructive",
739
743
  disabled: X.pending,
740
- onClick: () => void Yt(),
744
+ onClick: () => void Qt(),
741
745
  children: C("contentManager.delete")
742
746
  }),
743
- /* @__PURE__ */ g(d, { error: X.error })
747
+ /* @__PURE__ */ g(u, { error: X.error })
744
748
  ]
745
749
  })
746
750
  ]
747
751
  })]
748
752
  }),
749
- Jt,
753
+ Zt,
750
754
  /* @__PURE__ */ g(s, {
751
- open: !!_t,
752
- onOpenChange: (e) => !e && $.status !== "saving" && vt(null),
755
+ open: !!bt,
756
+ onOpenChange: (e) => !e && $.status !== "saving" && xt(null),
753
757
  source: "source" in $ ? $.source ?? null : null,
754
- aspect: _t?.aspect ?? "",
758
+ aspect: bt?.aspect ?? "",
755
759
  rotatable: !1,
756
760
  initialEdit: "edit" in $ ? $.edit : null,
757
761
  title: C("readerEditor.thumbnail"),
758
762
  confirmLabel: C("readerEditor.setThumbnail"),
759
763
  busy: $.status === "saving",
760
- error: $.status === "error" ? me(Ke, $.error) : void 0,
764
+ error: $.status === "error" ? he(Ye, $.error) : void 0,
761
765
  onConfirm: (e) => void $.save(e)
762
766
  })
763
767
  ]