@eutobias/serenojs 0.1.2 → 0.1.4

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.
Files changed (46) hide show
  1. package/README.md +21 -6
  2. package/admin-dist/assets/index-CEMJnHOP.js +22 -0
  3. package/admin-dist/assets/index-Di8sAvwO.css +2 -0
  4. package/admin-dist/assets/marked.esm-BBttRptN.js +77 -0
  5. package/admin-dist/assets/purify.es-Bz-uQoIK.js +3 -0
  6. package/admin-dist/index.html +2 -2
  7. package/dist/config.d.ts +2 -2
  8. package/dist/core/backup.server.js +71 -4
  9. package/dist/core/db.server.js +29 -1
  10. package/dist/core/schema.js +8 -1
  11. package/dist/core/types.d.ts +15 -4
  12. package/dist/core/validation.js +61 -0
  13. package/dist/ui/admin/collection-manager.js +1 -1
  14. package/dist/ui/admin/display.js +7 -0
  15. package/dist/ui/admin/field-control.d.ts +3 -1
  16. package/dist/ui/admin/field-control.js +10 -2
  17. package/dist/ui/admin/i18n.js +26 -0
  18. package/dist/ui/admin/object-list-control.d.ts +15 -0
  19. package/dist/ui/admin/object-list-control.js +42 -0
  20. package/dist/ui/admin/rich-text-control.d.ts +15 -0
  21. package/dist/ui/admin/rich-text-control.js +62 -0
  22. package/dist/ui/admin/rich-text-icons.d.ts +8 -0
  23. package/dist/ui/admin/rich-text-icons.js +18 -0
  24. package/dist/ui/index.d.ts +1 -0
  25. package/dist/ui/index.js +1 -0
  26. package/dist/ui/markdown-preview.d.ts +10 -0
  27. package/dist/ui/markdown-preview.js +34 -0
  28. package/package.json +4 -1
  29. package/src/admin/styles.css +152 -0
  30. package/src/config.ts +2 -1
  31. package/src/core/backup.server.ts +81 -4
  32. package/src/core/db.server.ts +34 -1
  33. package/src/core/schema.ts +8 -1
  34. package/src/core/types.ts +18 -3
  35. package/src/core/validation.ts +71 -0
  36. package/src/ui/admin/collection-manager.tsx +1 -0
  37. package/src/ui/admin/display.tsx +13 -1
  38. package/src/ui/admin/field-control.tsx +43 -2
  39. package/src/ui/admin/i18n.tsx +28 -0
  40. package/src/ui/admin/object-list-control.tsx +154 -0
  41. package/src/ui/admin/rich-text-control.tsx +173 -0
  42. package/src/ui/admin/rich-text-icons.tsx +125 -0
  43. package/src/ui/index.ts +1 -0
  44. package/src/ui/markdown-preview.tsx +42 -0
  45. package/admin-dist/assets/index-D2m0Eb4k.css +0 -2
  46. package/admin-dist/assets/index-Ddgw58Iy.js +0 -9
@@ -1,6 +1,17 @@
1
1
  import { collectionLocales, fieldDefault, isLocalizedField, relationIsMany, } from "./schema.js";
2
2
  import { isMediaUrl } from "./media.js";
3
3
  const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
