@eutobias/serenojs 0.1.1 → 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.
- package/README.md +30 -11
- package/admin-dist/assets/index-CEMJnHOP.js +22 -0
- package/admin-dist/assets/index-Di8sAvwO.css +2 -0
- package/admin-dist/assets/marked.esm-BBttRptN.js +77 -0
- package/admin-dist/assets/purify.es-Bz-uQoIK.js +3 -0
- package/admin-dist/index.html +2 -2
- package/dist/config.d.ts +9 -2
- package/dist/config.js +1 -0
- package/dist/core/backup.server.d.ts +5 -2
- package/dist/core/backup.server.js +346 -12
- package/dist/core/db.server.js +29 -1
- package/dist/core/schema-codegen.server.d.ts +17 -0
- package/dist/core/schema-codegen.server.js +155 -0
- package/dist/core/schema.js +8 -1
- package/dist/core/types.d.ts +15 -4
- package/dist/core/validation.js +61 -0
- package/dist/ui/admin/collection-manager.js +1 -1
- package/dist/ui/admin/display.js +7 -0
- package/dist/ui/admin/field-control.d.ts +3 -1
- package/dist/ui/admin/field-control.js +10 -2
- package/dist/ui/admin/i18n.js +30 -4
- package/dist/ui/admin/object-list-control.d.ts +15 -0
- package/dist/ui/admin/object-list-control.js +42 -0
- package/dist/ui/admin/rich-text-control.d.ts +15 -0
- package/dist/ui/admin/rich-text-control.js +62 -0
- package/dist/ui/admin/rich-text-icons.d.ts +8 -0
- package/dist/ui/admin/rich-text-icons.js +18 -0
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.js +1 -0
- package/dist/ui/markdown-preview.d.ts +10 -0
- package/dist/ui/markdown-preview.js +34 -0
- package/package.json +4 -1
- package/src/admin/styles.css +152 -0
- package/src/config.ts +6 -1
- package/src/core/backup.server.ts +435 -17
- package/src/core/db.server.ts +34 -1
- package/src/core/schema-codegen.server.ts +187 -0
- package/src/core/schema.ts +8 -1
- package/src/core/types.ts +18 -3
- package/src/core/validation.ts +71 -0
- package/src/ui/admin/collection-manager.tsx +1 -0
- package/src/ui/admin/display.tsx +13 -1
- package/src/ui/admin/field-control.tsx +43 -2
- package/src/ui/admin/i18n.tsx +32 -4
- package/src/ui/admin/object-list-control.tsx +154 -0
- package/src/ui/admin/rich-text-control.tsx +173 -0
- package/src/ui/admin/rich-text-icons.tsx +125 -0
- package/src/ui/index.ts +1 -0
- package/src/ui/markdown-preview.tsx +42 -0
- package/admin-dist/assets/index-B3EgqtT6.js +0 -9
- package/admin-dist/assets/index-D2m0Eb4k.css +0 -2
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema source-code generation used by the backup restore routine.
|
|
3
|
+
*
|
|
4
|
+
* The collection descriptors in `src/schemas` are the source of truth for the
|
|
5
|
+
* whole CMS, so a backup stores them and restore writes them back as TypeScript
|
|
6
|
+
* modules. Server-only: uses the filesystem.
|
|
7
|
+
*/
|
|
8
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
|
|
11
|
+
import type { LocaleDef } from "../config.js";
|
|
12
|
+
import type { CollectionDef } from "./types.js";
|
|
13
|
+
|
|
14
|
+
export type BackupSchemas = {
|
|
15
|
+
title: string;
|
|
16
|
+
defaultLocale: string;
|
|
17
|
+
locales: LocaleDef[];
|
|
18
|
+
collections: CollectionDef[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type SchemaWriteResult = {
|
|
22
|
+
files: number;
|
|
23
|
+
collections: number;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const RESERVED_IDENTIFIERS = new Set([
|
|
27
|
+
"break",
|
|
28
|
+
"case",
|
|
29
|
+
"catch",
|
|
30
|
+
"class",
|
|
31
|
+
"const",
|
|
32
|
+
"continue",
|
|
33
|
+
"debugger",
|
|
34
|
+
"default",
|
|
35
|
+
"delete",
|
|
36
|
+
"do",
|
|
37
|
+
"else",
|
|
38
|
+
"enum",
|
|
39
|
+
"export",
|
|
40
|
+
"extends",
|
|
41
|
+
"false",
|
|
42
|
+
"finally",
|
|
43
|
+
"for",
|
|
44
|
+
"function",
|
|
45
|
+
"if",
|
|
46
|
+
"implements",
|
|
47
|
+
"import",
|
|
48
|
+
"in",
|
|
49
|
+
"instanceof",
|
|
50
|
+
"interface",
|
|
51
|
+
"let",
|
|
52
|
+
"new",
|
|
53
|
+
"null",
|
|
54
|
+
"package",
|
|
55
|
+
"private",
|
|
56
|
+
"protected",
|
|
57
|
+
"public",
|
|
58
|
+
"return",
|
|
59
|
+
"static",
|
|
60
|
+
"super",
|
|
61
|
+
"switch",
|
|
62
|
+
"this",
|
|
63
|
+
"throw",
|
|
64
|
+
"true",
|
|
65
|
+
"try",
|
|
66
|
+
"typeof",
|
|
67
|
+
"var",
|
|
68
|
+
"void",
|
|
69
|
+
"while",
|
|
70
|
+
"with",
|
|
71
|
+
"yield",
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
function identifier(raw: string, fallback: string): string {
|
|
75
|
+
let value = raw.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
76
|
+
if (!value) value = fallback;
|
|
77
|
+
if (/^[0-9]/.test(value)) value = `_${value}`;
|
|
78
|
+
if (RESERVED_IDENTIFIERS.has(value)) value = `${value}_`;
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function fileBase(raw: string): string {
|
|
83
|
+
const value = raw.replace(/[^a-zA-Z0-9_-]/g, "_").replace(/^[-_]+/, "");
|
|
84
|
+
return value || "collection";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function literal(value: unknown): string {
|
|
88
|
+
return JSON.stringify(value, null, 2) ?? "null";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function collectionModule(exportName: string, collection: CollectionDef): string {
|
|
92
|
+
return [
|
|
93
|
+
`import type { CollectionDef } from "@eutobias/serenojs/config";`,
|
|
94
|
+
"",
|
|
95
|
+
`export const ${exportName}: CollectionDef = ${literal(collection)};`,
|
|
96
|
+
"",
|
|
97
|
+
].join("\n");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function localesModule(schemas: BackupSchemas): string {
|
|
101
|
+
return [
|
|
102
|
+
`/** Locale registry restored from a SerenoJS backup. */`,
|
|
103
|
+
"",
|
|
104
|
+
`export type LocaleDef = {`,
|
|
105
|
+
` code: string;`,
|
|
106
|
+
` label: string;`,
|
|
107
|
+
`};`,
|
|
108
|
+
"",
|
|
109
|
+
`export const locales: LocaleDef[] = ${literal(schemas.locales)};`,
|
|
110
|
+
"",
|
|
111
|
+
`/** Locale used as fallback and for the seed of legacy single-column data. */`,
|
|
112
|
+
`export const defaultLocale = ${literal(schemas.defaultLocale)};`,
|
|
113
|
+
"",
|
|
114
|
+
`/** Display label for a locale code (falls back to the uppercased code). */`,
|
|
115
|
+
`export function localeLabel(code: string): string {`,
|
|
116
|
+
` return (`,
|
|
117
|
+
` locales.find((locale) => locale.code === code)?.label ?? code.toUpperCase()`,
|
|
118
|
+
` );`,
|
|
119
|
+
`}`,
|
|
120
|
+
"",
|
|
121
|
+
].join("\n");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function indexModule(
|
|
125
|
+
schemas: BackupSchemas,
|
|
126
|
+
entries: { base: string; exportName: string }[],
|
|
127
|
+
): string {
|
|
128
|
+
const imports = entries
|
|
129
|
+
.map(({ base, exportName }) => `import { ${exportName} } from "./${base}";`)
|
|
130
|
+
.join("\n");
|
|
131
|
+
const values = entries.map(({ exportName }) => exportName).join(", ");
|
|
132
|
+
|
|
133
|
+
return [
|
|
134
|
+
`import type { CollectionDef } from "@eutobias/serenojs/config";`,
|
|
135
|
+
"",
|
|
136
|
+
imports,
|
|
137
|
+
"",
|
|
138
|
+
`export { defaultLocale, localeLabel, locales } from "./locales";`,
|
|
139
|
+
`export type { LocaleDef } from "./locales";`,
|
|
140
|
+
"",
|
|
141
|
+
`/** Title shown across the admin panel. */`,
|
|
142
|
+
`export const schemaTitle = ${literal(schemas.title)};`,
|
|
143
|
+
"",
|
|
144
|
+
`/** Every collection available in the admin/API. */`,
|
|
145
|
+
`export const collections: CollectionDef[] = [${values}];`,
|
|
146
|
+
"",
|
|
147
|
+
].join("\n");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Write the backup schemas into `dir` as the conventional starter layout:
|
|
152
|
+
* `index.ts`, `locales.ts` and one module per collection.
|
|
153
|
+
*/
|
|
154
|
+
export function writeSchemaFiles(
|
|
155
|
+
dir: string,
|
|
156
|
+
schemas: BackupSchemas,
|
|
157
|
+
): SchemaWriteResult {
|
|
158
|
+
mkdirSync(dir, { recursive: true });
|
|
159
|
+
|
|
160
|
+
const usedFiles = new Set<string>(["index", "locales"]);
|
|
161
|
+
const usedExports = new Set<string>();
|
|
162
|
+
const entries: { base: string; exportName: string }[] = [];
|
|
163
|
+
|
|
164
|
+
for (const collection of schemas.collections) {
|
|
165
|
+
const rawBase = fileBase(collection.slug);
|
|
166
|
+
let base = rawBase;
|
|
167
|
+
let suffix = 2;
|
|
168
|
+
while (usedFiles.has(base)) base = `${rawBase}_${suffix++}`;
|
|
169
|
+
usedFiles.add(base);
|
|
170
|
+
|
|
171
|
+
const rawExport = identifier(collection.slug, "collection");
|
|
172
|
+
let exportName = rawExport;
|
|
173
|
+
suffix = 2;
|
|
174
|
+
while (usedExports.has(exportName)) {
|
|
175
|
+
exportName = `${rawExport}_${suffix++}`;
|
|
176
|
+
}
|
|
177
|
+
usedExports.add(exportName);
|
|
178
|
+
|
|
179
|
+
writeFileSync(join(dir, `${base}.ts`), collectionModule(exportName, collection), "utf8");
|
|
180
|
+
entries.push({ base, exportName });
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
writeFileSync(join(dir, "locales.ts"), localesModule(schemas), "utf8");
|
|
184
|
+
writeFileSync(join(dir, "index.ts"), indexModule(schemas, entries), "utf8");
|
|
185
|
+
|
|
186
|
+
return { files: entries.length + 2, collections: entries.length };
|
|
187
|
+
}
|
package/src/core/schema.ts
CHANGED
|
@@ -8,7 +8,13 @@ import {
|
|
|
8
8
|
import type { CollectionDef, FieldDef, FieldValue, LocalizedValue } from "./types.js";
|
|
9
9
|
|
|
10
10
|
/** Field types that are localized by default. */
|
|
11
|
-
const LOCALIZED_TYPES = new Set([
|
|
11
|
+
const LOCALIZED_TYPES = new Set([
|
|
12
|
+
"text",
|
|
13
|
+
"textarea",
|
|
14
|
+
"richtext",
|
|
15
|
+
"email",
|
|
16
|
+
"list",
|
|
17
|
+
]);
|
|
12
18
|
|
|
13
19
|
/** Locales stored by a collection (falls back to the global default). */
|
|
14
20
|
export function collectionLocales(collection: CollectionDef): string[] {
|
|
@@ -92,6 +98,7 @@ export function fieldDefault(field: FieldDef): FieldValue {
|
|
|
92
98
|
case "media-list":
|
|
93
99
|
return [];
|
|
94
100
|
case "list":
|
|
101
|
+
case "object-list":
|
|
95
102
|
return [];
|
|
96
103
|
case "select":
|
|
97
104
|
return field.options?.[0]?.value ?? "";
|
package/src/core/types.ts
CHANGED
|
@@ -24,6 +24,7 @@ export type FieldType =
|
|
|
24
24
|
| "text"
|
|
25
25
|
| "email"
|
|
26
26
|
| "textarea"
|
|
27
|
+
| "richtext"
|
|
27
28
|
| "number"
|
|
28
29
|
| "boolean"
|
|
29
30
|
| "select"
|
|
@@ -31,7 +32,8 @@ export type FieldType =
|
|
|
31
32
|
| "relation"
|
|
32
33
|
| "media"
|
|
33
34
|
| "media-list"
|
|
34
|
-
| "list"
|
|
35
|
+
| "list"
|
|
36
|
+
| "object-list";
|
|
35
37
|
|
|
36
38
|
export type SelectOption = {
|
|
37
39
|
label: string;
|
|
@@ -72,11 +74,18 @@ export type FieldDef = {
|
|
|
72
74
|
accept?: string[];
|
|
73
75
|
/** Only for `media` fields. Maximum upload size in bytes. */
|
|
74
76
|
maxSize?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Only for `object-list` fields. Subfields of each stored object. Supported
|
|
79
|
+
* types: `text`, `email`, `textarea`, `number`, `boolean`, `select`,
|
|
80
|
+
* `date` and `list`. Subfields are never localized individually.
|
|
81
|
+
*/
|
|
82
|
+
fields?: FieldDef[];
|
|
75
83
|
/**
|
|
76
84
|
* Whether the field is stored per locale (`name_pt`, `name_en`). When
|
|
77
85
|
* omitted it defaults to `true` for editorial types (`text`, `textarea`,
|
|
78
|
-
* `email`, `list`) and `false` for structural ones. Set
|
|
79
|
-
* a text field (e.g. `slug`, `icon`) to stay
|
|
86
|
+
* `richtext`, `email`, `list`) and `false` for structural ones. Set
|
|
87
|
+
* explicitly to force a text field (e.g. `slug`, `icon`) to stay
|
|
88
|
+
* language-independent.
|
|
80
89
|
*/
|
|
81
90
|
localized?: boolean;
|
|
82
91
|
defaultValue?: string | number | boolean;
|
|
@@ -147,6 +156,11 @@ export type MediaItem = {
|
|
|
147
156
|
primary?: boolean;
|
|
148
157
|
};
|
|
149
158
|
|
|
159
|
+
/** A single entry of an `object-list` field, keyed by subfield name. */
|
|
160
|
+
export type ObjectItem = {
|
|
161
|
+
[field: string]: FieldValue;
|
|
162
|
+
};
|
|
163
|
+
|
|
150
164
|
/** An ordered list of translated values, keyed by locale code. */
|
|
151
165
|
export type LocalizedValue = {
|
|
152
166
|
[locale: string]: FieldValue;
|
|
@@ -161,6 +175,7 @@ export type FieldValue =
|
|
|
161
175
|
| number[]
|
|
162
176
|
| string[]
|
|
163
177
|
| MediaItem[]
|
|
178
|
+
| ObjectItem[]
|
|
164
179
|
| LocalizedValue;
|
|
165
180
|
|
|
166
181
|
/** An option shown by a relation control and used to render labels. */
|
package/src/core/validation.ts
CHANGED
|
@@ -8,9 +8,11 @@ import { isMediaUrl } from "./media.js";
|
|
|
8
8
|
import type {
|
|
9
9
|
CollectionDef,
|
|
10
10
|
FieldDef,
|
|
11
|
+
FieldType,
|
|
11
12
|
FieldValue,
|
|
12
13
|
LocalizedValue,
|
|
13
14
|
MediaItem,
|
|
15
|
+
ObjectItem,
|
|
14
16
|
} from "./types.js";
|
|
15
17
|
|
|
16
18
|
export type ValidationResult = {
|
|
@@ -21,6 +23,18 @@ export type ValidationResult = {
|
|
|
21
23
|
|
|
22
24
|
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
23
25
|
|
|
26
|
+
/** Types accepted inside an `object-list` item. */
|
|
27
|
+
const OBJECT_SUBFIELD_TYPES = new Set<FieldType>([
|
|
28
|
+
"text",
|
|
29
|
+
"email",
|
|
30
|
+
"textarea",
|
|
31
|
+
"number",
|
|
32
|
+
"boolean",
|
|
33
|
+
"select",
|
|
34
|
+
"date",
|
|
35
|
+
"list",
|
|
36
|
+
]);
|
|
37
|
+
|
|
24
38
|
function asRecord(input: unknown): Record<string, unknown> {
|
|
25
39
|
if (input && typeof input === "object" && !Array.isArray(input)) {
|
|
26
40
|
return input as Record<string, unknown>;
|
|
@@ -146,6 +160,63 @@ function coerceField(
|
|
|
146
160
|
}
|
|
147
161
|
return { value: items };
|
|
148
162
|
}
|
|
163
|
+
case "object-list": {
|
|
164
|
+
const subfields = field.fields ?? [];
|
|
165
|
+
if (subfields.length === 0) {
|
|
166
|
+
return { error: "Campo sem subcampos definidos." };
|
|
167
|
+
}
|
|
168
|
+
const source =
|
|
169
|
+
raw === null || raw === undefined
|
|
170
|
+
? []
|
|
171
|
+
: Array.isArray(raw)
|
|
172
|
+
? raw
|
|
173
|
+
: null;
|
|
174
|
+
if (source === null) {
|
|
175
|
+
return { error: "Envie uma lista de itens." };
|
|
176
|
+
}
|
|
177
|
+
const items: ObjectItem[] = [];
|
|
178
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
179
|
+
const entry = source[index];
|
|
180
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
181
|
+
return { error: `Item ${index + 1}: valor inválido.` };
|
|
182
|
+
}
|
|
183
|
+
const record = entry as Record<string, unknown>;
|
|
184
|
+
const item: ObjectItem = {};
|
|
185
|
+
for (const subfield of subfields) {
|
|
186
|
+
if (!OBJECT_SUBFIELD_TYPES.has(subfield.type)) {
|
|
187
|
+
return {
|
|
188
|
+
error: `Item ${index + 1} — ${subfield.label}: tipo de subcampo não suportado (${subfield.type}).`,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const present = Object.prototype.hasOwnProperty.call(
|
|
192
|
+
record,
|
|
193
|
+
subfield.name,
|
|
194
|
+
);
|
|
195
|
+
const result = coerceField(
|
|
196
|
+
subfield,
|
|
197
|
+
present ? record[subfield.name] : fieldDefault(subfield),
|
|
198
|
+
);
|
|
199
|
+
if ("error" in result) {
|
|
200
|
+
return {
|
|
201
|
+
error: `Item ${index + 1} — ${subfield.label}: ${result.error}`,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
item[subfield.name] = result.value;
|
|
205
|
+
}
|
|
206
|
+
items.push(item);
|
|
207
|
+
}
|
|
208
|
+
if (field.required && items.length === 0) {
|
|
209
|
+
return { error: "Adicione ao menos um item." };
|
|
210
|
+
}
|
|
211
|
+
return { value: items };
|
|
212
|
+
}
|
|
213
|
+
case "richtext": {
|
|
214
|
+
const value = raw === null || raw === undefined ? "" : String(raw);
|
|
215
|
+
if (!value.trim() && field.required) {
|
|
216
|
+
return { error: "Campo obrigatório." };
|
|
217
|
+
}
|
|
218
|
+
return { value };
|
|
219
|
+
}
|
|
149
220
|
case "email": {
|
|
150
221
|
const value = raw === null || raw === undefined ? "" : String(raw).trim();
|
|
151
222
|
if (!value) {
|
package/src/ui/admin/display.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import type { ReactNode } from "react";
|
|
|
2
2
|
|
|
3
3
|
import { relationIsMany } from "../../core/schema.js";
|
|
4
4
|
import { isImageUrl } from "../../core/media.js";
|
|
5
|
-
import type { FieldDef, FieldValue, MediaItem, RelationOption } from "../../core/types.js";
|
|
5
|
+
import type { FieldDef, FieldValue, MediaItem, ObjectItem, RelationOption } from "../../core/types.js";
|
|
6
6
|
import { Badge } from "../badge.js";
|
|
7
7
|
import { Box } from "../box.js";
|
|
8
8
|
import { Text } from "../text.js";
|
|
@@ -75,6 +75,18 @@ export function renderFieldValue(
|
|
|
75
75
|
);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
if (field.type === "object-list") {
|
|
79
|
+
const items = Array.isArray(value) ? (value as ObjectItem[]) : [];
|
|
80
|
+
if (items.length === 0) {
|
|
81
|
+
return <Text as="span" size="caption" className="text-gray-300">—</Text>;
|
|
82
|
+
}
|
|
83
|
+
return (
|
|
84
|
+
<Badge tone="gray">
|
|
85
|
+
{translate(locale, "list.count", { count: items.length })}
|
|
86
|
+
</Badge>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
78
90
|
if (field.type === "media-list") {
|
|
79
91
|
const items = Array.isArray(value) ? (value as MediaItem[]) : [];
|
|
80
92
|
if (items.length === 0) {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { FieldDef, FieldValue, MediaItem, RelationOption } from "../../core/types.js";
|
|
1
|
+
import type { FieldDef, FieldValue, MediaItem, ObjectItem, RelationOption } from "../../core/types.js";
|
|
2
2
|
import { Box } from "../box.js";
|
|
3
3
|
import { FieldWrapper, inputClass } from "../field-wrapper.js";
|
|
4
4
|
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
|
|
|
@@ -15,6 +17,8 @@ export type FieldControlProps = {
|
|
|
15
17
|
error?: string | undefined;
|
|
16
18
|
disabled?: boolean | undefined;
|
|
17
19
|
relationOptions?: RelationOption[] | undefined;
|
|
20
|
+
/** Optional prefix so nested/subfield controls get unique DOM ids. */
|
|
21
|
+
idPrefix?: string | undefined;
|
|
18
22
|
onChange: (value: FieldValue) => void;
|
|
19
23
|
};
|
|
20
24
|
|
|
@@ -28,10 +32,11 @@ export const FieldControl = ({
|
|
|
28
32
|
error,
|
|
29
33
|
disabled,
|
|
30
34
|
relationOptions,
|
|
35
|
+
idPrefix,
|
|
31
36
|
onChange,
|
|
32
37
|
}: FieldControlProps) => {
|
|
33
38
|
const { t } = useI18n();
|
|
34
|
-
const id =
|
|
39
|
+
const id = `${idPrefix ?? ""}field-${field.name}`;
|
|
35
40
|
|
|
36
41
|
if (field.type === "media") {
|
|
37
42
|
return (
|
|
@@ -71,6 +76,42 @@ export const FieldControl = ({
|
|
|
71
76
|
);
|
|
72
77
|
}
|
|
73
78
|
|
|
79
|
+
if (field.type === "richtext") {
|
|
80
|
+
return (
|
|
81
|
+
<RichTextControl
|
|
82
|
+
field={field}
|
|
83
|
+
id={id}
|
|
84
|
+
value={String(value ?? "")}
|
|
85
|
+
error={error}
|
|
86
|
+
disabled={disabled}
|
|
87
|
+
onChange={onChange}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (field.type === "object-list") {
|
|
93
|
+
return (
|
|
94
|
+
<ObjectListControl
|
|
95
|
+
field={field}
|
|
96
|
+
value={Array.isArray(value) ? (value as ObjectItem[]) : []}
|
|
97
|
+
error={error}
|
|
98
|
+
disabled={disabled}
|
|
99
|
+
onChange={onChange}
|
|
100
|
+
renderField={(subfield, subvalue, onSubChange, subPrefix) => (
|
|
101
|
+
<FieldControl
|
|
102
|
+
key={subfield.name}
|
|
103
|
+
field={subfield}
|
|
104
|
+
collectionSlug={collectionSlug}
|
|
105
|
+
value={subvalue}
|
|
106
|
+
disabled={disabled}
|
|
107
|
+
idPrefix={subPrefix}
|
|
108
|
+
onChange={onSubChange}
|
|
109
|
+
/>
|
|
110
|
+
)}
|
|
111
|
+
/>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
74
115
|
if (field.type === "relation") {
|
|
75
116
|
return (
|
|
76
117
|
<RelationControl
|
package/src/ui/admin/i18n.tsx
CHANGED
|
@@ -120,11 +120,25 @@ const en: Dictionary = {
|
|
|
120
120
|
|
|
121
121
|
"list.empty": "No items.",
|
|
122
122
|
"list.item": "Item {index}",
|
|
123
|
+
"list.count": "{count} item(s)",
|
|
123
124
|
"list.moveUp": "Move up",
|
|
124
125
|
"list.moveDown": "Move down",
|
|
125
126
|
"list.remove": "Remove",
|
|
126
127
|
"list.add": "Add item",
|
|
127
128
|
|
|
129
|
+
"richtext.bold": "Bold",
|
|
130
|
+
"richtext.header": "Header",
|
|
131
|
+
"richtext.italic": "Italic",
|
|
132
|
+
"richtext.quote": "Quote",
|
|
133
|
+
"richtext.link": "Link",
|
|
134
|
+
"richtext.unorderedList": "Bullet list",
|
|
135
|
+
"richtext.orderedList": "Numbered list",
|
|
136
|
+
"richtext.taskList": "Task list",
|
|
137
|
+
"richtext.write": "Write",
|
|
138
|
+
"richtext.preview": "Preview",
|
|
139
|
+
"richtext.tabs": "Editor mode",
|
|
140
|
+
"richtext.previewEmpty": "The preview appears as you type.",
|
|
141
|
+
|
|
128
142
|
"pagination.range": "{from}–{to} of {total} items",
|
|
129
143
|
"pagination.previous": "Previous",
|
|
130
144
|
"pagination.next": "Next",
|
|
@@ -155,13 +169,13 @@ const en: Dictionary = {
|
|
|
155
169
|
"users.networkRemove": "Network error while removing the user.",
|
|
156
170
|
|
|
157
171
|
"backup.title": "Backup",
|
|
158
|
-
"backup.subtitle": "Download or restore
|
|
172
|
+
"backup.subtitle": "Download or restore schemas, database and system images.",
|
|
159
173
|
"backup.refresh": "Refresh",
|
|
160
174
|
"backup.downloadCurrent": "Download current",
|
|
161
175
|
"backup.restoreAction": "Restore",
|
|
162
176
|
"backup.create": "Create backup",
|
|
163
177
|
"backup.description":
|
|
164
|
-
"The backup bundles a consistent SQLite snapshot and every file under public/images and public/files. Restoring replaces the current database and rewrites the images.",
|
|
178
|
+
"The backup bundles the collection schemas, a consistent SQLite snapshot and every file under public/images and public/files. Restoring rewrites the schema modules, replaces the current database and rewrites the images.",
|
|
165
179
|
"backup.file": "File",
|
|
166
180
|
"backup.size": "Size",
|
|
167
181
|
"backup.download": "Download",
|
|
@@ -275,11 +289,25 @@ const pt: Dictionary = {
|
|
|
275
289
|
|
|
276
290
|
"list.empty": "Nenhum item.",
|
|
277
291
|
"list.item": "Item {index}",
|
|
292
|
+
"list.count": "{count} item(ns)",
|
|
278
293
|
"list.moveUp": "Mover para cima",
|
|
279
294
|
"list.moveDown": "Mover para baixo",
|
|
280
295
|
"list.remove": "Remover",
|
|
281
296
|
"list.add": "Adicionar item",
|
|
282
297
|
|
|
298
|
+
"richtext.bold": "Negrito",
|
|
299
|
+
"richtext.header": "Título",
|
|
300
|
+
"richtext.italic": "Itálico",
|
|
301
|
+
"richtext.quote": "Citação",
|
|
302
|
+
"richtext.link": "Link",
|
|
303
|
+
"richtext.unorderedList": "Lista com marcadores",
|
|
304
|
+
"richtext.orderedList": "Lista numerada",
|
|
305
|
+
"richtext.taskList": "Lista de tarefas",
|
|
306
|
+
"richtext.write": "Escrever",
|
|
307
|
+
"richtext.preview": "Prévia",
|
|
308
|
+
"richtext.tabs": "Modo do editor",
|
|
309
|
+
"richtext.previewEmpty": "A prévia aparece enquanto você digita.",
|
|
310
|
+
|
|
283
311
|
"pagination.range": "{from}–{to} de {total} itens",
|
|
284
312
|
"pagination.previous": "Anterior",
|
|
285
313
|
"pagination.next": "Próxima",
|
|
@@ -310,13 +338,13 @@ const pt: Dictionary = {
|
|
|
310
338
|
"users.networkRemove": "Erro de rede ao remover o usuário.",
|
|
311
339
|
|
|
312
340
|
"backup.title": "Backup",
|
|
313
|
-
"backup.subtitle": "Baixe ou restaure o banco de dados e as imagens do sistema.",
|
|
341
|
+
"backup.subtitle": "Baixe ou restaure os schemas, o banco de dados e as imagens do sistema.",
|
|
314
342
|
"backup.refresh": "Atualizar",
|
|
315
343
|
"backup.downloadCurrent": "Baixar atual",
|
|
316
344
|
"backup.restoreAction": "Restaurar",
|
|
317
345
|
"backup.create": "Criar backup",
|
|
318
346
|
"backup.description":
|
|
319
|
-
"O backup reúne um snapshot consistente do banco SQLite e todos os arquivos de public/images e public/files. Restaurar substitui o banco atual e regrava as imagens.",
|
|
347
|
+
"O backup reúne os schemas das coleções, um snapshot consistente do banco SQLite e todos os arquivos de public/images e public/files. Restaurar regrava os módulos de schema, substitui o banco atual e regrava as imagens.",
|
|
320
348
|
"backup.file": "Arquivo",
|
|
321
349
|
"backup.size": "Tamanho",
|
|
322
350
|
"backup.download": "Baixar",
|