@adatechnology/content-ui 0.0.0-stage → 0.1.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 +112 -2
- package/dist/index.d.ts +600 -0
- package/dist/index.js +1497 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +607 -0
- package/dist/styles.css.map +1 -0
- package/package.json +44 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,1497 @@
|
|
|
1
|
+
// src/providers/ContentProvider.tsx
|
|
2
|
+
import { createContext, useContext, useMemo } from "react";
|
|
3
|
+
|
|
4
|
+
// src/locales/en.json
|
|
5
|
+
var en_default = {
|
|
6
|
+
statusDraft: "Draft",
|
|
7
|
+
statusScheduled: "Scheduled",
|
|
8
|
+
statusPublished: "Published",
|
|
9
|
+
statusArchived: "Archived",
|
|
10
|
+
listTitle: "Posts",
|
|
11
|
+
newPost: "New post",
|
|
12
|
+
searchLabel: "Search",
|
|
13
|
+
searchPlaceholder: "Title or address",
|
|
14
|
+
filterStatus: "Status",
|
|
15
|
+
filterAll: "All",
|
|
16
|
+
filterTag: "Tag",
|
|
17
|
+
loading: "Loading\u2026",
|
|
18
|
+
empty: "No posts found.",
|
|
19
|
+
loadError: "Could not load.",
|
|
20
|
+
retry: "Try again",
|
|
21
|
+
columnTitle: "Title",
|
|
22
|
+
columnStatus: "Status",
|
|
23
|
+
columnUpdated: "Updated",
|
|
24
|
+
columnPublished: "Publication",
|
|
25
|
+
paginationLabel: "Pagination",
|
|
26
|
+
paginationPrevious: "Previous",
|
|
27
|
+
paginationNext: "Next",
|
|
28
|
+
pageLabel: "Page {page}",
|
|
29
|
+
editorNewTitle: "New post",
|
|
30
|
+
editorEditTitle: "Edit post",
|
|
31
|
+
fieldTitle: "Title",
|
|
32
|
+
fieldSlug: "Address (slug)",
|
|
33
|
+
fieldSlugHint: "Shown in the URL. Changing it after publishing breaks links already shared.",
|
|
34
|
+
fieldExcerpt: "Excerpt",
|
|
35
|
+
fieldBody: "Content",
|
|
36
|
+
bodyHint: "Markdown: # heading, **bold**, *italic*, - list, [link](https://\u2026), ",
|
|
37
|
+
tabWrite: "Write",
|
|
38
|
+
tabPreview: "Preview",
|
|
39
|
+
previewEmpty: "Nothing to preview.",
|
|
40
|
+
fieldCover: "Cover image",
|
|
41
|
+
fieldCoverUrl: "Image URL",
|
|
42
|
+
fieldCoverAlt: "Image description (alt text)",
|
|
43
|
+
coverUpload: "Upload image",
|
|
44
|
+
coverRemove: "Remove cover",
|
|
45
|
+
coverTooLarge: "The image is larger than 1 MB.",
|
|
46
|
+
coverInvalidType: "Use JPG, PNG or WebP.",
|
|
47
|
+
coverUploading: "Uploading\u2026",
|
|
48
|
+
coverUploadError: "Could not upload the image.",
|
|
49
|
+
fieldTags: "Tags",
|
|
50
|
+
tagsHint: "Enter or comma to add",
|
|
51
|
+
tagRemove: "Remove tag {tag}",
|
|
52
|
+
fieldAuthor: "Author",
|
|
53
|
+
seoSection: "SEO",
|
|
54
|
+
fieldSeoTitle: "Search engine title",
|
|
55
|
+
fieldSeoDescription: "Search engine description",
|
|
56
|
+
fieldCanonical: "Canonical URL",
|
|
57
|
+
publishSection: "Publishing",
|
|
58
|
+
scheduleAt: "Schedule for",
|
|
59
|
+
save: "Save draft",
|
|
60
|
+
saveChanges: "Save",
|
|
61
|
+
saving: "Saving\u2026",
|
|
62
|
+
saved: "Saved.",
|
|
63
|
+
publishNow: "Publish now",
|
|
64
|
+
schedule: "Schedule",
|
|
65
|
+
unpublish: "Unpublish",
|
|
66
|
+
archive: "Archive",
|
|
67
|
+
archiveConfirm: "Archive this post? It will leave the site.",
|
|
68
|
+
close: "Back",
|
|
69
|
+
unsavedConfirm: "You have unsaved changes. Leave anyway?",
|
|
70
|
+
unsavedBadge: "Unsaved changes",
|
|
71
|
+
saveError: "Could not save.",
|
|
72
|
+
errorTitle: "Enter a title.",
|
|
73
|
+
errorSlug: "Use lowercase letters, numbers and hyphens.",
|
|
74
|
+
errorUrl: "Use a full http(s) address.",
|
|
75
|
+
errorSchedule: "Pick a date and time.",
|
|
76
|
+
scheduledFor: "Scheduled for {date}",
|
|
77
|
+
publishedOn: "Published on {date}",
|
|
78
|
+
readingTime: "{minutes} min read",
|
|
79
|
+
readMore: "Read more",
|
|
80
|
+
byAuthor: "By {author}",
|
|
81
|
+
allTags: "All",
|
|
82
|
+
tagsLabel: "Filter by tag",
|
|
83
|
+
shareLabel: "Share",
|
|
84
|
+
shareWhatsApp: "WhatsApp",
|
|
85
|
+
shareFacebook: "Facebook",
|
|
86
|
+
shareX: "X",
|
|
87
|
+
shareLinkedIn: "LinkedIn",
|
|
88
|
+
copyLink: "Copy link",
|
|
89
|
+
linkCopied: "Link copied",
|
|
90
|
+
shareNative: "Share\u2026",
|
|
91
|
+
shareOn: "Share on {network}",
|
|
92
|
+
notFound: "Post not found.",
|
|
93
|
+
postsEmpty: "No posts published yet.",
|
|
94
|
+
clearFilters: "Clear filters"
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// src/locales/pt-BR.json
|
|
98
|
+
var pt_BR_default = {
|
|
99
|
+
statusDraft: "Rascunho",
|
|
100
|
+
statusScheduled: "Agendado",
|
|
101
|
+
statusPublished: "Publicado",
|
|
102
|
+
statusArchived: "Arquivado",
|
|
103
|
+
listTitle: "Posts",
|
|
104
|
+
newPost: "Novo post",
|
|
105
|
+
searchLabel: "Buscar",
|
|
106
|
+
searchPlaceholder: "T\xEDtulo ou endere\xE7o",
|
|
107
|
+
filterStatus: "Status",
|
|
108
|
+
filterAll: "Todos",
|
|
109
|
+
filterTag: "Tag",
|
|
110
|
+
loading: "Carregando\u2026",
|
|
111
|
+
empty: "Nenhum post encontrado.",
|
|
112
|
+
loadError: "N\xE3o foi poss\xEDvel carregar.",
|
|
113
|
+
retry: "Tentar de novo",
|
|
114
|
+
columnTitle: "T\xEDtulo",
|
|
115
|
+
columnStatus: "Status",
|
|
116
|
+
columnUpdated: "Atualizado",
|
|
117
|
+
columnPublished: "Publica\xE7\xE3o",
|
|
118
|
+
paginationLabel: "Pagina\xE7\xE3o",
|
|
119
|
+
paginationPrevious: "Anterior",
|
|
120
|
+
paginationNext: "Pr\xF3xima",
|
|
121
|
+
pageLabel: "P\xE1gina {page}",
|
|
122
|
+
editorNewTitle: "Novo post",
|
|
123
|
+
editorEditTitle: "Editar post",
|
|
124
|
+
fieldTitle: "T\xEDtulo",
|
|
125
|
+
fieldSlug: "Endere\xE7o (slug)",
|
|
126
|
+
fieldSlugHint: "Aparece na URL. Mudar depois de publicado quebra links j\xE1 compartilhados.",
|
|
127
|
+
fieldExcerpt: "Resumo",
|
|
128
|
+
fieldBody: "Conte\xFAdo",
|
|
129
|
+
bodyHint: "Markdown: # t\xEDtulo, **negrito**, *it\xE1lico*, - lista, [link](https://\u2026), ",
|
|
130
|
+
tabWrite: "Escrever",
|
|
131
|
+
tabPreview: "Pr\xE9-visualizar",
|
|
132
|
+
previewEmpty: "Nada para pr\xE9-visualizar.",
|
|
133
|
+
fieldCover: "Imagem de capa",
|
|
134
|
+
fieldCoverUrl: "URL da imagem",
|
|
135
|
+
fieldCoverAlt: "Descri\xE7\xE3o da imagem (texto alternativo)",
|
|
136
|
+
coverUpload: "Enviar imagem",
|
|
137
|
+
coverRemove: "Remover capa",
|
|
138
|
+
coverTooLarge: "A imagem passa de 1 MB.",
|
|
139
|
+
coverInvalidType: "Use JPG, PNG ou WebP.",
|
|
140
|
+
coverUploading: "Enviando\u2026",
|
|
141
|
+
coverUploadError: "N\xE3o foi poss\xEDvel enviar a imagem.",
|
|
142
|
+
fieldTags: "Tags",
|
|
143
|
+
tagsHint: "Enter ou v\xEDrgula para adicionar",
|
|
144
|
+
tagRemove: "Remover tag {tag}",
|
|
145
|
+
fieldAuthor: "Autor",
|
|
146
|
+
seoSection: "SEO",
|
|
147
|
+
fieldSeoTitle: "T\xEDtulo para buscadores",
|
|
148
|
+
fieldSeoDescription: "Descri\xE7\xE3o para buscadores",
|
|
149
|
+
fieldCanonical: "URL can\xF4nica",
|
|
150
|
+
publishSection: "Publica\xE7\xE3o",
|
|
151
|
+
scheduleAt: "Agendar para",
|
|
152
|
+
save: "Salvar rascunho",
|
|
153
|
+
saveChanges: "Salvar",
|
|
154
|
+
saving: "Salvando\u2026",
|
|
155
|
+
saved: "Salvo.",
|
|
156
|
+
publishNow: "Publicar agora",
|
|
157
|
+
schedule: "Agendar",
|
|
158
|
+
unpublish: "Despublicar",
|
|
159
|
+
archive: "Arquivar",
|
|
160
|
+
archiveConfirm: "Arquivar este post? Ele sai do site.",
|
|
161
|
+
close: "Voltar",
|
|
162
|
+
unsavedConfirm: "H\xE1 altera\xE7\xF5es n\xE3o salvas. Sair mesmo assim?",
|
|
163
|
+
unsavedBadge: "Altera\xE7\xF5es n\xE3o salvas",
|
|
164
|
+
saveError: "N\xE3o foi poss\xEDvel salvar.",
|
|
165
|
+
errorTitle: "Informe o t\xEDtulo.",
|
|
166
|
+
errorSlug: "Use letras min\xFAsculas, n\xFAmeros e h\xEDfen.",
|
|
167
|
+
errorUrl: "Use um endere\xE7o http(s) completo.",
|
|
168
|
+
errorSchedule: "Escolha uma data e hora.",
|
|
169
|
+
scheduledFor: "Agendado para {date}",
|
|
170
|
+
publishedOn: "Publicado em {date}",
|
|
171
|
+
readingTime: "{minutes} min de leitura",
|
|
172
|
+
readMore: "Ler mais",
|
|
173
|
+
byAuthor: "Por {author}",
|
|
174
|
+
allTags: "Todos",
|
|
175
|
+
tagsLabel: "Filtrar por tag",
|
|
176
|
+
shareLabel: "Compartilhar",
|
|
177
|
+
shareWhatsApp: "WhatsApp",
|
|
178
|
+
shareFacebook: "Facebook",
|
|
179
|
+
shareX: "X",
|
|
180
|
+
shareLinkedIn: "LinkedIn",
|
|
181
|
+
copyLink: "Copiar link",
|
|
182
|
+
linkCopied: "Link copiado",
|
|
183
|
+
shareNative: "Compartilhar\u2026",
|
|
184
|
+
shareOn: "Compartilhar no {network}",
|
|
185
|
+
notFound: "Post n\xE3o encontrado.",
|
|
186
|
+
postsEmpty: "Nenhum post publicado ainda.",
|
|
187
|
+
clearFilters: "Limpar filtros"
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// src/locales/index.ts
|
|
191
|
+
var DEFAULT_CONTENT_LOCALE = "pt-BR";
|
|
192
|
+
var MESSAGES_BY_LOCALE = { "pt-BR": pt_BR_default, en: en_default };
|
|
193
|
+
function resolveContentMessages(locale) {
|
|
194
|
+
return MESSAGES_BY_LOCALE[locale] ?? MESSAGES_BY_LOCALE[DEFAULT_CONTENT_LOCALE];
|
|
195
|
+
}
|
|
196
|
+
function interpolate(message, values) {
|
|
197
|
+
return message.replace(/\{(\w+)\}/g, (match, key) => key in values ? String(values[key]) : match);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/providers/ContentProvider.tsx
|
|
201
|
+
import { jsx } from "react/jsx-runtime";
|
|
202
|
+
var ContentContext = createContext(null);
|
|
203
|
+
function defaultRenderLink({ children, ...props }) {
|
|
204
|
+
return /* @__PURE__ */ jsx("a", { ...props, children });
|
|
205
|
+
}
|
|
206
|
+
function ContentProvider({
|
|
207
|
+
adminApi,
|
|
208
|
+
publicApi,
|
|
209
|
+
locale = DEFAULT_CONTENT_LOCALE,
|
|
210
|
+
messages,
|
|
211
|
+
renderLink,
|
|
212
|
+
children
|
|
213
|
+
}) {
|
|
214
|
+
const value = useMemo(
|
|
215
|
+
() => ({
|
|
216
|
+
...adminApi ? { adminApi } : {},
|
|
217
|
+
...publicApi ? { publicApi } : {},
|
|
218
|
+
locale,
|
|
219
|
+
messages: { ...resolveContentMessages(locale), ...messages },
|
|
220
|
+
renderLink: renderLink ?? defaultRenderLink
|
|
221
|
+
}),
|
|
222
|
+
[adminApi, publicApi, locale, messages, renderLink]
|
|
223
|
+
);
|
|
224
|
+
return /* @__PURE__ */ jsx(ContentContext.Provider, { value, children });
|
|
225
|
+
}
|
|
226
|
+
function useContentContext() {
|
|
227
|
+
const value = useContext(ContentContext);
|
|
228
|
+
if (!value) throw new Error("content-ui: componente usado fora de <ContentProvider>");
|
|
229
|
+
return value;
|
|
230
|
+
}
|
|
231
|
+
function useContentAdminApi() {
|
|
232
|
+
const { adminApi } = useContentContext();
|
|
233
|
+
if (!adminApi) throw new Error("content-ui: <ContentProvider adminApi> \xE9 obrigat\xF3rio no painel");
|
|
234
|
+
return adminApi;
|
|
235
|
+
}
|
|
236
|
+
function useContentPublicApi() {
|
|
237
|
+
const { publicApi } = useContentContext();
|
|
238
|
+
if (!publicApi) throw new Error("content-ui: <ContentProvider publicApi> \xE9 obrigat\xF3rio no site p\xFAblico");
|
|
239
|
+
return publicApi;
|
|
240
|
+
}
|
|
241
|
+
function useContentText() {
|
|
242
|
+
const { messages, locale } = useContentContext();
|
|
243
|
+
return useMemo(
|
|
244
|
+
() => ({ messages, locale, format: (key, values) => interpolate(messages[key], values) }),
|
|
245
|
+
[messages, locale]
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
function useRenderLink() {
|
|
249
|
+
return useContentContext().renderLink;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// src/components/ContentWorkspace.tsx
|
|
253
|
+
import { useState as useState6 } from "react";
|
|
254
|
+
|
|
255
|
+
// src/components/PostEditor.tsx
|
|
256
|
+
import { Archive as Archive2, ArrowLeft, CalendarClock as CalendarClock2, EyeOff, ImageUp, Save, Send, Trash2 } from "lucide-react";
|
|
257
|
+
import { useId as useId2, useState as useState4 } from "react";
|
|
258
|
+
|
|
259
|
+
// src/hooks/usePostEditor.ts
|
|
260
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
|
|
261
|
+
|
|
262
|
+
// src/lib/format.ts
|
|
263
|
+
function formatPostDate(iso, locale, withTime = false) {
|
|
264
|
+
if (!iso) return "";
|
|
265
|
+
const date = new Date(iso);
|
|
266
|
+
if (Number.isNaN(date.getTime())) return "";
|
|
267
|
+
return new Intl.DateTimeFormat(locale, {
|
|
268
|
+
dateStyle: "long",
|
|
269
|
+
...withTime ? { timeStyle: "short" } : {}
|
|
270
|
+
}).format(date);
|
|
271
|
+
}
|
|
272
|
+
function pad(value) {
|
|
273
|
+
return String(value).padStart(2, "0");
|
|
274
|
+
}
|
|
275
|
+
function toDateTimeLocalValue(iso) {
|
|
276
|
+
if (!iso) return "";
|
|
277
|
+
const date = new Date(iso);
|
|
278
|
+
if (Number.isNaN(date.getTime())) return "";
|
|
279
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
280
|
+
}
|
|
281
|
+
function fromDateTimeLocalValue(value) {
|
|
282
|
+
if (!value) return void 0;
|
|
283
|
+
const date = new Date(value);
|
|
284
|
+
return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// src/lib/postDraft.ts
|
|
288
|
+
import { createPostSchema, slugify } from "@adatechnology/content-contracts";
|
|
289
|
+
var EMPTY_POST_DRAFT = {
|
|
290
|
+
title: "",
|
|
291
|
+
slug: "",
|
|
292
|
+
excerpt: "",
|
|
293
|
+
body: "",
|
|
294
|
+
coverImageUrl: "",
|
|
295
|
+
coverImageAlt: "",
|
|
296
|
+
tags: [],
|
|
297
|
+
authorName: "",
|
|
298
|
+
seoTitle: "",
|
|
299
|
+
seoDescription: "",
|
|
300
|
+
canonicalUrl: ""
|
|
301
|
+
};
|
|
302
|
+
function draftFromPost(post, defaults = {}) {
|
|
303
|
+
if (!post) return { ...EMPTY_POST_DRAFT, ...defaults };
|
|
304
|
+
return {
|
|
305
|
+
title: post.title,
|
|
306
|
+
slug: post.slug,
|
|
307
|
+
excerpt: post.excerpt ?? "",
|
|
308
|
+
body: post.body,
|
|
309
|
+
coverImageUrl: post.coverImageUrl ?? "",
|
|
310
|
+
coverImageAlt: post.coverImageAlt ?? "",
|
|
311
|
+
tags: post.tags,
|
|
312
|
+
authorName: post.authorName ?? "",
|
|
313
|
+
seoTitle: post.seoTitle ?? "",
|
|
314
|
+
seoDescription: post.seoDescription ?? "",
|
|
315
|
+
canonicalUrl: post.canonicalUrl ?? ""
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
var nullable = (value) => value.trim() ? value.trim() : null;
|
|
319
|
+
function draftToInput(draft) {
|
|
320
|
+
return {
|
|
321
|
+
title: draft.title.trim(),
|
|
322
|
+
...draft.slug.trim() ? { slug: draft.slug.trim() } : {},
|
|
323
|
+
excerpt: nullable(draft.excerpt),
|
|
324
|
+
body: draft.body,
|
|
325
|
+
coverImageUrl: nullable(draft.coverImageUrl),
|
|
326
|
+
coverImageAlt: nullable(draft.coverImageAlt),
|
|
327
|
+
tags: [...draft.tags],
|
|
328
|
+
authorName: nullable(draft.authorName),
|
|
329
|
+
seoTitle: nullable(draft.seoTitle),
|
|
330
|
+
seoDescription: nullable(draft.seoDescription),
|
|
331
|
+
canonicalUrl: nullable(draft.canonicalUrl)
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
function isDraftDirty(draft, baseline) {
|
|
335
|
+
return JSON.stringify(draft) !== JSON.stringify(baseline);
|
|
336
|
+
}
|
|
337
|
+
function deriveSlug(params) {
|
|
338
|
+
return params.slugTouched ? params.slug : slugify(params.title);
|
|
339
|
+
}
|
|
340
|
+
var DRAFT_ERROR = {
|
|
341
|
+
TITLE: "title",
|
|
342
|
+
SLUG: "slug",
|
|
343
|
+
COVER_IMAGE_URL: "coverImageUrl",
|
|
344
|
+
CANONICAL_URL: "canonicalUrl"
|
|
345
|
+
};
|
|
346
|
+
function validateDraft(draft) {
|
|
347
|
+
const result = createPostSchema.safeParse(draftToInput(draft));
|
|
348
|
+
if (result.success) return {};
|
|
349
|
+
const errors = {};
|
|
350
|
+
for (const issue of result.error.issues) {
|
|
351
|
+
const field = issue.path[0];
|
|
352
|
+
if (field === "title" || field === "slug" || field === "coverImageUrl" || field === "canonicalUrl")
|
|
353
|
+
errors[field] = true;
|
|
354
|
+
}
|
|
355
|
+
return errors;
|
|
356
|
+
}
|
|
357
|
+
function splitTagInput(value) {
|
|
358
|
+
return value.split(/[,\n]/).map((tag) => tag.trim().replace(/\s+/g, " ").toLowerCase()).filter(Boolean);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// src/hooks/useAsyncResource.ts
|
|
362
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
363
|
+
function useAsyncResource(load, key) {
|
|
364
|
+
const [state, setState] = useState({ isLoading: true });
|
|
365
|
+
const [attempt, setAttempt] = useState(0);
|
|
366
|
+
const loadRef = useRef(load);
|
|
367
|
+
loadRef.current = load;
|
|
368
|
+
useEffect(() => {
|
|
369
|
+
let isCurrent = true;
|
|
370
|
+
setState((previous) => ({ ...previous, isLoading: true, error: void 0 }));
|
|
371
|
+
loadRef.current().then((data) => {
|
|
372
|
+
if (isCurrent) setState({ data, isLoading: false });
|
|
373
|
+
}).catch((error) => {
|
|
374
|
+
if (isCurrent) setState({ isLoading: false, error });
|
|
375
|
+
});
|
|
376
|
+
return () => {
|
|
377
|
+
isCurrent = false;
|
|
378
|
+
};
|
|
379
|
+
}, [key, attempt]);
|
|
380
|
+
const reload = useCallback(() => setAttempt((value) => value + 1), []);
|
|
381
|
+
return { data: state.data, isLoading: state.isLoading, error: state.error, reload };
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// src/hooks/usePostEditor.ts
|
|
385
|
+
var COVER_MAX_BYTES = 1024 * 1024;
|
|
386
|
+
var COVER_MIME_TYPES = ["image/jpeg", "image/png", "image/webp"];
|
|
387
|
+
function usePostEditor(params) {
|
|
388
|
+
const api = useContentAdminApi();
|
|
389
|
+
const [post, setPost] = useState2();
|
|
390
|
+
const [isLoading, setIsLoading] = useState2(Boolean(params.postId));
|
|
391
|
+
const [baseline, setBaseline] = useState2(() => draftFromPost(void 0, params.defaults));
|
|
392
|
+
const [draft, setDraft] = useState2(baseline);
|
|
393
|
+
const [slugTouched, setSlugTouched] = useState2(Boolean(params.postId));
|
|
394
|
+
const [scheduleAt, setScheduleAt] = useState2("");
|
|
395
|
+
const [isBusy, setIsBusy] = useState2(false);
|
|
396
|
+
const [isUploading, setIsUploading] = useState2(false);
|
|
397
|
+
const [feedback, setFeedback] = useState2();
|
|
398
|
+
const [showErrors, setShowErrors] = useState2(false);
|
|
399
|
+
const tags = useAsyncResource(
|
|
400
|
+
() => api.listTags ? api.listTags() : Promise.resolve([]),
|
|
401
|
+
"editor-tags"
|
|
402
|
+
);
|
|
403
|
+
const accept = useCallback2((saved) => {
|
|
404
|
+
const next = draftFromPost(saved);
|
|
405
|
+
setPost(saved);
|
|
406
|
+
setBaseline(next);
|
|
407
|
+
setDraft(next);
|
|
408
|
+
setSlugTouched(true);
|
|
409
|
+
setScheduleAt(saved.status === "scheduled" ? toDateTimeLocalValue(saved.publishedAt) : "");
|
|
410
|
+
}, []);
|
|
411
|
+
useEffect2(() => {
|
|
412
|
+
if (!params.postId) return void 0;
|
|
413
|
+
let isCurrent = true;
|
|
414
|
+
setIsLoading(true);
|
|
415
|
+
api.getPost(params.postId).then((loaded) => {
|
|
416
|
+
if (!isCurrent) return;
|
|
417
|
+
accept(loaded);
|
|
418
|
+
setIsLoading(false);
|
|
419
|
+
}).catch(() => {
|
|
420
|
+
if (isCurrent) setIsLoading(false);
|
|
421
|
+
});
|
|
422
|
+
return () => {
|
|
423
|
+
isCurrent = false;
|
|
424
|
+
};
|
|
425
|
+
}, [params.postId, api, accept]);
|
|
426
|
+
const errors = useMemo2(() => validateDraft(draft), [draft]);
|
|
427
|
+
const isDirty = isDraftDirty(draft, baseline);
|
|
428
|
+
const isValid = Object.keys(errors).length === 0;
|
|
429
|
+
function update(field, value) {
|
|
430
|
+
setFeedback(void 0);
|
|
431
|
+
setDraft((current) => {
|
|
432
|
+
const next = { ...current, [field]: value };
|
|
433
|
+
if (field === "title" && !post)
|
|
434
|
+
return { ...next, slug: deriveSlug({ title: next.title, slug: next.slug, slugTouched }) };
|
|
435
|
+
return next;
|
|
436
|
+
});
|
|
437
|
+
if (field === "slug") setSlugTouched(true);
|
|
438
|
+
}
|
|
439
|
+
async function run(action) {
|
|
440
|
+
setShowErrors(true);
|
|
441
|
+
if (!isValid) return void 0;
|
|
442
|
+
setIsBusy(true);
|
|
443
|
+
try {
|
|
444
|
+
const saved = await action();
|
|
445
|
+
accept(saved);
|
|
446
|
+
setFeedback("saved");
|
|
447
|
+
params.onSaved?.(saved);
|
|
448
|
+
return saved;
|
|
449
|
+
} catch {
|
|
450
|
+
setFeedback("saveError");
|
|
451
|
+
return void 0;
|
|
452
|
+
} finally {
|
|
453
|
+
setIsBusy(false);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
async function persist() {
|
|
457
|
+
const input = draftToInput(draft);
|
|
458
|
+
if (!post) return api.createPost(input);
|
|
459
|
+
if (!isDirty) return post;
|
|
460
|
+
return api.updatePost(post.id, input);
|
|
461
|
+
}
|
|
462
|
+
const save = () => run(persist);
|
|
463
|
+
const publishNow = () => run(async () => api.publishPost((await persist()).id));
|
|
464
|
+
const schedule = () => {
|
|
465
|
+
const publishedAt = fromDateTimeLocalValue(scheduleAt);
|
|
466
|
+
if (!publishedAt) {
|
|
467
|
+
setFeedback("errorSchedule");
|
|
468
|
+
return Promise.resolve(void 0);
|
|
469
|
+
}
|
|
470
|
+
return run(async () => api.publishPost((await persist()).id, { publishedAt }));
|
|
471
|
+
};
|
|
472
|
+
const unpublish = () => run(async () => api.unpublishPost((await persist()).id));
|
|
473
|
+
async function archive() {
|
|
474
|
+
if (!post) return;
|
|
475
|
+
setIsBusy(true);
|
|
476
|
+
try {
|
|
477
|
+
await api.archivePost(post.id);
|
|
478
|
+
const archived = { ...post, status: "archived" };
|
|
479
|
+
setPost(archived);
|
|
480
|
+
params.onArchived?.(archived);
|
|
481
|
+
} catch {
|
|
482
|
+
setFeedback("saveError");
|
|
483
|
+
} finally {
|
|
484
|
+
setIsBusy(false);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
async function uploadCover(file) {
|
|
488
|
+
if (!api.uploadCoverImage) return;
|
|
489
|
+
if (!COVER_MIME_TYPES.includes(file.type)) return setFeedback("coverInvalidType");
|
|
490
|
+
if (file.size > COVER_MAX_BYTES) return setFeedback("coverTooLarge");
|
|
491
|
+
setIsUploading(true);
|
|
492
|
+
try {
|
|
493
|
+
const { url } = await api.uploadCoverImage(file);
|
|
494
|
+
update("coverImageUrl", url);
|
|
495
|
+
} catch {
|
|
496
|
+
setFeedback("coverUploadError");
|
|
497
|
+
} finally {
|
|
498
|
+
setIsUploading(false);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return {
|
|
502
|
+
post,
|
|
503
|
+
draft,
|
|
504
|
+
update,
|
|
505
|
+
errors: showErrors ? errors : {},
|
|
506
|
+
isLoading,
|
|
507
|
+
isDirty,
|
|
508
|
+
isBusy,
|
|
509
|
+
isUploading,
|
|
510
|
+
feedback,
|
|
511
|
+
scheduleAt,
|
|
512
|
+
setScheduleAt,
|
|
513
|
+
canUploadCover: Boolean(api.uploadCoverImage),
|
|
514
|
+
tagSuggestions: (tags.data ?? []).map((entry) => entry.tag),
|
|
515
|
+
save,
|
|
516
|
+
publishNow,
|
|
517
|
+
schedule,
|
|
518
|
+
unpublish,
|
|
519
|
+
archive,
|
|
520
|
+
uploadCover
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// src/hooks/useUnsavedChangesGuard.ts
|
|
525
|
+
import { useCallback as useCallback3, useEffect as useEffect3 } from "react";
|
|
526
|
+
function useUnsavedChangesGuard(isDirty, message) {
|
|
527
|
+
useEffect3(() => {
|
|
528
|
+
if (!isDirty) return void 0;
|
|
529
|
+
const handleBeforeUnload = (event) => {
|
|
530
|
+
event.preventDefault();
|
|
531
|
+
event.returnValue = "";
|
|
532
|
+
};
|
|
533
|
+
window.addEventListener("beforeunload", handleBeforeUnload);
|
|
534
|
+
return () => window.removeEventListener("beforeunload", handleBeforeUnload);
|
|
535
|
+
}, [isDirty]);
|
|
536
|
+
const confirmLeave = useCallback3(() => !isDirty || window.confirm(message), [isDirty, message]);
|
|
537
|
+
return { confirmLeave };
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// src/components/MarkdownContent.tsx
|
|
541
|
+
import {
|
|
542
|
+
createHeadingIdGenerator,
|
|
543
|
+
DEFAULT_LINK_REL,
|
|
544
|
+
inlineToPlainText,
|
|
545
|
+
isAbsoluteHttpUrl,
|
|
546
|
+
parseMarkdown,
|
|
547
|
+
resolveHeadingLevel
|
|
548
|
+
} from "@adatechnology/content-contracts";
|
|
549
|
+
import { useMemo as useMemo3 } from "react";
|
|
550
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
551
|
+
function renderInline(nodes) {
|
|
552
|
+
return nodes.map((node, index) => {
|
|
553
|
+
switch (node.type) {
|
|
554
|
+
case "text":
|
|
555
|
+
return node.value;
|
|
556
|
+
case "strong":
|
|
557
|
+
return /* @__PURE__ */ jsx2("strong", { children: renderInline(node.children) }, index);
|
|
558
|
+
case "emphasis":
|
|
559
|
+
return /* @__PURE__ */ jsx2("em", { children: renderInline(node.children) }, index);
|
|
560
|
+
case "strikethrough":
|
|
561
|
+
return /* @__PURE__ */ jsx2("del", { children: renderInline(node.children) }, index);
|
|
562
|
+
case "inlineCode":
|
|
563
|
+
return /* @__PURE__ */ jsx2("code", { children: node.value }, index);
|
|
564
|
+
case "break":
|
|
565
|
+
return /* @__PURE__ */ jsx2("br", {}, index);
|
|
566
|
+
case "image":
|
|
567
|
+
return /* @__PURE__ */ jsx2("img", { src: node.src, alt: node.alt, title: node.title, loading: "lazy", decoding: "async" }, index);
|
|
568
|
+
case "link":
|
|
569
|
+
return /* @__PURE__ */ jsx2(
|
|
570
|
+
"a",
|
|
571
|
+
{
|
|
572
|
+
href: node.href,
|
|
573
|
+
title: node.title,
|
|
574
|
+
rel: DEFAULT_LINK_REL,
|
|
575
|
+
...isAbsoluteHttpUrl(node.href) ? { target: "_blank" } : {},
|
|
576
|
+
children: renderInline(node.children)
|
|
577
|
+
},
|
|
578
|
+
index
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
function renderBlock(block, key, context, tight = false) {
|
|
584
|
+
switch (block.type) {
|
|
585
|
+
case "heading": {
|
|
586
|
+
const Tag = `h${resolveHeadingLevel(block.level, context.offset)}`;
|
|
587
|
+
return /* @__PURE__ */ jsx2(Tag, { id: context.nextHeadingId(inlineToPlainText(block.children)), children: renderInline(block.children) }, key);
|
|
588
|
+
}
|
|
589
|
+
case "paragraph":
|
|
590
|
+
return tight ? /* @__PURE__ */ jsx2("span", { children: renderInline(block.children) }, key) : /* @__PURE__ */ jsx2("p", { children: renderInline(block.children) }, key);
|
|
591
|
+
case "blockquote":
|
|
592
|
+
return /* @__PURE__ */ jsx2("blockquote", { children: block.children.map((child, index) => renderBlock(child, index, context)) }, key);
|
|
593
|
+
case "codeBlock":
|
|
594
|
+
return /* @__PURE__ */ jsx2("pre", { children: /* @__PURE__ */ jsx2("code", { className: block.language ? `language-${block.language}` : void 0, children: block.value }) }, key);
|
|
595
|
+
case "thematicBreak":
|
|
596
|
+
return /* @__PURE__ */ jsx2("hr", {}, key);
|
|
597
|
+
case "list": {
|
|
598
|
+
const items = block.items.map((item, index) => /* @__PURE__ */ jsx2("li", { children: item.map((child, childIndex) => renderBlock(child, childIndex, context, block.tight)) }, index));
|
|
599
|
+
return block.ordered ? /* @__PURE__ */ jsx2("ol", { start: block.start, children: items }, key) : /* @__PURE__ */ jsx2("ul", { children: items }, key);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
function MarkdownContent({ markdown, headingLevelOffset = 0, className }) {
|
|
604
|
+
const document = useMemo3(() => parseMarkdown(markdown), [markdown]);
|
|
605
|
+
const context = { offset: headingLevelOffset, nextHeadingId: createHeadingIdGenerator() };
|
|
606
|
+
return /* @__PURE__ */ jsx2("div", { className: ["adc-prose", className].filter(Boolean).join(" "), children: document.children.map((block, index) => renderBlock(block, index, context)) });
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// src/components/StatusChip.tsx
|
|
610
|
+
import { POST_STATUS } from "@adatechnology/content-contracts";
|
|
611
|
+
import { Archive, CalendarClock, CircleCheck, PencilLine } from "lucide-react";
|
|
612
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
613
|
+
var STATUS_VIEW = {
|
|
614
|
+
[POST_STATUS.DRAFT]: { icon: PencilLine, label: "statusDraft" },
|
|
615
|
+
[POST_STATUS.SCHEDULED]: { icon: CalendarClock, label: "statusScheduled" },
|
|
616
|
+
[POST_STATUS.PUBLISHED]: { icon: CircleCheck, label: "statusPublished" },
|
|
617
|
+
[POST_STATUS.ARCHIVED]: { icon: Archive, label: "statusArchived" }
|
|
618
|
+
};
|
|
619
|
+
function StatusChip({ status }) {
|
|
620
|
+
const { messages } = useContentText();
|
|
621
|
+
const { icon: Icon, label } = STATUS_VIEW[status];
|
|
622
|
+
return /* @__PURE__ */ jsxs("span", { className: `adc-chip adc-chip--${status}`, children: [
|
|
623
|
+
/* @__PURE__ */ jsx3(Icon, { "aria-hidden": "true", className: "adc-icon" }),
|
|
624
|
+
messages[label]
|
|
625
|
+
] });
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// src/components/TagsInput.tsx
|
|
629
|
+
import { normalizeTags, TAGS_MAX_COUNT } from "@adatechnology/content-contracts";
|
|
630
|
+
import { X } from "lucide-react";
|
|
631
|
+
import { useId, useState as useState3 } from "react";
|
|
632
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
633
|
+
function TagsInput({ value, onChange, suggestions = [], label }) {
|
|
634
|
+
const { messages, format } = useContentText();
|
|
635
|
+
const [text, setText] = useState3("");
|
|
636
|
+
const inputId = useId();
|
|
637
|
+
const listId = useId();
|
|
638
|
+
function commit(raw) {
|
|
639
|
+
const added = splitTagInput(raw);
|
|
640
|
+
if (added.length > 0) onChange(normalizeTags([...value, ...added]));
|
|
641
|
+
setText("");
|
|
642
|
+
}
|
|
643
|
+
function handleKeyDown(event) {
|
|
644
|
+
if (event.key === "Enter" || event.key === ",") {
|
|
645
|
+
event.preventDefault();
|
|
646
|
+
commit(text);
|
|
647
|
+
} else if (event.key === "Backspace" && !text && value.length > 0) {
|
|
648
|
+
onChange(value.slice(0, -1));
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
return /* @__PURE__ */ jsxs2("div", { className: "adc-field", children: [
|
|
652
|
+
/* @__PURE__ */ jsx4("label", { htmlFor: inputId, children: label }),
|
|
653
|
+
/* @__PURE__ */ jsxs2("div", { className: "adc-tags-input", children: [
|
|
654
|
+
value.map((tag) => /* @__PURE__ */ jsxs2("span", { className: "adc-tag", children: [
|
|
655
|
+
tag,
|
|
656
|
+
/* @__PURE__ */ jsx4(
|
|
657
|
+
"button",
|
|
658
|
+
{
|
|
659
|
+
type: "button",
|
|
660
|
+
className: "adc-tag-remove",
|
|
661
|
+
"aria-label": format("tagRemove", { tag }),
|
|
662
|
+
onClick: () => onChange(value.filter((current) => current !== tag)),
|
|
663
|
+
children: /* @__PURE__ */ jsx4(X, { "aria-hidden": "true", className: "adc-icon" })
|
|
664
|
+
}
|
|
665
|
+
)
|
|
666
|
+
] }, tag)),
|
|
667
|
+
/* @__PURE__ */ jsx4(
|
|
668
|
+
"input",
|
|
669
|
+
{
|
|
670
|
+
id: inputId,
|
|
671
|
+
value: text,
|
|
672
|
+
list: suggestions.length > 0 ? listId : void 0,
|
|
673
|
+
disabled: value.length >= TAGS_MAX_COUNT,
|
|
674
|
+
onChange: (event) => setText(event.target.value),
|
|
675
|
+
onKeyDown: handleKeyDown,
|
|
676
|
+
onBlur: () => commit(text),
|
|
677
|
+
"aria-describedby": `${inputId}-hint`
|
|
678
|
+
}
|
|
679
|
+
)
|
|
680
|
+
] }),
|
|
681
|
+
/* @__PURE__ */ jsx4("small", { id: `${inputId}-hint`, className: "adc-hint", children: messages.tagsHint }),
|
|
682
|
+
suggestions.length > 0 && /* @__PURE__ */ jsx4("datalist", { id: listId, children: suggestions.filter((tag) => !value.includes(tag)).map((tag) => /* @__PURE__ */ jsx4("option", { value: tag }, tag)) })
|
|
683
|
+
] });
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// src/components/PostEditor.tsx
|
|
687
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
688
|
+
function TextField({ label, value, onChange, error, hint, type = "text", multiline, maxLength }) {
|
|
689
|
+
const id = useId2();
|
|
690
|
+
const describedBy = [hint ? `${id}-hint` : "", error ? `${id}-error` : ""].filter(Boolean).join(" ") || void 0;
|
|
691
|
+
const common = {
|
|
692
|
+
id,
|
|
693
|
+
value,
|
|
694
|
+
maxLength,
|
|
695
|
+
"aria-invalid": error ? true : void 0,
|
|
696
|
+
"aria-describedby": describedBy
|
|
697
|
+
};
|
|
698
|
+
return /* @__PURE__ */ jsxs3("div", { className: "adc-field", children: [
|
|
699
|
+
/* @__PURE__ */ jsx5("label", { htmlFor: id, children: label }),
|
|
700
|
+
multiline ? /* @__PURE__ */ jsx5("textarea", { ...common, rows: 3, onChange: (event) => onChange(event.target.value) }) : /* @__PURE__ */ jsx5("input", { ...common, type, onChange: (event) => onChange(event.target.value) }),
|
|
701
|
+
hint && /* @__PURE__ */ jsx5("small", { id: `${id}-hint`, className: "adc-hint", children: hint }),
|
|
702
|
+
error && /* @__PURE__ */ jsx5("small", { id: `${id}-error`, className: "adc-error", children: error })
|
|
703
|
+
] });
|
|
704
|
+
}
|
|
705
|
+
function Section({ title, children }) {
|
|
706
|
+
return /* @__PURE__ */ jsxs3("fieldset", { className: "adc-section", children: [
|
|
707
|
+
/* @__PURE__ */ jsx5("legend", { children: title }),
|
|
708
|
+
children
|
|
709
|
+
] });
|
|
710
|
+
}
|
|
711
|
+
function PostEditor({ postId, defaults, onSaved, onArchived, onClose }) {
|
|
712
|
+
const { messages, locale, format } = useContentText();
|
|
713
|
+
const editor = usePostEditor({
|
|
714
|
+
...postId ? { postId } : {},
|
|
715
|
+
...defaults ? { defaults } : {},
|
|
716
|
+
...onSaved ? { onSaved } : {},
|
|
717
|
+
...onArchived ? { onArchived } : {}
|
|
718
|
+
});
|
|
719
|
+
const { confirmLeave } = useUnsavedChangesGuard(editor.isDirty, messages.unsavedConfirm);
|
|
720
|
+
const [tab, setTab] = useState4("write");
|
|
721
|
+
const bodyId = useId2();
|
|
722
|
+
const scheduleId = useId2();
|
|
723
|
+
const { draft, update, errors, post } = editor;
|
|
724
|
+
if (editor.isLoading) {
|
|
725
|
+
return /* @__PURE__ */ jsx5("p", { className: "adc-root adc-state", role: "status", children: messages.loading });
|
|
726
|
+
}
|
|
727
|
+
const status = post?.status;
|
|
728
|
+
const isLive = status === "published" || status === "scheduled";
|
|
729
|
+
return /* @__PURE__ */ jsxs3(
|
|
730
|
+
"form",
|
|
731
|
+
{
|
|
732
|
+
className: "adc-root adc-editor",
|
|
733
|
+
onSubmit: (event) => {
|
|
734
|
+
event.preventDefault();
|
|
735
|
+
void editor.save();
|
|
736
|
+
},
|
|
737
|
+
children: [
|
|
738
|
+
/* @__PURE__ */ jsxs3("header", { className: "adc-toolbar", children: [
|
|
739
|
+
onClose && /* @__PURE__ */ jsxs3("button", { type: "button", className: "adc-button adc-button--ghost", onClick: () => confirmLeave() && onClose(), children: [
|
|
740
|
+
/* @__PURE__ */ jsx5(ArrowLeft, { "aria-hidden": "true", className: "adc-icon" }),
|
|
741
|
+
messages.close
|
|
742
|
+
] }),
|
|
743
|
+
/* @__PURE__ */ jsx5("h2", { className: "adc-title", children: post ? messages.editorEditTitle : messages.editorNewTitle }),
|
|
744
|
+
status && /* @__PURE__ */ jsx5(StatusChip, { status }),
|
|
745
|
+
editor.isDirty && /* @__PURE__ */ jsx5("span", { className: "adc-badge", children: messages.unsavedBadge })
|
|
746
|
+
] }),
|
|
747
|
+
/* @__PURE__ */ jsxs3("div", { className: "adc-editor-grid", children: [
|
|
748
|
+
/* @__PURE__ */ jsxs3("div", { className: "adc-editor-main", children: [
|
|
749
|
+
/* @__PURE__ */ jsx5(
|
|
750
|
+
TextField,
|
|
751
|
+
{
|
|
752
|
+
label: messages.fieldTitle,
|
|
753
|
+
value: draft.title,
|
|
754
|
+
maxLength: 200,
|
|
755
|
+
onChange: (value) => update("title", value),
|
|
756
|
+
error: errors.title ? messages.errorTitle : void 0
|
|
757
|
+
}
|
|
758
|
+
),
|
|
759
|
+
/* @__PURE__ */ jsx5(
|
|
760
|
+
TextField,
|
|
761
|
+
{
|
|
762
|
+
label: messages.fieldSlug,
|
|
763
|
+
value: draft.slug,
|
|
764
|
+
maxLength: 120,
|
|
765
|
+
hint: messages.fieldSlugHint,
|
|
766
|
+
onChange: (value) => update("slug", value.toLowerCase()),
|
|
767
|
+
error: errors.slug ? messages.errorSlug : void 0
|
|
768
|
+
}
|
|
769
|
+
),
|
|
770
|
+
/* @__PURE__ */ jsx5(
|
|
771
|
+
TextField,
|
|
772
|
+
{
|
|
773
|
+
label: messages.fieldExcerpt,
|
|
774
|
+
value: draft.excerpt,
|
|
775
|
+
maxLength: 500,
|
|
776
|
+
multiline: true,
|
|
777
|
+
onChange: (value) => update("excerpt", value)
|
|
778
|
+
}
|
|
779
|
+
),
|
|
780
|
+
/* @__PURE__ */ jsxs3("div", { className: "adc-field", children: [
|
|
781
|
+
/* @__PURE__ */ jsxs3("div", { className: "adc-tabs", role: "tablist", "aria-label": messages.fieldBody, children: [
|
|
782
|
+
/* @__PURE__ */ jsx5("span", { className: "adc-label", id: `${bodyId}-label`, children: messages.fieldBody }),
|
|
783
|
+
["write", "preview"].map((value) => /* @__PURE__ */ jsx5(
|
|
784
|
+
"button",
|
|
785
|
+
{
|
|
786
|
+
type: "button",
|
|
787
|
+
role: "tab",
|
|
788
|
+
"aria-selected": tab === value,
|
|
789
|
+
"aria-controls": `${bodyId}-${value}`,
|
|
790
|
+
className: "adc-tab",
|
|
791
|
+
onClick: () => setTab(value),
|
|
792
|
+
children: value === "write" ? messages.tabWrite : messages.tabPreview
|
|
793
|
+
},
|
|
794
|
+
value
|
|
795
|
+
))
|
|
796
|
+
] }),
|
|
797
|
+
/* @__PURE__ */ jsxs3("div", { className: `adc-body-panes adc-body-panes--${tab}`, children: [
|
|
798
|
+
/* @__PURE__ */ jsxs3("div", { id: `${bodyId}-write`, role: "tabpanel", className: "adc-pane adc-pane--write", children: [
|
|
799
|
+
/* @__PURE__ */ jsx5(
|
|
800
|
+
"textarea",
|
|
801
|
+
{
|
|
802
|
+
"aria-labelledby": `${bodyId}-label`,
|
|
803
|
+
"aria-describedby": `${bodyId}-hint`,
|
|
804
|
+
className: "adc-markdown-input",
|
|
805
|
+
value: draft.body,
|
|
806
|
+
onChange: (event) => update("body", event.target.value)
|
|
807
|
+
}
|
|
808
|
+
),
|
|
809
|
+
/* @__PURE__ */ jsx5("small", { id: `${bodyId}-hint`, className: "adc-hint", children: messages.bodyHint })
|
|
810
|
+
] }),
|
|
811
|
+
/* @__PURE__ */ jsx5("div", { id: `${bodyId}-preview`, role: "tabpanel", className: "adc-pane adc-pane--preview", "aria-live": "polite", children: draft.body.trim() ? /* @__PURE__ */ jsx5(MarkdownContent, { markdown: draft.body, headingLevelOffset: 1 }) : /* @__PURE__ */ jsx5("p", { className: "adc-muted", children: messages.previewEmpty }) })
|
|
812
|
+
] })
|
|
813
|
+
] })
|
|
814
|
+
] }),
|
|
815
|
+
/* @__PURE__ */ jsxs3("aside", { className: "adc-editor-side", children: [
|
|
816
|
+
/* @__PURE__ */ jsxs3(Section, { title: messages.publishSection, children: [
|
|
817
|
+
post?.publishedAt && /* @__PURE__ */ jsx5("p", { className: "adc-muted", children: format(status === "scheduled" ? "scheduledFor" : "publishedOn", {
|
|
818
|
+
date: formatPostDate(post.publishedAt, locale, true)
|
|
819
|
+
}) }),
|
|
820
|
+
/* @__PURE__ */ jsxs3("button", { type: "submit", className: "adc-button", disabled: editor.isBusy, children: [
|
|
821
|
+
/* @__PURE__ */ jsx5(Save, { "aria-hidden": "true", className: "adc-icon" }),
|
|
822
|
+
editor.isBusy ? messages.saving : isLive ? messages.saveChanges : messages.save
|
|
823
|
+
] }),
|
|
824
|
+
status !== "published" && /* @__PURE__ */ jsxs3(
|
|
825
|
+
"button",
|
|
826
|
+
{
|
|
827
|
+
type: "button",
|
|
828
|
+
className: "adc-button adc-button--primary",
|
|
829
|
+
disabled: editor.isBusy,
|
|
830
|
+
onClick: () => void editor.publishNow(),
|
|
831
|
+
children: [
|
|
832
|
+
/* @__PURE__ */ jsx5(Send, { "aria-hidden": "true", className: "adc-icon" }),
|
|
833
|
+
messages.publishNow
|
|
834
|
+
]
|
|
835
|
+
}
|
|
836
|
+
),
|
|
837
|
+
/* @__PURE__ */ jsxs3("div", { className: "adc-field", children: [
|
|
838
|
+
/* @__PURE__ */ jsx5("label", { htmlFor: scheduleId, children: messages.scheduleAt }),
|
|
839
|
+
/* @__PURE__ */ jsx5(
|
|
840
|
+
"input",
|
|
841
|
+
{
|
|
842
|
+
id: scheduleId,
|
|
843
|
+
type: "datetime-local",
|
|
844
|
+
value: editor.scheduleAt,
|
|
845
|
+
onChange: (event) => editor.setScheduleAt(event.target.value)
|
|
846
|
+
}
|
|
847
|
+
)
|
|
848
|
+
] }),
|
|
849
|
+
/* @__PURE__ */ jsxs3(
|
|
850
|
+
"button",
|
|
851
|
+
{
|
|
852
|
+
type: "button",
|
|
853
|
+
className: "adc-button",
|
|
854
|
+
disabled: editor.isBusy || !editor.scheduleAt,
|
|
855
|
+
onClick: () => void editor.schedule(),
|
|
856
|
+
children: [
|
|
857
|
+
/* @__PURE__ */ jsx5(CalendarClock2, { "aria-hidden": "true", className: "adc-icon" }),
|
|
858
|
+
messages.schedule
|
|
859
|
+
]
|
|
860
|
+
}
|
|
861
|
+
),
|
|
862
|
+
isLive && /* @__PURE__ */ jsxs3(
|
|
863
|
+
"button",
|
|
864
|
+
{
|
|
865
|
+
type: "button",
|
|
866
|
+
className: "adc-button",
|
|
867
|
+
disabled: editor.isBusy,
|
|
868
|
+
onClick: () => void editor.unpublish(),
|
|
869
|
+
children: [
|
|
870
|
+
/* @__PURE__ */ jsx5(EyeOff, { "aria-hidden": "true", className: "adc-icon" }),
|
|
871
|
+
messages.unpublish
|
|
872
|
+
]
|
|
873
|
+
}
|
|
874
|
+
),
|
|
875
|
+
post && status !== "archived" && /* @__PURE__ */ jsxs3(
|
|
876
|
+
"button",
|
|
877
|
+
{
|
|
878
|
+
type: "button",
|
|
879
|
+
className: "adc-button adc-button--danger",
|
|
880
|
+
disabled: editor.isBusy,
|
|
881
|
+
onClick: () => window.confirm(messages.archiveConfirm) && void editor.archive(),
|
|
882
|
+
children: [
|
|
883
|
+
/* @__PURE__ */ jsx5(Archive2, { "aria-hidden": "true", className: "adc-icon" }),
|
|
884
|
+
messages.archive
|
|
885
|
+
]
|
|
886
|
+
}
|
|
887
|
+
),
|
|
888
|
+
editor.feedback && /* @__PURE__ */ jsx5(
|
|
889
|
+
"p",
|
|
890
|
+
{
|
|
891
|
+
className: editor.feedback === "saved" ? "adc-success" : "adc-error",
|
|
892
|
+
role: editor.feedback === "saved" ? "status" : "alert",
|
|
893
|
+
children: messages[editor.feedback]
|
|
894
|
+
}
|
|
895
|
+
)
|
|
896
|
+
] }),
|
|
897
|
+
/* @__PURE__ */ jsxs3(Section, { title: messages.fieldCover, children: [
|
|
898
|
+
draft.coverImageUrl && /* @__PURE__ */ jsx5("img", { className: "adc-cover-preview", src: draft.coverImageUrl, alt: draft.coverImageAlt }),
|
|
899
|
+
editor.canUploadCover && /* @__PURE__ */ jsxs3("label", { className: "adc-button adc-upload", children: [
|
|
900
|
+
/* @__PURE__ */ jsx5(ImageUp, { "aria-hidden": "true", className: "adc-icon" }),
|
|
901
|
+
editor.isUploading ? messages.coverUploading : messages.coverUpload,
|
|
902
|
+
/* @__PURE__ */ jsx5(
|
|
903
|
+
"input",
|
|
904
|
+
{
|
|
905
|
+
type: "file",
|
|
906
|
+
accept: "image/jpeg,image/png,image/webp",
|
|
907
|
+
className: "adc-visually-hidden",
|
|
908
|
+
disabled: editor.isUploading,
|
|
909
|
+
onChange: (event) => {
|
|
910
|
+
const file = event.target.files?.[0];
|
|
911
|
+
event.target.value = "";
|
|
912
|
+
if (file) void editor.uploadCover(file);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
)
|
|
916
|
+
] }),
|
|
917
|
+
/* @__PURE__ */ jsx5(
|
|
918
|
+
TextField,
|
|
919
|
+
{
|
|
920
|
+
label: messages.fieldCoverUrl,
|
|
921
|
+
type: "url",
|
|
922
|
+
value: draft.coverImageUrl,
|
|
923
|
+
onChange: (value) => update("coverImageUrl", value),
|
|
924
|
+
error: errors.coverImageUrl ? messages.errorUrl : void 0
|
|
925
|
+
}
|
|
926
|
+
),
|
|
927
|
+
/* @__PURE__ */ jsx5(
|
|
928
|
+
TextField,
|
|
929
|
+
{
|
|
930
|
+
label: messages.fieldCoverAlt,
|
|
931
|
+
value: draft.coverImageAlt,
|
|
932
|
+
maxLength: 300,
|
|
933
|
+
onChange: (value) => update("coverImageAlt", value)
|
|
934
|
+
}
|
|
935
|
+
),
|
|
936
|
+
draft.coverImageUrl && /* @__PURE__ */ jsxs3(
|
|
937
|
+
"button",
|
|
938
|
+
{
|
|
939
|
+
type: "button",
|
|
940
|
+
className: "adc-button adc-button--ghost",
|
|
941
|
+
onClick: () => update("coverImageUrl", ""),
|
|
942
|
+
children: [
|
|
943
|
+
/* @__PURE__ */ jsx5(Trash2, { "aria-hidden": "true", className: "adc-icon" }),
|
|
944
|
+
messages.coverRemove
|
|
945
|
+
]
|
|
946
|
+
}
|
|
947
|
+
)
|
|
948
|
+
] }),
|
|
949
|
+
/* @__PURE__ */ jsxs3(Section, { title: messages.fieldTags, children: [
|
|
950
|
+
/* @__PURE__ */ jsx5(
|
|
951
|
+
TagsInput,
|
|
952
|
+
{
|
|
953
|
+
label: messages.fieldTags,
|
|
954
|
+
value: draft.tags,
|
|
955
|
+
suggestions: editor.tagSuggestions,
|
|
956
|
+
onChange: (tags) => update("tags", tags)
|
|
957
|
+
}
|
|
958
|
+
),
|
|
959
|
+
/* @__PURE__ */ jsx5(
|
|
960
|
+
TextField,
|
|
961
|
+
{
|
|
962
|
+
label: messages.fieldAuthor,
|
|
963
|
+
value: draft.authorName,
|
|
964
|
+
maxLength: 120,
|
|
965
|
+
onChange: (value) => update("authorName", value)
|
|
966
|
+
}
|
|
967
|
+
)
|
|
968
|
+
] }),
|
|
969
|
+
/* @__PURE__ */ jsxs3(Section, { title: messages.seoSection, children: [
|
|
970
|
+
/* @__PURE__ */ jsx5(
|
|
971
|
+
TextField,
|
|
972
|
+
{
|
|
973
|
+
label: messages.fieldSeoTitle,
|
|
974
|
+
value: draft.seoTitle,
|
|
975
|
+
maxLength: 200,
|
|
976
|
+
onChange: (value) => update("seoTitle", value)
|
|
977
|
+
}
|
|
978
|
+
),
|
|
979
|
+
/* @__PURE__ */ jsx5(
|
|
980
|
+
TextField,
|
|
981
|
+
{
|
|
982
|
+
label: messages.fieldSeoDescription,
|
|
983
|
+
value: draft.seoDescription,
|
|
984
|
+
maxLength: 320,
|
|
985
|
+
multiline: true,
|
|
986
|
+
onChange: (value) => update("seoDescription", value)
|
|
987
|
+
}
|
|
988
|
+
),
|
|
989
|
+
/* @__PURE__ */ jsx5(
|
|
990
|
+
TextField,
|
|
991
|
+
{
|
|
992
|
+
label: messages.fieldCanonical,
|
|
993
|
+
type: "url",
|
|
994
|
+
value: draft.canonicalUrl,
|
|
995
|
+
onChange: (value) => update("canonicalUrl", value),
|
|
996
|
+
error: errors.canonicalUrl ? messages.errorUrl : void 0
|
|
997
|
+
}
|
|
998
|
+
)
|
|
999
|
+
] })
|
|
1000
|
+
] })
|
|
1001
|
+
] })
|
|
1002
|
+
]
|
|
1003
|
+
}
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// src/components/PostList.tsx
|
|
1008
|
+
import { POST_STATUSES } from "@adatechnology/content-contracts";
|
|
1009
|
+
import { Plus, RotateCcw, Search } from "lucide-react";
|
|
1010
|
+
import { useId as useId3 } from "react";
|
|
1011
|
+
|
|
1012
|
+
// src/hooks/usePostList.ts
|
|
1013
|
+
import { useState as useState5 } from "react";
|
|
1014
|
+
function usePostList(params) {
|
|
1015
|
+
const api = useContentAdminApi();
|
|
1016
|
+
const [filters, setFilters] = useState5({});
|
|
1017
|
+
const [page, setPage] = useState5(1);
|
|
1018
|
+
const key = JSON.stringify({ filters, page, pageSize: params.pageSize, reload: params.reloadKey ?? 0 });
|
|
1019
|
+
const posts = useAsyncResource(() => api.listPosts({ ...filters, page, pageSize: params.pageSize }), key);
|
|
1020
|
+
const tags = useAsyncResource(
|
|
1021
|
+
() => api.listTags ? api.listTags() : Promise.resolve([]),
|
|
1022
|
+
`tags-${params.reloadKey ?? 0}`
|
|
1023
|
+
);
|
|
1024
|
+
function updateFilters(next) {
|
|
1025
|
+
setFilters(next);
|
|
1026
|
+
setPage(1);
|
|
1027
|
+
}
|
|
1028
|
+
return {
|
|
1029
|
+
posts,
|
|
1030
|
+
tags: api.listTags ? tags.data ?? [] : void 0,
|
|
1031
|
+
filters,
|
|
1032
|
+
updateFilters,
|
|
1033
|
+
page,
|
|
1034
|
+
setPage,
|
|
1035
|
+
hasFilters: Boolean(filters.status || filters.tag || filters.search)
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// src/components/Pagination.tsx
|
|
1040
|
+
import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
1041
|
+
|
|
1042
|
+
// src/lib/pagination.ts
|
|
1043
|
+
function buildPageItems(params) {
|
|
1044
|
+
const siblings = params.siblings ?? 1;
|
|
1045
|
+
const total = Math.max(1, params.total);
|
|
1046
|
+
const current = Math.min(Math.max(1, params.current), total);
|
|
1047
|
+
const pages = /* @__PURE__ */ new Set([1, total]);
|
|
1048
|
+
for (let page = current - siblings; page <= current + siblings; page += 1) {
|
|
1049
|
+
if (page >= 1 && page <= total) pages.add(page);
|
|
1050
|
+
}
|
|
1051
|
+
const items = [];
|
|
1052
|
+
let previous = 0;
|
|
1053
|
+
for (const page of [...pages].sort((left, right) => left - right)) {
|
|
1054
|
+
if (page - previous > 1) items.push({ kind: "gap", key: `gap-${previous}` });
|
|
1055
|
+
items.push({ kind: "page", page });
|
|
1056
|
+
previous = page;
|
|
1057
|
+
}
|
|
1058
|
+
return items;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// src/components/Pagination.tsx
|
|
1062
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1063
|
+
function Pagination({ page, totalPages, getPageHref, onPageChange }) {
|
|
1064
|
+
const { messages, format } = useContentText();
|
|
1065
|
+
const renderLink = useRenderLink();
|
|
1066
|
+
if (totalPages <= 1) return null;
|
|
1067
|
+
function renderTarget(target, label, content, isCurrent = false) {
|
|
1068
|
+
const className = `adc-page${isCurrent ? " adc-page--current" : ""}`;
|
|
1069
|
+
if (getPageHref && !isCurrent)
|
|
1070
|
+
return renderLink({ href: getPageHref(target), className, "aria-label": label, children: content });
|
|
1071
|
+
return /* @__PURE__ */ jsx6(
|
|
1072
|
+
"button",
|
|
1073
|
+
{
|
|
1074
|
+
type: "button",
|
|
1075
|
+
className,
|
|
1076
|
+
"aria-label": label,
|
|
1077
|
+
"aria-current": isCurrent ? "page" : void 0,
|
|
1078
|
+
disabled: isCurrent,
|
|
1079
|
+
onClick: () => onPageChange?.(target),
|
|
1080
|
+
children: content
|
|
1081
|
+
}
|
|
1082
|
+
);
|
|
1083
|
+
}
|
|
1084
|
+
return /* @__PURE__ */ jsxs4("nav", { className: "adc-pagination", "aria-label": messages.paginationLabel, children: [
|
|
1085
|
+
page > 1 && renderTarget(page - 1, messages.paginationPrevious, /* @__PURE__ */ jsx6(ChevronLeft, { "aria-hidden": "true", className: "adc-icon" })),
|
|
1086
|
+
buildPageItems({ current: page, total: totalPages }).map(
|
|
1087
|
+
(item) => item.kind === "gap" ? /* @__PURE__ */ jsx6("span", { className: "adc-page-gap", "aria-hidden": "true", children: "\u2026" }, item.key) : /* @__PURE__ */ jsx6("span", { children: renderTarget(item.page, format("pageLabel", { page: item.page }), item.page, item.page === page) }, item.page)
|
|
1088
|
+
),
|
|
1089
|
+
page < totalPages && renderTarget(page + 1, messages.paginationNext, /* @__PURE__ */ jsx6(ChevronRight, { "aria-hidden": "true", className: "adc-icon" }))
|
|
1090
|
+
] });
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// src/components/PostList.tsx
|
|
1094
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1095
|
+
var STATUS_LABEL = {
|
|
1096
|
+
draft: "statusDraft",
|
|
1097
|
+
scheduled: "statusScheduled",
|
|
1098
|
+
published: "statusPublished",
|
|
1099
|
+
archived: "statusArchived"
|
|
1100
|
+
};
|
|
1101
|
+
function PostList({ onSelect, onCreate, pageSize = 20, reloadKey }) {
|
|
1102
|
+
const { messages, locale } = useContentText();
|
|
1103
|
+
const { posts, tags, filters, updateFilters, page, setPage, hasFilters } = usePostList({
|
|
1104
|
+
pageSize,
|
|
1105
|
+
...reloadKey !== void 0 ? { reloadKey } : {}
|
|
1106
|
+
});
|
|
1107
|
+
const searchId = useId3();
|
|
1108
|
+
const statusId = useId3();
|
|
1109
|
+
const tagId = useId3();
|
|
1110
|
+
return /* @__PURE__ */ jsxs5("section", { className: "adc-root adc-post-list", children: [
|
|
1111
|
+
/* @__PURE__ */ jsxs5("header", { className: "adc-toolbar", children: [
|
|
1112
|
+
/* @__PURE__ */ jsx7("h2", { className: "adc-title", children: messages.listTitle }),
|
|
1113
|
+
onCreate && /* @__PURE__ */ jsxs5("button", { type: "button", className: "adc-button adc-button--primary", onClick: onCreate, children: [
|
|
1114
|
+
/* @__PURE__ */ jsx7(Plus, { "aria-hidden": "true", className: "adc-icon" }),
|
|
1115
|
+
messages.newPost
|
|
1116
|
+
] })
|
|
1117
|
+
] }),
|
|
1118
|
+
/* @__PURE__ */ jsxs5("div", { className: "adc-filters", children: [
|
|
1119
|
+
/* @__PURE__ */ jsxs5("div", { className: "adc-field adc-field--search", children: [
|
|
1120
|
+
/* @__PURE__ */ jsx7("label", { htmlFor: searchId, children: messages.searchLabel }),
|
|
1121
|
+
/* @__PURE__ */ jsxs5("div", { className: "adc-input-icon", children: [
|
|
1122
|
+
/* @__PURE__ */ jsx7(Search, { "aria-hidden": "true", className: "adc-icon" }),
|
|
1123
|
+
/* @__PURE__ */ jsx7(
|
|
1124
|
+
"input",
|
|
1125
|
+
{
|
|
1126
|
+
id: searchId,
|
|
1127
|
+
type: "search",
|
|
1128
|
+
placeholder: messages.searchPlaceholder,
|
|
1129
|
+
value: filters.search ?? "",
|
|
1130
|
+
onChange: (event) => updateFilters({ ...filters, search: event.target.value || void 0 })
|
|
1131
|
+
}
|
|
1132
|
+
)
|
|
1133
|
+
] })
|
|
1134
|
+
] }),
|
|
1135
|
+
/* @__PURE__ */ jsxs5("div", { className: "adc-field", children: [
|
|
1136
|
+
/* @__PURE__ */ jsx7("label", { htmlFor: statusId, children: messages.filterStatus }),
|
|
1137
|
+
/* @__PURE__ */ jsxs5(
|
|
1138
|
+
"select",
|
|
1139
|
+
{
|
|
1140
|
+
id: statusId,
|
|
1141
|
+
value: filters.status ?? "",
|
|
1142
|
+
onChange: (event) => updateFilters({ ...filters, status: event.target.value || void 0 }),
|
|
1143
|
+
children: [
|
|
1144
|
+
/* @__PURE__ */ jsx7("option", { value: "", children: messages.filterAll }),
|
|
1145
|
+
POST_STATUSES.map((status) => /* @__PURE__ */ jsx7("option", { value: status, children: messages[STATUS_LABEL[status]] }, status))
|
|
1146
|
+
]
|
|
1147
|
+
}
|
|
1148
|
+
)
|
|
1149
|
+
] }),
|
|
1150
|
+
/* @__PURE__ */ jsxs5("div", { className: "adc-field", children: [
|
|
1151
|
+
/* @__PURE__ */ jsx7("label", { htmlFor: tagId, children: messages.filterTag }),
|
|
1152
|
+
/* @__PURE__ */ jsx7(
|
|
1153
|
+
"input",
|
|
1154
|
+
{
|
|
1155
|
+
id: tagId,
|
|
1156
|
+
list: tags && tags.length > 0 ? `${tagId}-list` : void 0,
|
|
1157
|
+
value: filters.tag ?? "",
|
|
1158
|
+
onChange: (event) => updateFilters({ ...filters, tag: event.target.value || void 0 })
|
|
1159
|
+
}
|
|
1160
|
+
),
|
|
1161
|
+
tags && /* @__PURE__ */ jsx7("datalist", { id: `${tagId}-list`, children: tags.map((entry) => /* @__PURE__ */ jsx7("option", { value: entry.tag }, entry.tag)) })
|
|
1162
|
+
] }),
|
|
1163
|
+
hasFilters && /* @__PURE__ */ jsxs5("button", { type: "button", className: "adc-button adc-button--ghost", onClick: () => updateFilters({}), children: [
|
|
1164
|
+
/* @__PURE__ */ jsx7(RotateCcw, { "aria-hidden": "true", className: "adc-icon" }),
|
|
1165
|
+
messages.clearFilters
|
|
1166
|
+
] })
|
|
1167
|
+
] }),
|
|
1168
|
+
posts.error !== void 0 && !posts.isLoading ? /* @__PURE__ */ jsxs5("div", { className: "adc-state adc-state--error", role: "alert", children: [
|
|
1169
|
+
messages.loadError,
|
|
1170
|
+
/* @__PURE__ */ jsx7("button", { type: "button", className: "adc-button", onClick: posts.reload, children: messages.retry })
|
|
1171
|
+
] }) : posts.isLoading && !posts.data ? /* @__PURE__ */ jsx7("p", { className: "adc-state", role: "status", children: messages.loading }) : (posts.data?.data.length ?? 0) === 0 ? /* @__PURE__ */ jsx7("p", { className: "adc-state", children: messages.empty }) : /* @__PURE__ */ jsx7("div", { className: "adc-table-wrap", "aria-busy": posts.isLoading, children: /* @__PURE__ */ jsxs5("table", { className: "adc-table", children: [
|
|
1172
|
+
/* @__PURE__ */ jsx7("thead", { children: /* @__PURE__ */ jsxs5("tr", { children: [
|
|
1173
|
+
/* @__PURE__ */ jsx7("th", { scope: "col", children: messages.columnTitle }),
|
|
1174
|
+
/* @__PURE__ */ jsx7("th", { scope: "col", children: messages.columnStatus }),
|
|
1175
|
+
/* @__PURE__ */ jsx7("th", { scope: "col", children: messages.columnPublished }),
|
|
1176
|
+
/* @__PURE__ */ jsx7("th", { scope: "col", children: messages.columnUpdated })
|
|
1177
|
+
] }) }),
|
|
1178
|
+
/* @__PURE__ */ jsx7("tbody", { children: posts.data?.data.map((post) => /* @__PURE__ */ jsxs5("tr", { children: [
|
|
1179
|
+
/* @__PURE__ */ jsxs5("td", { children: [
|
|
1180
|
+
/* @__PURE__ */ jsx7("button", { type: "button", className: "adc-row-link", onClick: () => onSelect(post), children: post.title }),
|
|
1181
|
+
/* @__PURE__ */ jsxs5("span", { className: "adc-muted adc-slug", children: [
|
|
1182
|
+
"/",
|
|
1183
|
+
post.slug
|
|
1184
|
+
] })
|
|
1185
|
+
] }),
|
|
1186
|
+
/* @__PURE__ */ jsx7("td", { children: /* @__PURE__ */ jsx7(StatusChip, { status: post.status }) }),
|
|
1187
|
+
/* @__PURE__ */ jsx7("td", { children: formatPostDate(post.publishedAt, locale, true) }),
|
|
1188
|
+
/* @__PURE__ */ jsx7("td", { children: formatPostDate(post.updatedAt, locale, true) })
|
|
1189
|
+
] }, post.id)) })
|
|
1190
|
+
] }) }),
|
|
1191
|
+
posts.data && /* @__PURE__ */ jsx7(Pagination, { page, totalPages: posts.data.pagination.totalPages, onPageChange: setPage })
|
|
1192
|
+
] });
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
// src/components/ContentWorkspace.tsx
|
|
1196
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1197
|
+
function ContentWorkspace({ pageSize, newPostDefaults, onPostSaved }) {
|
|
1198
|
+
const [view, setView] = useState6({ kind: "list" });
|
|
1199
|
+
const [reloadKey, setReloadKey] = useState6(0);
|
|
1200
|
+
function handleSaved(post) {
|
|
1201
|
+
setReloadKey((value) => value + 1);
|
|
1202
|
+
setView({ kind: "editor", postId: post.id });
|
|
1203
|
+
onPostSaved?.(post);
|
|
1204
|
+
}
|
|
1205
|
+
if (view.kind === "editor") {
|
|
1206
|
+
return /* @__PURE__ */ jsx8(
|
|
1207
|
+
PostEditor,
|
|
1208
|
+
{
|
|
1209
|
+
...view.postId ? { postId: view.postId } : {},
|
|
1210
|
+
...newPostDefaults ? { defaults: newPostDefaults } : {},
|
|
1211
|
+
onSaved: handleSaved,
|
|
1212
|
+
onArchived: () => {
|
|
1213
|
+
setReloadKey((value) => value + 1);
|
|
1214
|
+
setView({ kind: "list" });
|
|
1215
|
+
},
|
|
1216
|
+
onClose: () => setView({ kind: "list" })
|
|
1217
|
+
},
|
|
1218
|
+
view.postId ?? "new"
|
|
1219
|
+
);
|
|
1220
|
+
}
|
|
1221
|
+
return /* @__PURE__ */ jsx8(
|
|
1222
|
+
PostList,
|
|
1223
|
+
{
|
|
1224
|
+
reloadKey,
|
|
1225
|
+
...pageSize ? { pageSize } : {},
|
|
1226
|
+
onSelect: (post) => setView({ kind: "editor", postId: post.id }),
|
|
1227
|
+
onCreate: () => setView({ kind: "editor" })
|
|
1228
|
+
}
|
|
1229
|
+
);
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
// src/components/PostCard.tsx
|
|
1233
|
+
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1234
|
+
function PostCard({ post, href, headingLevel = 2 }) {
|
|
1235
|
+
const { messages, locale, format } = useContentText();
|
|
1236
|
+
const renderLink = useRenderLink();
|
|
1237
|
+
const Heading = `h${headingLevel}`;
|
|
1238
|
+
return /* @__PURE__ */ jsxs6("article", { className: "adc-card", children: [
|
|
1239
|
+
post.coverImageUrl && /* @__PURE__ */ jsx9(
|
|
1240
|
+
"img",
|
|
1241
|
+
{
|
|
1242
|
+
className: "adc-card-cover",
|
|
1243
|
+
src: post.coverImageUrl,
|
|
1244
|
+
alt: post.coverImageAlt ?? "",
|
|
1245
|
+
loading: "lazy",
|
|
1246
|
+
decoding: "async"
|
|
1247
|
+
}
|
|
1248
|
+
),
|
|
1249
|
+
/* @__PURE__ */ jsxs6("div", { className: "adc-card-body", children: [
|
|
1250
|
+
/* @__PURE__ */ jsx9(Heading, { className: "adc-card-title", children: renderLink({ href, className: "adc-card-link", children: post.title }) }),
|
|
1251
|
+
/* @__PURE__ */ jsxs6("p", { className: "adc-meta", children: [
|
|
1252
|
+
/* @__PURE__ */ jsx9("time", { dateTime: post.publishedAt, children: formatPostDate(post.publishedAt, locale) }),
|
|
1253
|
+
/* @__PURE__ */ jsx9("span", { "aria-hidden": "true", children: " \xB7 " }),
|
|
1254
|
+
format("readingTime", { minutes: post.readingTimeMinutes })
|
|
1255
|
+
] }),
|
|
1256
|
+
post.excerpt && /* @__PURE__ */ jsx9("p", { className: "adc-card-excerpt", children: post.excerpt }),
|
|
1257
|
+
post.tags.length > 0 && /* @__PURE__ */ jsx9("ul", { className: "adc-tag-list", children: post.tags.map((tag) => /* @__PURE__ */ jsx9("li", { className: "adc-tag", children: tag }, tag)) }),
|
|
1258
|
+
/* @__PURE__ */ jsx9("span", { className: "adc-card-more", "aria-hidden": "true", children: messages.readMore })
|
|
1259
|
+
] })
|
|
1260
|
+
] });
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
// src/components/PostListPage.tsx
|
|
1264
|
+
import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1265
|
+
function PostListPage({ page = 1, tag, pageSize = 10, getPostHref, getListHref, title }) {
|
|
1266
|
+
const api = useContentPublicApi();
|
|
1267
|
+
const { messages } = useContentText();
|
|
1268
|
+
const renderLink = useRenderLink();
|
|
1269
|
+
const posts = useAsyncResource(
|
|
1270
|
+
() => api.listPublishedPosts({ page, pageSize, ...tag ? { tag } : {} }),
|
|
1271
|
+
JSON.stringify({ page, pageSize, tag })
|
|
1272
|
+
);
|
|
1273
|
+
const tags = useAsyncResource(
|
|
1274
|
+
() => api.listTags ? api.listTags() : Promise.resolve([]),
|
|
1275
|
+
"public-tags"
|
|
1276
|
+
);
|
|
1277
|
+
const withTag = (target) => getListHref({ page: target, ...tag ? { tag } : {} });
|
|
1278
|
+
return /* @__PURE__ */ jsxs7("section", { className: "adc-root adc-public-list", children: [
|
|
1279
|
+
title && /* @__PURE__ */ jsx10("h1", { className: "adc-page-title", children: title }),
|
|
1280
|
+
(tags.data?.length ?? 0) > 0 && /* @__PURE__ */ jsxs7("nav", { className: "adc-tag-filter", "aria-label": messages.tagsLabel, children: [
|
|
1281
|
+
renderLink({
|
|
1282
|
+
href: getListHref({ page: 1 }),
|
|
1283
|
+
className: `adc-tag-chip${tag ? "" : " adc-tag-chip--active"}`,
|
|
1284
|
+
...tag ? {} : { "aria-current": "page" },
|
|
1285
|
+
children: messages.allTags
|
|
1286
|
+
}),
|
|
1287
|
+
tags.data?.map(
|
|
1288
|
+
(entry) => renderLink({
|
|
1289
|
+
href: getListHref({ page: 1, tag: entry.tag }),
|
|
1290
|
+
className: `adc-tag-chip${entry.tag === tag ? " adc-tag-chip--active" : ""}`,
|
|
1291
|
+
...entry.tag === tag ? { "aria-current": "page" } : {},
|
|
1292
|
+
children: `${entry.tag} (${entry.count})`
|
|
1293
|
+
})
|
|
1294
|
+
)
|
|
1295
|
+
] }),
|
|
1296
|
+
posts.isLoading && !posts.data ? /* @__PURE__ */ jsx10("p", { className: "adc-state", role: "status", children: messages.loading }) : posts.error !== void 0 ? /* @__PURE__ */ jsxs7("div", { className: "adc-state adc-state--error", role: "alert", children: [
|
|
1297
|
+
messages.loadError,
|
|
1298
|
+
/* @__PURE__ */ jsx10("button", { type: "button", className: "adc-button", onClick: posts.reload, children: messages.retry })
|
|
1299
|
+
] }) : (posts.data?.data.length ?? 0) === 0 ? /* @__PURE__ */ jsx10("p", { className: "adc-state", children: messages.postsEmpty }) : /* @__PURE__ */ jsx10("div", { className: "adc-card-grid", children: posts.data?.data.map((post) => /* @__PURE__ */ jsx10(PostCard, { post, href: getPostHref(post.slug) }, post.id)) }),
|
|
1300
|
+
posts.data && /* @__PURE__ */ jsx10(Pagination, { page, totalPages: posts.data.pagination.totalPages, getPageHref: withTag })
|
|
1301
|
+
] });
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
// src/components/PostPage.tsx
|
|
1305
|
+
import { useEffect as useEffect5 } from "react";
|
|
1306
|
+
|
|
1307
|
+
// src/components/ShareButtons.tsx
|
|
1308
|
+
import { Check, Link2, Share2 } from "lucide-react";
|
|
1309
|
+
import { useEffect as useEffect4, useState as useState7 } from "react";
|
|
1310
|
+
|
|
1311
|
+
// src/lib/share.ts
|
|
1312
|
+
var SHARE_NETWORK = {
|
|
1313
|
+
WHATSAPP: "whatsapp",
|
|
1314
|
+
FACEBOOK: "facebook",
|
|
1315
|
+
X: "x",
|
|
1316
|
+
LINKEDIN: "linkedin"
|
|
1317
|
+
};
|
|
1318
|
+
var SHARE_NETWORKS = Object.values(SHARE_NETWORK);
|
|
1319
|
+
function buildShareLinks(params) {
|
|
1320
|
+
const url = encodeURIComponent(params.url);
|
|
1321
|
+
const text = encodeURIComponent(params.title);
|
|
1322
|
+
return [
|
|
1323
|
+
{
|
|
1324
|
+
network: SHARE_NETWORK.WHATSAPP,
|
|
1325
|
+
href: `https://wa.me/?text=${encodeURIComponent(`${params.title} ${params.url}`)}`
|
|
1326
|
+
},
|
|
1327
|
+
{ network: SHARE_NETWORK.FACEBOOK, href: `https://www.facebook.com/sharer/sharer.php?u=${url}` },
|
|
1328
|
+
{ network: SHARE_NETWORK.X, href: `https://x.com/intent/post?url=${url}&text=${text}` },
|
|
1329
|
+
{ network: SHARE_NETWORK.LINKEDIN, href: `https://www.linkedin.com/sharing/share-offsite/?url=${url}` }
|
|
1330
|
+
];
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
// src/components/ShareButtons.tsx
|
|
1334
|
+
import { jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1335
|
+
var NETWORK_LABEL = {
|
|
1336
|
+
[SHARE_NETWORK.WHATSAPP]: "shareWhatsApp",
|
|
1337
|
+
[SHARE_NETWORK.FACEBOOK]: "shareFacebook",
|
|
1338
|
+
[SHARE_NETWORK.X]: "shareX",
|
|
1339
|
+
[SHARE_NETWORK.LINKEDIN]: "shareLinkedIn"
|
|
1340
|
+
};
|
|
1341
|
+
var COPIED_FEEDBACK_MS = 2e3;
|
|
1342
|
+
function ShareButtons({ url, title, networks }) {
|
|
1343
|
+
const { messages, format } = useContentText();
|
|
1344
|
+
const [isCopied, setIsCopied] = useState7(false);
|
|
1345
|
+
const links = buildShareLinks({ url, title }).filter((link) => !networks || networks.includes(link.network));
|
|
1346
|
+
const [capabilities, setCapabilities] = useState7({ canShareNatively: false, canCopy: false });
|
|
1347
|
+
useEffect4(() => {
|
|
1348
|
+
setCapabilities({
|
|
1349
|
+
canShareNatively: typeof navigator.share === "function",
|
|
1350
|
+
canCopy: Boolean(navigator.clipboard)
|
|
1351
|
+
});
|
|
1352
|
+
}, []);
|
|
1353
|
+
const { canShareNatively, canCopy } = capabilities;
|
|
1354
|
+
async function handleCopy() {
|
|
1355
|
+
await navigator.clipboard.writeText(url);
|
|
1356
|
+
setIsCopied(true);
|
|
1357
|
+
window.setTimeout(() => setIsCopied(false), COPIED_FEEDBACK_MS);
|
|
1358
|
+
}
|
|
1359
|
+
return /* @__PURE__ */ jsxs8("div", { className: "adc-share", role: "group", "aria-label": messages.shareLabel, children: [
|
|
1360
|
+
/* @__PURE__ */ jsx11("span", { className: "adc-label", children: messages.shareLabel }),
|
|
1361
|
+
canShareNatively && /* @__PURE__ */ jsxs8(
|
|
1362
|
+
"button",
|
|
1363
|
+
{
|
|
1364
|
+
type: "button",
|
|
1365
|
+
className: "adc-button",
|
|
1366
|
+
onClick: () => void navigator.share({ url, title }).catch(() => void 0),
|
|
1367
|
+
children: [
|
|
1368
|
+
/* @__PURE__ */ jsx11(Share2, { "aria-hidden": "true", className: "adc-icon" }),
|
|
1369
|
+
messages.shareNative
|
|
1370
|
+
]
|
|
1371
|
+
}
|
|
1372
|
+
),
|
|
1373
|
+
links.map((link) => /* @__PURE__ */ jsx11(
|
|
1374
|
+
"a",
|
|
1375
|
+
{
|
|
1376
|
+
className: `adc-button adc-share-link adc-share-link--${link.network}`,
|
|
1377
|
+
href: link.href,
|
|
1378
|
+
target: "_blank",
|
|
1379
|
+
rel: "noopener noreferrer",
|
|
1380
|
+
"aria-label": format("shareOn", { network: messages[NETWORK_LABEL[link.network]] }),
|
|
1381
|
+
children: messages[NETWORK_LABEL[link.network]]
|
|
1382
|
+
},
|
|
1383
|
+
link.network
|
|
1384
|
+
)),
|
|
1385
|
+
canCopy && /* @__PURE__ */ jsxs8("button", { type: "button", className: "adc-button", onClick: () => void handleCopy().catch(() => void 0), children: [
|
|
1386
|
+
isCopied ? /* @__PURE__ */ jsx11(Check, { "aria-hidden": "true", className: "adc-icon" }) : /* @__PURE__ */ jsx11(Link2, { "aria-hidden": "true", className: "adc-icon" }),
|
|
1387
|
+
/* @__PURE__ */ jsx11("span", { "aria-live": "polite", children: isCopied ? messages.linkCopied : messages.copyLink })
|
|
1388
|
+
] })
|
|
1389
|
+
] });
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
// src/components/PostPage.tsx
|
|
1393
|
+
import { Fragment, jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1394
|
+
function PostPage({ slug, shareUrl, shareNetworks, getTagHref, onLoaded, renderNotFound }) {
|
|
1395
|
+
const api = useContentPublicApi();
|
|
1396
|
+
const { messages, locale, format } = useContentText();
|
|
1397
|
+
const renderLink = useRenderLink();
|
|
1398
|
+
const resource = useAsyncResource(() => api.getPublishedPost(slug), slug);
|
|
1399
|
+
const post = resource.data;
|
|
1400
|
+
useEffect5(() => {
|
|
1401
|
+
if (post) onLoaded?.(post);
|
|
1402
|
+
}, [post, onLoaded]);
|
|
1403
|
+
if (resource.isLoading && !post) {
|
|
1404
|
+
return /* @__PURE__ */ jsx12("p", { className: "adc-root adc-state", role: "status", children: messages.loading });
|
|
1405
|
+
}
|
|
1406
|
+
if (!post) {
|
|
1407
|
+
return /* @__PURE__ */ jsx12(Fragment, { children: renderNotFound ? renderNotFound() : /* @__PURE__ */ jsx12("p", { className: "adc-root adc-state", children: messages.notFound }) });
|
|
1408
|
+
}
|
|
1409
|
+
const url = shareUrl ?? (typeof window !== "undefined" ? window.location.href : "");
|
|
1410
|
+
return /* @__PURE__ */ jsxs9("article", { className: "adc-root adc-post", children: [
|
|
1411
|
+
/* @__PURE__ */ jsxs9("header", { className: "adc-post-header", children: [
|
|
1412
|
+
/* @__PURE__ */ jsx12("h1", { className: "adc-page-title", children: post.title }),
|
|
1413
|
+
/* @__PURE__ */ jsxs9("p", { className: "adc-meta", children: [
|
|
1414
|
+
/* @__PURE__ */ jsx12("time", { dateTime: post.publishedAt, children: formatPostDate(post.publishedAt, locale) }),
|
|
1415
|
+
/* @__PURE__ */ jsx12("span", { "aria-hidden": "true", children: " \xB7 " }),
|
|
1416
|
+
format("readingTime", { minutes: post.readingTimeMinutes }),
|
|
1417
|
+
post.authorName && /* @__PURE__ */ jsxs9(Fragment, { children: [
|
|
1418
|
+
/* @__PURE__ */ jsx12("span", { "aria-hidden": "true", children: " \xB7 " }),
|
|
1419
|
+
format("byAuthor", { author: post.authorName })
|
|
1420
|
+
] })
|
|
1421
|
+
] }),
|
|
1422
|
+
post.tags.length > 0 && /* @__PURE__ */ jsx12("ul", { className: "adc-tag-list", children: post.tags.map((tag) => /* @__PURE__ */ jsx12("li", { className: "adc-tag", children: getTagHref ? renderLink({ href: getTagHref(tag), children: tag }) : tag }, tag)) })
|
|
1423
|
+
] }),
|
|
1424
|
+
post.coverImageUrl && /* @__PURE__ */ jsx12("img", { className: "adc-post-cover", src: post.coverImageUrl, alt: post.coverImageAlt ?? "", decoding: "async" }),
|
|
1425
|
+
/* @__PURE__ */ jsx12(MarkdownContent, { markdown: post.body, headingLevelOffset: 1 }),
|
|
1426
|
+
url && shareNetworks?.length !== 0 && /* @__PURE__ */ jsx12(ShareButtons, { url, title: post.title, ...shareNetworks ? { networks: shareNetworks } : {} })
|
|
1427
|
+
] });
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
// src/lib/seo.ts
|
|
1431
|
+
import { buildExcerpt } from "@adatechnology/content-contracts";
|
|
1432
|
+
function buildPostMeta(post, params) {
|
|
1433
|
+
const baseTitle = post.seoTitle ?? post.title;
|
|
1434
|
+
const title = params.siteName ? `${baseTitle} | ${params.siteName}` : baseTitle;
|
|
1435
|
+
const description = post.seoDescription ?? post.excerpt ?? buildExcerpt(post.body, 160);
|
|
1436
|
+
const url = post.canonicalUrl ?? params.url;
|
|
1437
|
+
return {
|
|
1438
|
+
title,
|
|
1439
|
+
description,
|
|
1440
|
+
canonicalUrl: url,
|
|
1441
|
+
openGraph: {
|
|
1442
|
+
type: "article",
|
|
1443
|
+
title: baseTitle,
|
|
1444
|
+
description,
|
|
1445
|
+
url,
|
|
1446
|
+
...post.coverImageUrl ? { image: post.coverImageUrl } : {},
|
|
1447
|
+
...post.coverImageAlt ? { imageAlt: post.coverImageAlt } : {},
|
|
1448
|
+
publishedTime: post.publishedAt,
|
|
1449
|
+
modifiedTime: post.updatedAt,
|
|
1450
|
+
tags: post.tags
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
export {
|
|
1455
|
+
COVER_MAX_BYTES,
|
|
1456
|
+
COVER_MIME_TYPES,
|
|
1457
|
+
ContentProvider,
|
|
1458
|
+
ContentWorkspace,
|
|
1459
|
+
DEFAULT_CONTENT_LOCALE,
|
|
1460
|
+
DRAFT_ERROR,
|
|
1461
|
+
EMPTY_POST_DRAFT,
|
|
1462
|
+
MarkdownContent,
|
|
1463
|
+
Pagination,
|
|
1464
|
+
PostCard,
|
|
1465
|
+
PostEditor,
|
|
1466
|
+
PostList,
|
|
1467
|
+
PostListPage,
|
|
1468
|
+
PostPage,
|
|
1469
|
+
SHARE_NETWORK,
|
|
1470
|
+
SHARE_NETWORKS,
|
|
1471
|
+
ShareButtons,
|
|
1472
|
+
StatusChip,
|
|
1473
|
+
TagsInput,
|
|
1474
|
+
buildPageItems,
|
|
1475
|
+
buildPostMeta,
|
|
1476
|
+
buildShareLinks,
|
|
1477
|
+
deriveSlug,
|
|
1478
|
+
draftFromPost,
|
|
1479
|
+
draftToInput,
|
|
1480
|
+
formatPostDate,
|
|
1481
|
+
fromDateTimeLocalValue,
|
|
1482
|
+
interpolate,
|
|
1483
|
+
isDraftDirty,
|
|
1484
|
+
resolveContentMessages,
|
|
1485
|
+
splitTagInput,
|
|
1486
|
+
toDateTimeLocalValue,
|
|
1487
|
+
useAsyncResource,
|
|
1488
|
+
useContentAdminApi,
|
|
1489
|
+
useContentPublicApi,
|
|
1490
|
+
useContentText,
|
|
1491
|
+
usePostEditor,
|
|
1492
|
+
usePostList,
|
|
1493
|
+
useRenderLink,
|
|
1494
|
+
useUnsavedChangesGuard,
|
|
1495
|
+
validateDraft
|
|
1496
|
+
};
|
|
1497
|
+
//# sourceMappingURL=index.js.map
|