@adatechnology/content-ui 0.0.0-stage → 0.2.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 +138 -2
- package/dist/index.d.ts +762 -0
- package/dist/index.js +2114 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +725 -0
- package/dist/styles.css.map +1 -0
- package/package.json +44 -3
package/README.md
CHANGED
|
@@ -1,3 +1,139 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @adatechnology/content-ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Telas de **blog / novidades / notícias** para React 18+: painel (lista e editor com Markdown, prévia
|
|
4
|
+
ao vivo, capa, tags, SEO, agendamento) e site público (card, lista com paginação e filtro de tag,
|
|
5
|
+
página do post com compartilhamento). Pareado com `@adatechnology/content-module`, mas não faz
|
|
6
|
+
`fetch`: o host injeta a API.
|
|
7
|
+
|
|
8
|
+
## Instalação
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
bun add @adatechnology/content-ui @adatechnology/content-contracts
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import '@adatechnology/content-ui/styles.css'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Painel
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { ContentProvider, ContentWorkspace, type ContentAdminApi } from '@adatechnology/content-ui'
|
|
22
|
+
|
|
23
|
+
const adminApi: ContentAdminApi = {
|
|
24
|
+
listPosts: (params) => http.get('/v1/content/posts', { params }), // → { data, pagination }
|
|
25
|
+
getPost: (id) => http.get(`/v1/content/posts/${id}`).then((r) => r.data),
|
|
26
|
+
createPost: (input) => http.post('/v1/content/posts', input).then((r) => r.data),
|
|
27
|
+
updatePost: (id, input) => http.patch(`/v1/content/posts/${id}`, input).then((r) => r.data),
|
|
28
|
+
publishPost: (id, input) => http.post(`/v1/content/posts/${id}/publish`, input).then((r) => r.data),
|
|
29
|
+
unpublishPost: (id) => http.post(`/v1/content/posts/${id}/unpublish`).then((r) => r.data),
|
|
30
|
+
archivePost: (id) => http.delete(`/v1/content/posts/${id}`),
|
|
31
|
+
listTags: () => http.get('/v1/content/posts/tags').then((r) => r.data), // opcional
|
|
32
|
+
uploadCoverImage: (file) => http.post('/v1/content/posts/cover-images', file, { // opcional
|
|
33
|
+
headers: { 'Content-Type': file.type },
|
|
34
|
+
}).then((r) => r.data),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
<ContentProvider adminApi={adminApi} locale="pt-BR" messages={{ listTitle: 'Novidades' }}>
|
|
38
|
+
<ContentWorkspace newPostDefaults={{ authorName: user.name }} />
|
|
39
|
+
</ContentProvider>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`ContentWorkspace` é a tela composta (lista ↔ editor). As peças também saem soltas:
|
|
43
|
+
|
|
44
|
+
| Componente | Props |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `PostList` | `onSelect(post)`, `onCreate?()`, `pageSize?`, `reloadKey?` |
|
|
47
|
+
| `PostEditor` | `postId?`, `defaults?`, `onSaved?(post)`, `onArchived?(post)`, `onClose?()` |
|
|
48
|
+
| `StatusChip` | `status` |
|
|
49
|
+
| `TagsInput` | `value`, `onChange`, `suggestions?`, `label` |
|
|
50
|
+
|
|
51
|
+
O editor protege alterações não salvas (aviso do navegador ao fechar a aba e confirmação no botão
|
|
52
|
+
Voltar), valida com o mesmo schema do servidor, gera o slug do título enquanto o autor não o edita
|
|
53
|
+
e esconde o upload quando a API não tem `uploadCoverImage`.
|
|
54
|
+
|
|
55
|
+
### Editor do corpo: barra, emoji, imagens e seletores
|
|
56
|
+
|
|
57
|
+
O corpo continua sendo **Markdown** (o formato guardado não muda); a barra escreve a sintaxe sobre a
|
|
58
|
+
seleção: negrito, itálico, título (H2/H3), lista, lista numerada, citação, link, imagem e emoji.
|
|
59
|
+
Atalhos: `Ctrl/Cmd+B`, `Ctrl/Cmd+I`, `Ctrl/Cmd+K`. A prévia fica ao lado no desktop e em aba no celular.
|
|
60
|
+
|
|
61
|
+
- **Imagem no corpo**: o botão abre um painel com URL, descrição (alt) e, se o host definiu
|
|
62
|
+
`uploadCoverImage`, "Enviar do aparelho" (no celular o sistema oferece câmera ou galeria). O arquivo
|
|
63
|
+
sobe pela mesma API da capa (mesmos limites: JPG/PNG/WebP até 1 MB) e entra como ``.
|
|
64
|
+
- **Emoji**: painel com busca (nome em pt-BR ou en) e categorias, sem dependência.
|
|
65
|
+
- **Esconder a barra**: `<ContentWorkspace showFormattingToolbar={false} />` (ou no `PostEditor`).
|
|
66
|
+
- **Seletor de data e hora próprio** para "Agendar para": `renderDateTimeInput`.
|
|
67
|
+
O valor é `YYYY-MM-DDTHH:mm` (hora local, 24h).
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
<ContentWorkspace
|
|
71
|
+
renderDateTimeInput={({ id, label, value, onChange }) => (
|
|
72
|
+
<MyDateTimePicker id={id} label={label} value={value} onChange={onChange} />
|
|
73
|
+
)}
|
|
74
|
+
/>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
- **Seletor de arquivo** estilizado (botão + nome do arquivo): textos em `coverUpload`,
|
|
78
|
+
`imageUploadFromDevice` e `fileNoneChosen` (`messages`), não os do navegador.
|
|
79
|
+
- Headless: `toggleWrap`, `toggleLinePrefix`, `insertLink`, `insertImage`, `insertText` e `MarkdownEditor`.
|
|
80
|
+
|
|
81
|
+
## Site público
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
import { ContentProvider, PostListPage, PostPage, buildPostMeta, type ContentPublicApi } from '@adatechnology/content-ui'
|
|
85
|
+
|
|
86
|
+
const publicApi: ContentPublicApi = {
|
|
87
|
+
listPublishedPosts: (params) => fetchJson('/v1/content/public/posts', params),
|
|
88
|
+
getPublishedPost: (slug) => fetchJson(`/v1/content/public/posts/${slug}`).then((r) => r.data),
|
|
89
|
+
listTags: () => fetchJson('/v1/content/public/tags').then((r) => r.data), // opcional
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
<ContentProvider publicApi={publicApi} renderLink={({ href, ...props }) => <Link to={href} {...props} />}>
|
|
93
|
+
<PostListPage
|
|
94
|
+
page={page}
|
|
95
|
+
tag={tag}
|
|
96
|
+
title="Novidades"
|
|
97
|
+
getPostHref={(slug) => `/blog/${slug}`}
|
|
98
|
+
getListHref={({ page, tag }) => `/blog?page=${page}${tag ? `&tag=${encodeURIComponent(tag)}` : ''}`}
|
|
99
|
+
/>
|
|
100
|
+
<PostPage slug={slug} getTagHref={(tag) => `/blog?tag=${tag}`} onLoaded={(post) => setHead(buildPostMeta(post, { url }))} />
|
|
101
|
+
</ContentProvider>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
| Componente | Props |
|
|
105
|
+
|---|---|
|
|
106
|
+
| `PostListPage` | `page?`, `tag?`, `pageSize?`, `getPostHref(slug)`, `getListHref({ page, tag? })`, `title?` |
|
|
107
|
+
| `PostPage` | `slug`, `shareUrl?`, `shareNetworks?`, `getTagHref?`, `onLoaded?(post)`, `renderNotFound?()` |
|
|
108
|
+
| `PostCard` | `post`, `href`, `headingLevel?` |
|
|
109
|
+
| `ShareButtons` | `url`, `title`, `networks?` (`whatsapp`, `facebook`, `x`, `linkedin`) |
|
|
110
|
+
| `MarkdownContent` | `markdown`, `headingLevelOffset?` |
|
|
111
|
+
|
|
112
|
+
O corpo é renderizado do AST do `content-contracts` direto em elementos React — **sem
|
|
113
|
+
`dangerouslySetInnerHTML`**. Compartilhar usa só URLs das redes (nenhum script de terceiro), mais
|
|
114
|
+
"Copiar link" e o Web Share nativo quando o navegador tem.
|
|
115
|
+
|
|
116
|
+
## Tema
|
|
117
|
+
|
|
118
|
+
Sem cor própria: sobrescreva as variáveis no escopo do host.
|
|
119
|
+
|
|
120
|
+
```css
|
|
121
|
+
:root {
|
|
122
|
+
--adc-accent: #0f766e;
|
|
123
|
+
--adc-surface: #ffffff;
|
|
124
|
+
--adc-text: #0f172a;
|
|
125
|
+
--adc-muted: #64748b;
|
|
126
|
+
--adc-border: #e2e8f0;
|
|
127
|
+
--adc-radius-base: 12px;
|
|
128
|
+
--adc-font-title: 'Space Grotesk', system-ui;
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Responsivo a partir de 375px (uma coluna; 2 em 640px; 3 e editor lado a lado em 1024px), áreas de
|
|
133
|
+
toque de 44px, `prefers-reduced-motion` respeitado.
|
|
134
|
+
|
|
135
|
+
## Textos
|
|
136
|
+
|
|
137
|
+
`pt-BR` (padrão) e `en`. `messages` sobrescreve chaves pontuais. Camada headless: `usePostEditor`,
|
|
138
|
+
`usePostList`, `useUnsavedChangesGuard`, mais os utilitários puros (`buildShareLinks`,
|
|
139
|
+
`buildPostMeta`, `draftToInput`, `validateDraft`, `buildPageItems`).
|