@adatechnology/content-ui 0.1.0 → 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 CHANGED
@@ -52,6 +52,32 @@ O editor protege alterações não salvas (aviso do navegador ao fechar a aba e
52
52
  Voltar), valida com o mesmo schema do servidor, gera o slug do título enquanto o autor não o edita
53
53
  e esconde o upload quando a API não tem `uploadCoverImage`.
54
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 `![alt](url)`.
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
+
55
81
  ## Site público
56
82
 
57
83
  ```tsx
package/dist/index.d.ts CHANGED
@@ -92,6 +92,38 @@ var shareOn = "Compartilhar no {network}";
92
92
  var notFound = "Post não encontrado.";
93
93
  var postsEmpty = "Nenhum post publicado ainda.";
94
94
  var clearFilters = "Limpar filtros";
95
+ var bodyHintToolbar = "Selecione o texto e use os botões acima. Atalhos: Ctrl+B negrito, Ctrl+I itálico, Ctrl+K link.";
96
+ var toolbarLabel = "Formatação do texto";
97
+ var formatBold = "Negrito";
98
+ var formatItalic = "Itálico";
99
+ var formatHeading2 = "Título";
100
+ var formatHeading3 = "Subtítulo";
101
+ var formatBulletList = "Lista com marcadores";
102
+ var formatNumberedList = "Lista numerada";
103
+ var formatQuote = "Citação";
104
+ var formatLink = "Link";
105
+ var formatImage = "Imagem";
106
+ var formatEmoji = "Emoji";
107
+ var formatSampleText = "texto";
108
+ var linkDialogTitle = "Inserir link";
109
+ var linkUrl = "Endereço do link (URL)";
110
+ var linkText = "Texto do link";
111
+ var imageDialogTitle = "Inserir imagem";
112
+ var imageUploadFromDevice = "Enviar do aparelho";
113
+ var dialogInsert = "Inserir";
114
+ var dialogCancel = "Cancelar";
115
+ var fileNoneChosen = "Nenhum arquivo escolhido";
116
+ var emojiTitle = "Escolher emoji";
117
+ var emojiSearch = "Buscar emoji";
118
+ var emojiCategories = "Categorias de emoji";
119
+ var emojiEmpty = "Nenhum emoji encontrado.";
120
+ var emojiSmileys = "Rostos";
121
+ var emojiGestures = "Gestos";
122
+ var emojiFood = "Comida";
123
+ var emojiNature = "Natureza";
124
+ var emojiTravel = "Lugares";
125
+ var emojiObjects = "Objetos";
126
+ var emojiSymbols = "Símbolos";
95
127
  var ptBR = {
96
128
  statusDraft: statusDraft,
97
129
  statusScheduled: statusScheduled,
@@ -181,7 +213,39 @@ var ptBR = {
181
213
  shareOn: shareOn,
182
214
  notFound: notFound,
183
215
  postsEmpty: postsEmpty,
184
- clearFilters: clearFilters
216
+ clearFilters: clearFilters,
217
+ bodyHintToolbar: bodyHintToolbar,
218
+ toolbarLabel: toolbarLabel,
219
+ formatBold: formatBold,
220
+ formatItalic: formatItalic,
221
+ formatHeading2: formatHeading2,
222
+ formatHeading3: formatHeading3,
223
+ formatBulletList: formatBulletList,
224
+ formatNumberedList: formatNumberedList,
225
+ formatQuote: formatQuote,
226
+ formatLink: formatLink,
227
+ formatImage: formatImage,
228
+ formatEmoji: formatEmoji,
229
+ formatSampleText: formatSampleText,
230
+ linkDialogTitle: linkDialogTitle,
231
+ linkUrl: linkUrl,
232
+ linkText: linkText,
233
+ imageDialogTitle: imageDialogTitle,
234
+ imageUploadFromDevice: imageUploadFromDevice,
235
+ dialogInsert: dialogInsert,
236
+ dialogCancel: dialogCancel,
237
+ fileNoneChosen: fileNoneChosen,
238
+ emojiTitle: emojiTitle,
239
+ emojiSearch: emojiSearch,
240
+ emojiCategories: emojiCategories,
241
+ emojiEmpty: emojiEmpty,
242
+ emojiSmileys: emojiSmileys,
243
+ emojiGestures: emojiGestures,
244
+ emojiFood: emojiFood,
245
+ emojiNature: emojiNature,
246
+ emojiTravel: emojiTravel,
247
+ emojiObjects: emojiObjects,
248
+ emojiSymbols: emojiSymbols
185
249
  };
186
250
 
187
251
  /**
@@ -250,6 +314,15 @@ type RenderLinkProps = {
250
314
  };
251
315
  /** Troca o `<a>` pelo `Link` do roteador do host (Next, React Router…) sem o pacote conhecê-lo. */
252
316
  type RenderLink = (props: RenderLinkProps) => ReactNode;
317
+ type DateTimeInputProps = {
318
+ readonly id: string;
319
+ readonly label: string;
320
+ /** Formato `YYYY-MM-DDTHH:mm` (hora local, 24h), ou vazio. */
321
+ readonly value: string;
322
+ readonly onChange: (value: string) => void;
323
+ };
324
+ /** Troca o `<input type="datetime-local">` nativo pelo seletor de data e hora do host. */
325
+ type RenderDateTimeInput = (props: DateTimeInputProps) => ReactNode;
253
326
 
254
327
  type ContentProviderProps = {
255
328
  /** Painel: lista e editor. Site público não precisa passar. */
@@ -321,8 +394,10 @@ type ContentWorkspaceProps = {
321
394
  /** Valores iniciais do post novo (ex.: autor logado). */
322
395
  readonly newPostDefaults?: Partial<PostDraft>;
323
396
  readonly onPostSaved?: (post: Post) => void;
397
+ readonly showFormattingToolbar?: boolean;
398
+ readonly renderDateTimeInput?: RenderDateTimeInput;
324
399
  };
325
- declare function ContentWorkspace({ pageSize, newPostDefaults, onPostSaved }: ContentWorkspaceProps): react.JSX.Element;
400
+ declare function ContentWorkspace({ pageSize, newPostDefaults, onPostSaved, showFormattingToolbar, renderDateTimeInput, }: ContentWorkspaceProps): react.JSX.Element;
326
401
 
327
402
  type PostListProps = {
328
403
  readonly onSelect: (post: PostSummary) => void;
@@ -343,8 +418,85 @@ type PostEditorProps = {
343
418
  readonly onArchived?: (post: Post) => void;
344
419
  /** Ausente: sem botão Voltar. Só é chamado depois de confirmar alterações não salvas. */
345
420
  readonly onClose?: () => void;
421
+ /** Barra de formatação do corpo (padrão: ligada). O formato guardado é Markdown nos dois casos. */
422
+ readonly showFormattingToolbar?: boolean;
423
+ /** Seletor de data e hora do host para "Agendar para". Padrão: `<input type="datetime-local">`. */
424
+ readonly renderDateTimeInput?: RenderDateTimeInput;
425
+ };
426
+ declare function PostEditor({ postId, defaults, onSaved, onArchived, onClose, showFormattingToolbar, renderDateTimeInput, }: PostEditorProps): react.JSX.Element;
427
+
428
+ declare const COVER_MAX_BYTES: number;
429
+ declare const COVER_MIME_TYPES: readonly string[];
430
+ type EditorFeedback = 'saved' | 'saveError' | 'coverTooLarge' | 'coverInvalidType' | 'coverUploadError' | 'errorSchedule';
431
+ type UploadImageResult = {
432
+ readonly url: string;
433
+ } | {
434
+ readonly error: 'coverTooLarge' | 'coverInvalidType' | 'coverUploadError';
435
+ };
436
+ declare function usePostEditor(params: {
437
+ readonly postId?: string;
438
+ readonly defaults?: Partial<PostDraft>;
439
+ readonly onSaved?: (post: Post) => void;
440
+ readonly onArchived?: (post: Post) => void;
441
+ }): {
442
+ post: Post | undefined;
443
+ draft: PostDraft;
444
+ update: <TKey extends keyof PostDraft>(field: TKey, value: PostDraft[TKey]) => void;
445
+ errors: Partial<Record<DraftErrorField, true>>;
446
+ isLoading: boolean;
447
+ isDirty: boolean;
448
+ isBusy: boolean;
449
+ isUploading: boolean;
450
+ feedback: EditorFeedback | undefined;
451
+ scheduleAt: string;
452
+ setScheduleAt: react.Dispatch<react.SetStateAction<string>>;
453
+ canUploadCover: boolean;
454
+ tagSuggestions: string[];
455
+ save: () => Promise<Post | undefined>;
456
+ publishNow: () => Promise<Post | undefined>;
457
+ schedule: () => Promise<Post | undefined>;
458
+ unpublish: () => Promise<Post | undefined>;
459
+ archive: () => Promise<void>;
460
+ uploadCover: (file: File) => Promise<void>;
461
+ uploadImage: (file: File) => Promise<UploadImageResult>;
462
+ };
463
+ type PostEditorState = ReturnType<typeof usePostEditor>;
464
+
465
+ type MarkdownEditorProps = {
466
+ readonly value: string;
467
+ readonly onChange: (value: string) => void;
468
+ readonly labelledBy: string;
469
+ readonly describedBy?: string;
470
+ readonly showToolbar?: boolean;
471
+ /** Ausente: o botão de imagem só aceita URL, sem envio de arquivo. */
472
+ readonly onUploadImage?: (file: File) => Promise<UploadImageResult>;
473
+ readonly isUploading?: boolean;
474
+ };
475
+ declare function MarkdownEditor({ value, onChange, labelledBy, describedBy, showToolbar, onUploadImage, isUploading, }: MarkdownEditorProps): react.JSX.Element;
476
+
477
+ /**
478
+ * Copyright (c) 2026 Ada Technology. MIT License.
479
+ */
480
+ type EmojiPickerProps = {
481
+ readonly onPick: (emoji: string) => void;
482
+ readonly onClose: () => void;
483
+ };
484
+ declare function EmojiPicker({ onPick, onClose }: EmojiPickerProps): react.JSX.Element;
485
+
486
+ /**
487
+ * Copyright (c) 2026 Ada Technology. MIT License.
488
+ *
489
+ * Seletor de arquivo estilizado: botão + nome do arquivo, com os textos vindos das mensagens (o
490
+ * `<input type="file">` nativo mostra o idioma do navegador e não aceita estilo).
491
+ */
492
+ type FilePickerProps = {
493
+ readonly buttonLabel: string;
494
+ readonly emptyLabel: string;
495
+ readonly accept: string;
496
+ readonly isBusy?: boolean;
497
+ readonly onPick: (file: File) => void;
346
498
  };
347
- declare function PostEditor({ postId, defaults, onSaved, onArchived, onClose }: PostEditorProps): react.JSX.Element;
499
+ declare function FilePicker({ buttonLabel, emptyLabel, accept, isBusy, onPick }: FilePickerProps): react.JSX.Element;
348
500
 
349
501
  type StatusChipProps = {
350
502
  readonly status: PostStatus;
@@ -462,37 +614,6 @@ type PaginationProps = {
462
614
  };
463
615
  declare function Pagination({ page, totalPages, getPageHref, onPageChange }: PaginationProps): react.JSX.Element | null;
464
616
 
465
- declare const COVER_MAX_BYTES: number;
466
- declare const COVER_MIME_TYPES: readonly string[];
467
- type EditorFeedback = 'saved' | 'saveError' | 'coverTooLarge' | 'coverInvalidType' | 'coverUploadError' | 'errorSchedule';
468
- declare function usePostEditor(params: {
469
- readonly postId?: string;
470
- readonly defaults?: Partial<PostDraft>;
471
- readonly onSaved?: (post: Post) => void;
472
- readonly onArchived?: (post: Post) => void;
473
- }): {
474
- post: Post | undefined;
475
- draft: PostDraft;
476
- update: <TKey extends keyof PostDraft>(field: TKey, value: PostDraft[TKey]) => void;
477
- errors: Partial<Record<DraftErrorField, true>>;
478
- isLoading: boolean;
479
- isDirty: boolean;
480
- isBusy: boolean;
481
- isUploading: boolean;
482
- feedback: EditorFeedback | undefined;
483
- scheduleAt: string;
484
- setScheduleAt: react.Dispatch<react.SetStateAction<string>>;
485
- canUploadCover: boolean;
486
- tagSuggestions: string[];
487
- save: () => Promise<Post | undefined>;
488
- publishNow: () => Promise<Post | undefined>;
489
- schedule: () => Promise<Post | undefined>;
490
- unpublish: () => Promise<Post | undefined>;
491
- archive: () => Promise<void>;
492
- uploadCover: (file: File) => Promise<void>;
493
- };
494
- type PostEditorState = ReturnType<typeof usePostEditor>;
495
-
496
617
  /**
497
618
  * Copyright (c) 2026 Ada Technology. MIT License.
498
619
  */
@@ -577,6 +698,47 @@ declare function toDateTimeLocalValue(iso: string | null | undefined): string;
577
698
  /** Valor do `datetime-local` (hora local, sem fuso) → ISO com fuso, pronto para a API. */
578
699
  declare function fromDateTimeLocalValue(value: string): string | undefined;
579
700
 
701
+ /**
702
+ * Copyright (c) 2026 Ada Technology. MIT License.
703
+ *
704
+ * Transformações puras do editor de corpo: texto + seleção entram, texto + seleção saem. O formato
705
+ * guardado continua Markdown; a barra só escreve a sintaxe por quem edita.
706
+ */
707
+ type TextSelection = {
708
+ readonly value: string;
709
+ readonly start: number;
710
+ readonly end: number;
711
+ };
712
+ type LinePrefixKind = 'heading2' | 'heading3' | 'bulletList' | 'numberedList' | 'quote';
713
+ declare function insertText(source: TextSelection, text: string): TextSelection;
714
+ /** Envolve a seleção (`**x**`); com a seleção já envolvida, desfaz. Sem seleção, usa o texto de exemplo. */
715
+ declare function toggleWrap(source: TextSelection, marker: string, placeholder: string): TextSelection;
716
+ /** Aplica o prefixo de bloco em cada linha da seleção; se todas já o têm, remove (liga e desliga). */
717
+ declare function toggleLinePrefix(source: TextSelection, kind: LinePrefixKind, placeholder: string): TextSelection;
718
+ declare function insertLink(source: TextSelection, params: {
719
+ readonly url: string;
720
+ readonly text?: string;
721
+ }): TextSelection;
722
+ declare function insertImage(source: TextSelection, params: {
723
+ readonly url: string;
724
+ readonly alt: string;
725
+ }): TextSelection;
726
+
727
+ /**
728
+ * Copyright (c) 2026 Ada Technology. MIT License.
729
+ *
730
+ * Conjunto enxuto de emojis (sem dependência): o suficiente para um post de novidades. A busca casa
731
+ * o nome em pt-BR ou en.
732
+ */
733
+ type EmojiEntry = {
734
+ readonly char: string;
735
+ readonly keywords: string;
736
+ };
737
+ type EmojiCategory = 'smileys' | 'gestures' | 'food' | 'nature' | 'travel' | 'objects' | 'symbols';
738
+ declare const EMOJI_CATEGORIES: readonly EmojiCategory[];
739
+ declare const EMOJI_BY_CATEGORY: Readonly<Record<EmojiCategory, readonly EmojiEntry[]>>;
740
+ declare function searchEmoji(query: string): readonly EmojiEntry[];
741
+
580
742
  /**
581
743
  * Copyright (c) 2026 Ada Technology. MIT License.
582
744
  */
@@ -597,4 +759,4 @@ declare function buildPageItems(params: {
597
759
  readonly siblings?: number;
598
760
  }): PageItem[];
599
761
 
600
- export { type AsyncResource, COVER_MAX_BYTES, COVER_MIME_TYPES, type ContentAdminApi, type ContentLocale, type ContentMessages, ContentProvider, type ContentProviderProps, type ContentPublicApi, type ContentText, ContentWorkspace, type ContentWorkspaceProps, DEFAULT_CONTENT_LOCALE, DRAFT_ERROR, type DraftErrorField, EMPTY_POST_DRAFT, type EditorFeedback, type ListPostsParams, type ListPublishedPostsParams, MarkdownContent, type MarkdownContentProps, type PageItem, Pagination, type PaginationProps, PostCard, type PostCardProps, type PostDraft, PostEditor, type PostEditorProps, type PostEditorState, PostList, type PostListFilters, PostListPage, type PostListPageProps, type PostListProps, type PostMeta, PostPage, type PostPageProps, type RenderLink, type RenderLinkProps, SHARE_NETWORK, SHARE_NETWORKS, ShareButtons, type ShareButtonsProps, type ShareLink, type ShareNetwork, StatusChip, type StatusChipProps, TagsInput, type TagsInputProps, buildPageItems, buildPostMeta, buildShareLinks, deriveSlug, draftFromPost, draftToInput, formatPostDate, fromDateTimeLocalValue, interpolate, isDraftDirty, resolveContentMessages, splitTagInput, toDateTimeLocalValue, useAsyncResource, useContentAdminApi, useContentPublicApi, useContentText, usePostEditor, usePostList, useRenderLink, useUnsavedChangesGuard, validateDraft };
762
+ export { type AsyncResource, COVER_MAX_BYTES, COVER_MIME_TYPES, type ContentAdminApi, type ContentLocale, type ContentMessages, ContentProvider, type ContentProviderProps, type ContentPublicApi, type ContentText, ContentWorkspace, type ContentWorkspaceProps, DEFAULT_CONTENT_LOCALE, DRAFT_ERROR, type DateTimeInputProps, type DraftErrorField, EMOJI_BY_CATEGORY, EMOJI_CATEGORIES, EMPTY_POST_DRAFT, type EditorFeedback, EmojiPicker, type EmojiPickerProps, FilePicker, type FilePickerProps, type LinePrefixKind, type ListPostsParams, type ListPublishedPostsParams, MarkdownContent, type MarkdownContentProps, MarkdownEditor, type MarkdownEditorProps, type PageItem, Pagination, type PaginationProps, PostCard, type PostCardProps, type PostDraft, PostEditor, type PostEditorProps, type PostEditorState, PostList, type PostListFilters, PostListPage, type PostListPageProps, type PostListProps, type PostMeta, PostPage, type PostPageProps, type RenderDateTimeInput, type RenderLink, type RenderLinkProps, SHARE_NETWORK, SHARE_NETWORKS, ShareButtons, type ShareButtonsProps, type ShareLink, type ShareNetwork, StatusChip, type StatusChipProps, TagsInput, type TagsInputProps, type TextSelection, type UploadImageResult, buildPageItems, buildPostMeta, buildShareLinks, deriveSlug, draftFromPost, draftToInput, formatPostDate, fromDateTimeLocalValue, insertImage, insertLink, insertText, interpolate, isDraftDirty, resolveContentMessages, searchEmoji, splitTagInput, toDateTimeLocalValue, toggleLinePrefix, toggleWrap, useAsyncResource, useContentAdminApi, useContentPublicApi, useContentText, usePostEditor, usePostList, useRenderLink, useUnsavedChangesGuard, validateDraft };