4
+ /** Types accepted inside an `object-list` item. */
5
+ const OBJECT_SUBFIELD_TYPES = new Set([
6
+ "text",
7
+ "email",
8
+ "textarea",
9
+ "number",
10
+ "boolean",
11
+ "select",
12
+ "date",
13
+ "list",
14
+ ]);
4
15
  function asRecord(input) {
5
16
  if (input && typeof input === "object" && !Array.isArray(input)) {
6
17
  return input;
@@ -125,6 +136,56 @@ function coerceField(field, raw) {
125
136
  }
126
137
  return { value: items };
127
138
  }
139
+ case "object-list": {
140
+ const subfields = field.fields ?? [];
141
+ if (subfields.length === 0) {
142
+ return { error: "Campo sem subcampos definidos." };
143
+ }
144
+ const source = raw === null || raw === undefined
145
+ ? []
146
+ : Array.isArray(raw)
147
+ ? raw
148
+ : null;
149
+ if (source === null) {
150
+ return { error: "Envie uma lista de itens." };
151
+ }
152
+ const items = [];
153
+ for (let index = 0; index < source.length; index += 1) {
154
+ const entry = source[index];
155
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
156
+ return { error: `Item ${index + 1}: valor inválido.` };
157
+ }
158
+ const record = entry;
159
+ const item = {};
160
+ for (const subfield of subfields) {
161
+ if (!OBJECT_SUBFIELD_TYPES.has(subfield.type)) {
162
+ return {
163
+ error: `Item ${index + 1} — ${subfield.label}: tipo de subcampo não suportado (${subfield.type}).`,
164
+ };
165
+ }
166
+ const present = Object.prototype.hasOwnProperty.call(record, subfield.name);
167
+ const result = coerceField(subfield, present ? record[subfield.name] : fieldDefault(subfield));
168
+ if ("error" in result) {
169
+ return {
170
+ error: `Item ${index + 1} — ${subfield.label}: ${result.error}`,
171
+ };
172
+ }
173
+ item[subfield.name] = result.value;
174
+ }
175
+ items.push(item);
176
+ }
177
+ if (field.required && items.length === 0) {
178
+ return { error: "Adicione ao menos um item." };
179
+ }
180
+ return { value: items };
181
+ }
182
+ case "richtext": {
183
+ const value = raw === null || raw === undefined ? "" : String(raw);
184
+ if (!value.trim() && field.required) {
185
+ return { error: "Campo obrigatório." };
186
+ }
187
+ return { value };
188
+ }
128
189
  case "email": {
129
190
  const value = raw === null || raw === undefined ? "" : String(raw).trim();
130
191
  if (!value) {
@@ -145,7 +145,7 @@ export const CollectionManager = ({ collection, initial, relationOptions, }) =>
145
145
  const fieldColumn = (field) => ({
146
146
  key: field.name,
147
147
  header: field.label,
148
- render: (row) => renderFieldValue(field, valueForLocale(collection, field, row), relationOptions[field.name] ?? []),
148
+ render: (row) => renderFieldValue(field, valueForLocale(collection, field, row), relationOptions[field.name] ?? [], locale),
149
149
  });
150
150
  const idColumn = {
151
151
  key: "id",
@@ -37,6 +37,13 @@ export function renderFieldValue(field, value, options = [], locale = "en") {
37
37
  }
38
38
  return (_jsxs(Box, { className: "flex-wrap items-center gap-1", children: [items.slice(0, 2).map((item, index) => (_jsx(Badge, { tone: "gray", children: item }, `${item}-${index}`))), items.length > 2 ? _jsxs(Badge, { tone: "gray", children: ["+", items.length - 2] }) : null] }));
39
39
  }
40
+ if (field.type === "object-list") {
41
+ const items = Array.isArray(value) ? value : [];
42
+ if (items.length === 0) {
43
+ return _jsx(Text, { as: "span", size: "caption", className: "text-gray-300", children: "\u2014" });
44
+ }
45
+ return (_jsx(Badge, { tone: "gray", children: translate(locale, "list.count", { count: items.length }) }));
46
+ }
40
47
  if (field.type === "media-list") {
41
48
  const items = Array.isArray(value) ? value : [];
42
49
  if (items.length === 0) {
@@ -6,9 +6,11 @@ export type FieldControlProps = {
6
6
  error?: string | undefined;
7
7
  disabled?: boolean | undefined;
8
8
  relationOptions?: RelationOption[] | undefined;
9
+ /** Optional prefix so nested/subfield controls get unique DOM ids. */
10
+ idPrefix?: string | undefined;
9
11
  onChange: (value: FieldValue) => void;
10
12
  };
11
13
  /**
12
14
  * Renders a single descriptor field as the right input control.
13
15
  */
14
- export declare const FieldControl: ({ field, collectionSlug, value, error, disabled, relationOptions, onChange, }: FieldControlProps) => import("react").JSX.Element;
16
+ export declare const FieldControl: ({ field, collectionSlug, value, error, disabled, relationOptions, idPrefix, onChange, }: FieldControlProps) => import("react").JSX.Element;
@@ -5,14 +5,16 @@ import { Text } from "../text.js";
5
5
  import { MediaControl } from "./media-control.js";
6
6
  import { MediaListControl } from "./media-list-control.js";
7
7
  import { ListControl } from "./list-control.js";
8
+ import { ObjectListControl } from "./object-list-control.js";
9
+ import { RichTextControl } from "./rich-text-control.js";
8
10
  import { RelationControl } from "./relation-control.js";
9
11
  import { useI18n } from "./i18n.js";
10
12
  /**
11
13
  * Renders a single descriptor field as the right input control.
12
14
  */
13
- export const FieldControl = ({ field, collectionSlug, value, error, disabled, relationOptions, onChange, }) => {
15
+ export const FieldControl = ({ field, collectionSlug, value, error, disabled, relationOptions, idPrefix, onChange, }) => {
14
16
  const { t } = useI18n();
15
- const id = `field-${field.name}`;
17
+ const id = `${idPrefix ?? ""}field-${field.name}`;
16
18
  if (field.type === "media") {
17
19
  return (_jsx(MediaControl, { field: field, collectionSlug: collectionSlug, value: typeof value === "string" ? value : "", error: error, disabled: disabled, onChange: onChange }));
18
20
  }
@@ -22,6 +24,12 @@ export const FieldControl = ({ field, collectionSlug, value, error, disabled, re
22
24
  if (field.type === "list") {
23
25
  return (_jsx(ListControl, { field: field, value: Array.isArray(value) ? value : [], error: error, disabled: disabled, onChange: onChange }));
24
26
  }
27
+ if (field.type === "richtext") {
28
+ return (_jsx(RichTextControl, { field: field, id: id, value: String(value ?? ""), error: error, disabled: disabled, onChange: onChange }));
29
+ }
30
+ if (field.type === "object-list") {
31
+ return (_jsx(ObjectListControl, { field: field, value: Array.isArray(value) ? value : [], error: error, disabled: disabled, onChange: onChange, renderField: (subfield, subvalue, onSubChange, subPrefix) => (_jsx(FieldControl, { field: subfield, collectionSlug: collectionSlug, value: subvalue, disabled: disabled, idPrefix: subPrefix, onChange: onSubChange }, subfield.name)) }));
32
+ }
25
33
  if (field.type === "relation") {
26
34
  return (_jsx(RelationControl, { field: field, value: value, options: relationOptions ?? [], error: error, disabled: disabled, onChange: onChange }));
27
35
  }
@@ -88,10 +88,23 @@ const en = {
88
88
  "relation.empty": "No items available to relate.",
89
89
  "list.empty": "No items.",
90
90
  "list.item": "Item {index}",
91
+ "list.count": "{count} item(s)",
91
92
  "list.moveUp": "Move up",
92
93
  "list.moveDown": "Move down",
93
94
  "list.remove": "Remove",
94
95
  "list.add": "Add item",
96
+ "richtext.bold": "Bold",
97
+ "richtext.header": "Header",
98
+ "richtext.italic": "Italic",
99
+ "richtext.quote": "Quote",
100
+ "richtext.link": "Link",
101
+ "richtext.unorderedList": "Bullet list",
102
+ "richtext.orderedList": "Numbered list",
103
+ "richtext.taskList": "Task list",
104
+ "richtext.write": "Write",
105
+ "richtext.preview": "Preview",
106
+ "richtext.tabs": "Editor mode",
107
+ "richtext.previewEmpty": "The preview appears as you type.",
95
108
  "pagination.range": "{from}–{to} of {total} items",
96
109
  "pagination.previous": "Previous",
97
110
  "pagination.next": "Next",
@@ -225,10 +238,23 @@ const pt = {
225
238
  "relation.empty": "Nenhum item disponível para relacionar.",
226
239
  "list.empty": "Nenhum item.",
227
240
  "list.item": "Item {index}",
241
+ "list.count": "{count} item(ns)",
228
242
  "list.moveUp": "Mover para cima",
229
243
  "list.moveDown": "Mover para baixo",
230
244
  "list.remove": "Remover",
231
245
  "list.add": "Adicionar item",
246
+ "richtext.bold": "Negrito",
247
+ "richtext.header": "Título",
248
+ "richtext.italic": "Itálico",
249
+ "richtext.quote": "Citação",
250
+ "richtext.link": "Link",
251
+ "richtext.unorderedList": "Lista com marcadores",
252
+ "richtext.orderedList": "Lista numerada",
253
+ "richtext.taskList": "Lista de tarefas",
254
+ "richtext.write": "Escrever",
255
+ "richtext.preview": "Prévia",
256
+ "richtext.tabs": "Modo do editor",
257
+ "richtext.previewEmpty": "A prévia aparece enquanto você digita.",
232
258
  "pagination.range": "{from}–{to} de {total} itens",
233
259
  "pagination.previous": "Anterior",
234
260
  "pagination.next": "Próxima",
@@ -0,0 +1,15 @@
1
+ import type { ReactNode } from "react";
2
+ import type { FieldDef, FieldValue, ObjectItem } from "../../core/types.js";
3
+ export type ObjectListControlProps = {
4
+ field: FieldDef;
5
+ value: ObjectItem[];
6
+ error?: string | undefined;
7
+ disabled?: boolean | undefined;
8
+ onChange: (value: ObjectItem[]) => void;
9
+ renderField: (field: FieldDef, value: FieldValue, onChange: (value: FieldValue) => void, idPrefix: string) => ReactNode;
10
+ };
11
+ /**
12
+ * Repeater for `object-list` fields: each item is an object rendered from its
13
+ * subfield descriptors, with add/remove/reorder controls.
14
+ */
15
+ export declare const ObjectListControl: ({ field, value, error, disabled, onChange, renderField, }: ObjectListControlProps) => import("react").JSX.Element;
@@ -0,0 +1,42 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { FiArrowDown, FiArrowUp, FiPlus, FiTrash2 } from "react-icons/fi";
4
+ import { fieldDefault } from "../../core/schema.js";
5
+ import { Box } from "../box.js";
6
+ import { Button, IconButton } from "../button.js";
7
+ import { FieldWrapper } from "../field-wrapper.js";
8
+ import { Text } from "../text.js";
9
+ import { useI18n } from "./i18n.js";
10
+ function emptyItem(field) {
11
+ const item = {};
12
+ for (const subfield of field.fields ?? []) {
13
+ item[subfield.name] = fieldDefault(subfield);
14
+ }
15
+ return item;
16
+ }
17
+ /**
18
+ * Repeater for `object-list` fields: each item is an object rendered from its
19
+ * subfield descriptors, with add/remove/reorder controls.
20
+ */
21
+ export const ObjectListControl = ({ field, value, error, disabled, onChange, renderField, }) => {
22
+ const { t } = useI18n();
23
+ const subfields = field.fields ?? [];
24
+ const update = (index, name, next) => {
25
+ onChange(value.map((item, i) => i === index ? { ...item, [name]: next } : item));
26
+ };
27
+ const remove = (index) => onChange(value.filter((_, i) => i !== index));
28
+ const move = (index, direction) => {
29
+ const target = index + direction;
30
+ if (target < 0 || target >= value.length)
31
+ return;
32
+ const next = [...value];
33
+ const current = next[index];
34
+ const swap = next[target];
35
+ if (current === undefined || swap === undefined)
36
+ return;
37
+ next[index] = swap;
38
+ next[target] = current;
39
+ onChange(next);
40
+ };
41
+ return (_jsx(FieldWrapper, { label: field.label, required: field.required, help: field.help, error: error, children: _jsxs(Box, { className: "flex-col gap-3", children: [value.length === 0 ? (_jsx(Text, { size: "caption", className: "text-gray-400", children: t("list.empty") })) : null, value.map((item, index) => (_jsxs(Box, { className: "flex-col gap-3 rounded-md border border-gray-200 bg-gray-50 p-3", children: [_jsxs(Box, { className: "items-center justify-between gap-2", children: [_jsx(Text, { size: "caption", className: "font-semibold uppercase tracking-wide text-gray-500", children: t("list.item", { index: index + 1 }) }), _jsxs(Box, { className: "items-center gap-1", children: [_jsx(IconButton, { type: "button", label: t("list.moveUp"), disabled: disabled || index === 0, onClick: () => move(index, -1), children: _jsx(FiArrowUp, { "aria-hidden": true }) }), _jsx(IconButton, { type: "button", label: t("list.moveDown"), disabled: disabled || index === value.length - 1, onClick: () => move(index, 1), children: _jsx(FiArrowDown, { "aria-hidden": true }) }), _jsx(IconButton, { type: "button", label: t("list.remove"), className: "text-red-600 hover:bg-red-50 hover:text-red-700", disabled: disabled, onClick: () => remove(index), children: _jsx(FiTrash2, { "aria-hidden": true }) })] })] }), subfields.map((subfield) => renderField(subfield, item[subfield.name] ?? null, (next) => update(index, subfield.name, next), `${field.name}-${index}-`))] }, index))), _jsxs(Button, { type: "button", variant: "secondary", size: "sm", disabled: disabled, onClick: () => onChange([...value, emptyItem(field)]), children: [_jsx(FiPlus, { "aria-hidden": true, className: "mr-1.5" }), t("list.add")] })] }) }));
42
+ };
@@ -0,0 +1,15 @@
1
+ import "@github/markdown-toolbar-element";
2
+ import type { FieldDef } from "../../core/types.js";
3
+ export type RichTextControlProps = {
4
+ field: FieldDef;
5
+ id: string;
6
+ value: string;
7
+ error?: string | undefined;
8
+ disabled?: boolean | undefined;
9
+ onChange: (value: string) => void;
10
+ };
11
+ /**
12
+ * Markdown editor with Write/Preview tabs and the GitHub markdown-toolbar
13
+ * custom elements on the right.
14
+ */
15
+ export declare const RichTextControl: ({ field, id, value, error, disabled, onChange, }: RichTextControlProps) => import("react").JSX.Element;
@@ -0,0 +1,62 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import "@github/markdown-toolbar-element";
4
+ import { createElement, useEffect, useRef, useState } from "react";
5
+ import { FieldWrapper } from "../field-wrapper.js";
6
+ import { MarkdownPreview } from "../markdown-preview.js";
7
+ import { Text } from "../text.js";
8
+ import { BoldIcon, HeaderIcon, ItalicIcon, LinkIcon, OrderedListIcon, QuoteIcon, TaskListIcon, UnorderedListIcon, } from "./rich-text-icons.js";
9
+ import { useI18n } from "./i18n.js";
10
+ const TOOLBAR_BUTTONS = [
11
+ { tag: "md-header", label: "richtext.header", icon: HeaderIcon },
12
+ { tag: "md-bold", label: "richtext.bold", icon: BoldIcon },
13
+ { tag: "md-italic", label: "richtext.italic", icon: ItalicIcon },
14
+ { tag: "md-quote", label: "richtext.quote", icon: QuoteIcon },
15
+ { tag: "md-link", label: "richtext.link", icon: LinkIcon },
16
+ {
17
+ tag: "md-unordered-list",
18
+ label: "richtext.unorderedList",
19
+ icon: UnorderedListIcon,
20
+ },
21
+ {
22
+ tag: "md-ordered-list",
23
+ label: "richtext.orderedList",
24
+ icon: OrderedListIcon,
25
+ },
26
+ { tag: "md-task-list", label: "richtext.taskList", icon: TaskListIcon },
27
+ ];
28
+ /**
29
+ * Markdown editor with Write/Preview tabs and the GitHub markdown-toolbar
30
+ * custom elements on the right.
31
+ */
32
+ export const RichTextControl = ({ field, id, value, error, disabled, onChange, }) => {
33
+ const { t } = useI18n();
34
+ const [tab, setTab] = useState("write");
35
+ const toolbarRef = useRef(null);
36
+ const textareaRef = useRef(null);
37
+ useEffect(() => {
38
+ toolbarRef.current?.setAttribute("for", id);
39
+ }, [id]);
40
+ return (_jsx(FieldWrapper, { label: field.label, htmlFor: id, required: field.required, help: field.help, error: error, children: _jsxs("div", { className: `overflow-hidden rounded-md border bg-white focus-within:border-gray-900 focus-within:ring-1 focus-within:ring-gray-900 ${error ? "border-red-400" : "border-gray-300"} ${disabled ? "pointer-events-none opacity-60" : ""}`, onClick: () => {
41
+ const element = textareaRef.current;
42
+ if (element && element.value !== value)
43
+ onChange(element.value);
44
+ }, onKeyUp: () => {
45
+ const element = textareaRef.current;
46
+ if (element && element.value !== value)
47
+ onChange(element.value);
48
+ }, children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2 border-b border-gray-200 bg-gray-50 px-2 py-1", children: [_jsx("div", { className: "flex items-center gap-1", role: "group", "aria-label": t("richtext.tabs"), children: ["write", "preview"].map((name) => {
49
+ const active = tab === name;
50
+ return (_jsx("button", { type: "button", "aria-pressed": active, onClick: () => setTab(name), className: `rounded-md px-3 py-1.5 text-xs font-medium transition-colors ${active
51
+ ? "bg-white text-gray-900 shadow-sm"
52
+ : "text-gray-500 hover:text-gray-900"}`, children: t(`richtext.${name}`) }, name));
53
+ }) }), _jsx("div", { className: `min-w-0 ${tab === "preview" ? "pointer-events-none opacity-40" : ""}`, "aria-hidden": tab === "preview", inert: tab === "preview" ? true : undefined, children: createElement("markdown-toolbar", {
54
+ ref: toolbarRef,
55
+ className: "px-1",
56
+ }, TOOLBAR_BUTTONS.map((button) => createElement(button.tag, {
57
+ key: button.tag,
58
+ role: "button",
59
+ "aria-label": t(button.label),
60
+ title: t(button.label),
61
+ }, createElement(button.icon)))) })] }), tab === "write" ? (_jsx("textarea", { ref: textareaRef, id: id, rows: 10, value: value, disabled: disabled, "aria-invalid": Boolean(error), placeholder: field.placeholder, onInput: (event) => onChange(event.currentTarget.value), className: "w-full resize-y border-0 bg-white px-3 py-2.5 font-mono text-[13px] leading-6 text-gray-900 outline-none placeholder:text-gray-400 disabled:bg-gray-50 disabled:text-gray-500" })) : (_jsxs("div", { className: "min-h-[15rem] bg-white px-4 py-3 text-sm text-gray-800", children: [_jsx(MarkdownPreview, { value: value }), value.trim() ? null : (_jsx(Text, { size: "caption", className: "text-gray-400", children: t("richtext.previewEmpty") }))] }))] }) }));
62
+ };
@@ -0,0 +1,8 @@
1
+ export declare const BoldIcon: () => import("react").JSX.Element;
2
+ export declare const HeaderIcon: () => import("react").JSX.Element;
3
+ export declare const ItalicIcon: () => import("react").JSX.Element;
4
+ export declare const QuoteIcon: () => import("react").JSX.Element;
5
+ export declare const LinkIcon: () => import("react").JSX.Element;
6
+ export declare const UnorderedListIcon: () => import("react").JSX.Element;
7
+ export declare const OrderedListIcon: () => import("react").JSX.Element;
8
+ export declare const TaskListIcon: () => import("react").JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ const SCALE = 256 / 24;
3
+ /**
4
+ * Every icon is authored in a 24x24 coordinate grid (4px padding, artwork in
5
+ * 4..20), then scaled into a 256x256 SVG. CSS renders the toolbar icon at the
6
+ * same 24px size as before.
7
+ */
8
+ function Icon({ children }) {
9
+ return (_jsx("svg", { width: 256, height: 256, viewBox: "0 0 256 256", fill: "none", stroke: "currentColor", strokeWidth: 1.6, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("g", { transform: `scale(${SCALE})`, children: children }) }));
10
+ }
11
+ export const BoldIcon = () => (_jsxs(Icon, { children: [_jsx("path", { d: "M7 5h5.4a3.3 3.3 0 0 1 0 6.6H7z" }), _jsx("path", { d: "M7 11.6h6.2a3.7 3.7 0 0 1 0 7.4H7z" })] }));
12
+ export const HeaderIcon = () => (_jsxs(Icon, { children: [_jsx("path", { d: "M5 5v12M12 5v12M5 11h7" }), _jsx("text", { x: "13.2", y: "18.5", fill: "currentColor", stroke: "none", fontSize: "6.5", fontWeight: "700", fontFamily: "ui-sans-serif, system-ui, sans-serif", children: "3" })] }));
13
+ export const ItalicIcon = () => (_jsx(Icon, { children: _jsx("path", { d: "M10 5h7M7 19h7M13.5 5l-3 14" }) }));
14
+ export const QuoteIcon = () => (_jsx(Icon, { children: _jsx("path", { d: "M6 7h5v5H8l-2 4zM13 7h5v5h-3l-2 4z" }) }));
15
+ export const LinkIcon = () => (_jsxs(Icon, { children: [_jsx("path", { d: "M10.5 13.5a3.5 3.5 0 0 0 5 0l2-2a3.5 3.5 0 0 0-5-5l-1 1" }), _jsx("path", { d: "M13.5 10.5a3.5 3.5 0 0 0-5 0l-2 2a3.5 3.5 0 0 0 5 5l1-1" })] }));
16
+ export const UnorderedListIcon = () => (_jsxs(Icon, { children: [_jsx("circle", { cx: "6", cy: "7", r: "1", fill: "currentColor", stroke: "none" }), _jsx("circle", { cx: "6", cy: "12", r: "1", fill: "currentColor", stroke: "none" }), _jsx("circle", { cx: "6", cy: "17", r: "1", fill: "currentColor", stroke: "none" }), _jsx("path", { d: "M10 7h8M10 12h8M10 17h8" })] }));
17
+ export const OrderedListIcon = () => (_jsxs(Icon, { children: [_jsx("path", { d: "M10 7h8M10 12h8M10 17h8" }), _jsx("text", { x: "5", y: "9", fill: "currentColor", stroke: "none", fontSize: "5", fontFamily: "ui-monospace, monospace", children: "1" }), _jsx("text", { x: "5", y: "14", fill: "currentColor", stroke: "none", fontSize: "5", fontFamily: "ui-monospace, monospace", children: "2" }), _jsx("text", { x: "5", y: "19", fill: "currentColor", stroke: "none", fontSize: "5", fontFamily: "ui-monospace, monospace", children: "3" })] }));
18
+ export const TaskListIcon = () => (_jsxs(Icon, { children: [_jsx("rect", { x: "5", y: "5.5", width: "4", height: "4", rx: "1" }), _jsx("path", { d: "M6 7.5l1 1 2-2M11.5 7.5h7" }), _jsx("rect", { x: "5", y: "10.5", width: "4", height: "4", rx: "1" }), _jsx("path", { d: "M11.5 12.5h7" }), _jsx("rect", { x: "5", y: "15.5", width: "4", height: "4", rx: "1" }), _jsx("path", { d: "M11.5 17.5h7" })] }));
@@ -5,4 +5,5 @@ export { Card } from "./card.js";
5
5
  export { Container } from "./container.js";
6
6
  export { Drawer } from "./drawer.js";
7
7
  export { FieldWrapper, inputClass } from "./field-wrapper.js";
8
+ export { MarkdownPreview } from "./markdown-preview.js";
8
9
  export { Text } from "./text.js";
package/dist/ui/index.js CHANGED
@@ -5,4 +5,5 @@ export { Card } from "./card.js";
5
5
  export { Container } from "./container.js";
6
6
  export { Drawer } from "./drawer.js";
7
7
  export { FieldWrapper, inputClass } from "./field-wrapper.js";
8
+ export { MarkdownPreview } from "./markdown-preview.js";
8
9
  export { Text } from "./text.js";
@@ -0,0 +1,10 @@
1
+ export type MarkdownPreviewProps = {
2
+ value: string;
3
+ className?: string;
4
+ };
5
+ /**
6
+ * Client-only Markdown preview. `marked` and `dompurify` are loaded lazily so
7
+ * server rendering never touches the DOM, and the generated HTML is sanitized
8
+ * before it reaches the page.
9
+ */
10
+ export declare const MarkdownPreview: ({ value, className, }: MarkdownPreviewProps) => import("react").JSX.Element;
@@ -0,0 +1,34 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useDeferredValue, useEffect, useState } from "react";
4
+ /**
5
+ * Client-only Markdown preview. `marked` and `dompurify` are loaded lazily so
6
+ * server rendering never touches the DOM, and the generated HTML is sanitized
7
+ * before it reaches the page.
8
+ */
9
+ export const MarkdownPreview = ({ value, className = "serenojs-markdown", }) => {
10
+ const [html, setHtml] = useState("");
11
+ const deferredValue = useDeferredValue(value);
12
+ useEffect(() => {
13
+ let cancelled = false;
14
+ void (async () => {
15
+ try {
16
+ const [{ marked }, { default: DOMPurify }] = await Promise.all([
17
+ import("marked"),
18
+ import("dompurify"),
19
+ ]);
20
+ const raw = await marked.parse(deferredValue);
21
+ if (!cancelled)
22
+ setHtml(DOMPurify.sanitize(raw));
23
+ }
24
+ catch {
25
+ if (!cancelled)
26
+ setHtml("");
27
+ }
28
+ })();
29
+ return () => {
30
+ cancelled = true;
31
+ };
32
+ }, [deferredValue]);
33
+ return _jsx("div", { className: className, dangerouslySetInnerHTML: { __html: html } });
34
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eutobias/serenojs",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "SerenoJS — schema-driven CMS for Waku: auto-generated admin SPA + Hono REST API.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -69,7 +69,10 @@
69
69
  "waku": "1.0.0-rc.1"
70
70
  },
71
71
  "dependencies": {
72
+ "@github/markdown-toolbar-element": "^2.2.3",
73
+ "dompurify": "^3.5.1",
72
74
  "hono": "^4.12.14",
75
+ "marked": "^18.4.0",
73
76
  "react-icons": "^5.7.0"
74
77
  },
75
78
  "publishConfig": {
@@ -7,3 +7,155 @@
7
7
  --font-sans: ui-sans-serif, system-ui, -apple-system, sans-serif;
8
8
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
9
9
  }
10
+
11
+ /* Rich text toolbar */
12
+
13
+ markdown-toolbar {
14
+ display: flex;
15
+ flex-wrap: wrap;
16
+ gap: 2px;
17
+ }
18
+
19
+ markdown-toolbar md-bold,
20
+ markdown-toolbar md-header,
21
+ markdown-toolbar md-italic,
22
+ markdown-toolbar md-quote,
23
+ markdown-toolbar md-link,
24
+ markdown-toolbar md-unordered-list,
25
+ markdown-toolbar md-ordered-list,
26
+ markdown-toolbar md-task-list {
27
+ display: inline-flex;
28
+ align-items: center;
29
+ padding: 2px;
30
+ border-radius: 6px;
31
+ color: #4b5563;
32
+ line-height: 0;
33
+ cursor: pointer;
34
+ user-select: none;
35
+ }
36
+
37
+ markdown-toolbar md-bold svg,
38
+ markdown-toolbar md-header svg,
39
+ markdown-toolbar md-italic svg,
40
+ markdown-toolbar md-quote svg,
41
+ markdown-toolbar md-link svg,
42
+ markdown-toolbar md-unordered-list svg,
43
+ markdown-toolbar md-ordered-list svg,
44
+ markdown-toolbar md-task-list svg {
45
+ display: block;
46
+ width: 24px;
47
+ height: 24px;
48
+ }
49
+
50
+ markdown-toolbar md-bold:hover,
51
+ markdown-toolbar md-header:hover,
52
+ markdown-toolbar md-italic:hover,
53
+ markdown-toolbar md-quote:hover,
54
+ markdown-toolbar md-link:hover,
55
+ markdown-toolbar md-unordered-list:hover,
56
+ markdown-toolbar md-ordered-list:hover,
57
+ markdown-toolbar md-task-list:hover,
58
+ markdown-toolbar md-bold:focus-visible,
59
+ markdown-toolbar md-header:focus-visible,
60
+ markdown-toolbar md-italic:focus-visible,
61
+ markdown-toolbar md-quote:focus-visible,
62
+ markdown-toolbar md-link:focus-visible,
63
+ markdown-toolbar md-unordered-list:focus-visible,
64
+ markdown-toolbar md-ordered-list:focus-visible,
65
+ markdown-toolbar md-task-list:focus-visible {
66
+ background: #e5e7eb;
67
+ color: #111827;
68
+ }
69
+
70
+ markdown-toolbar md-bold:focus-visible,
71
+ markdown-toolbar md-header:focus-visible,
72
+ markdown-toolbar md-italic:focus-visible,
73
+ markdown-toolbar md-quote:focus-visible,
74
+ markdown-toolbar md-link:focus-visible,
75
+ markdown-toolbar md-unordered-list:focus-visible,
76
+ markdown-toolbar md-ordered-list:focus-visible,
77
+ markdown-toolbar md-task-list:focus-visible {
78
+ outline: 2px solid #6b7280;
79
+ outline-offset: 1px;
80
+ }
81
+
82
+ /* Markdown preview */
83
+
84
+ .serenojs-markdown {
85
+ line-height: 1.6;
86
+ overflow-wrap: anywhere;
87
+ }
88
+
89
+ .serenojs-markdown > :first-child {
90
+ margin-top: 0;
91
+ }
92
+
93
+ .serenojs-markdown > :last-child {
94
+ margin-bottom: 0;
95
+ }
96
+
97
+ .serenojs-markdown h1,
98
+ .serenojs-markdown h2,
99
+ .serenojs-markdown h3 {
100
+ margin: 0.9em 0 0.35em;
101
+ font-weight: 650;
102
+ line-height: 1.25;
103
+ }
104
+
105
+ .serenojs-markdown h1 {
106
+ font-size: 1.35em;
107
+ }
108
+
109
+ .serenojs-markdown h2 {
110
+ font-size: 1.2em;
111
+ }
112
+
113
+ .serenojs-markdown h3 {
114
+ font-size: 1.05em;
115
+ }
116
+
117
+ .serenojs-markdown p,
118
+ .serenojs-markdown ul,
119
+ .serenojs-markdown ol,
120
+ .serenojs-markdown blockquote,
121
+ .serenojs-markdown pre {
122
+ margin: 0.55em 0;
123
+ }
124
+
125
+ .serenojs-markdown ul,
126
+ .serenojs-markdown ol {
127
+ padding-left: 1.35em;
128
+ }
129
+
130
+ .serenojs-markdown blockquote {
131
+ padding-left: 0.9em;
132
+ border-left: 3px solid #d1d5db;
133
+ color: #4b5563;
134
+ }
135
+
136
+ .serenojs-markdown code {
137
+ padding: 0.1em 0.3em;
138
+ border-radius: 4px;
139
+ background: #f3f4f6;
140
+ font-family: var(--font-mono);
141
+ font-size: 0.9em;
142
+ }
143
+
144
+ .serenojs-markdown pre {
145
+ overflow-x: auto;
146
+ padding: 0.8em;
147
+ border-radius: 6px;
148
+ background: #111827;
149
+ color: #f9fafb;
150
+ }
151
+
152
+ .serenojs-markdown pre code {
153
+ padding: 0;
154
+ background: transparent;
155
+ color: inherit;
156
+ }
157
+
158
+ .serenojs-markdown a {
159
+ color: #047857;
160
+ text-decoration: underline;
161
+ }
package/src/config.ts CHANGED
@@ -14,10 +14,11 @@ import type {
14
14
  Item,
15
15
  ListResult,
16
16
  MediaItem,
17
+ ObjectItem,
17
18
  RelationOptionsMap,
18
19
  } from "./core/types.js";
19
20
 
20
- export type { CollectionDef, CollectionIconName, FieldDef, FieldValue, Item, ListResult, MediaItem, RelationOptionsMap };
21
+ export type { CollectionDef, CollectionIconName, FieldDef, FieldValue, Item, ListResult, MediaItem, ObjectItem, RelationOptionsMap };
21
22
 
22
23
  /** A locale known to the admin UI. */
23
24
  export type LocaleDef = {