@quoin-cms/admin 0.6.0 → 0.6.1
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/package.json
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import type { FieldSchema } from '$lib/types/schema.js';
|
|
2
3
|
import BlockCard from './BlockCard.svelte';
|
|
3
4
|
|
|
4
5
|
interface Props {
|
|
5
|
-
field: {
|
|
6
|
+
field: {
|
|
7
|
+
name: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
labels?: { singular?: string; plural?: string };
|
|
10
|
+
/** Subfield schemas injected by the server from Go field.Array.Fields. */
|
|
11
|
+
fields?: FieldSchema[];
|
|
12
|
+
};
|
|
6
13
|
// Two-way bound by FieldWidget (`bind:value`); writes go straight back.
|
|
7
14
|
value?: any[];
|
|
8
15
|
}
|
|
@@ -10,6 +17,7 @@
|
|
|
10
17
|
|
|
11
18
|
const rows = $derived(Array.isArray(value) ? value : []);
|
|
12
19
|
const singular = $derived(field.labels?.singular ?? 'Item');
|
|
20
|
+
const subfields = $derived<FieldSchema[]>(field.fields ?? []);
|
|
13
21
|
|
|
14
22
|
function genId(): string {
|
|
15
23
|
// randomUUID is only defined in secure contexts; fall back so array
|
|
@@ -24,11 +32,6 @@
|
|
|
24
32
|
function add() {
|
|
25
33
|
value = [...rows, { id: genId() }];
|
|
26
34
|
}
|
|
27
|
-
function update(i: number, next: any) {
|
|
28
|
-
const out = [...rows];
|
|
29
|
-
out[i] = next;
|
|
30
|
-
value = out;
|
|
31
|
-
}
|
|
32
35
|
function remove(i: number) {
|
|
33
36
|
value = rows.filter((_, j) => j !== i);
|
|
34
37
|
}
|
|
@@ -51,10 +54,10 @@
|
|
|
51
54
|
{#each rows as row, i (row.id)}
|
|
52
55
|
<BlockCard
|
|
53
56
|
title="{singular} #{i + 1}"
|
|
54
|
-
|
|
57
|
+
fields={subfields}
|
|
58
|
+
bind:row={value![i]}
|
|
55
59
|
canMoveUp={i > 0}
|
|
56
60
|
canMoveDown={i < rows.length - 1}
|
|
57
|
-
onChange={(next) => update(i, next)}
|
|
58
61
|
onMoveUp={() => moveUp(i)}
|
|
59
62
|
onMoveDown={() => moveDown(i)}
|
|
60
63
|
onDelete={() => remove(i)}
|
|
@@ -1,39 +1,33 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import type { FieldSchema } from '$lib/types/schema.js';
|
|
3
|
+
import FieldWidget from './FieldWidget.svelte';
|
|
4
|
+
|
|
2
5
|
interface Props {
|
|
3
6
|
title: string; // e.g. "Block #1 · hero"
|
|
4
|
-
|
|
7
|
+
/** Subfield schemas for the row (Array.Fields, or Blocks block fields). */
|
|
8
|
+
fields: FieldSchema[];
|
|
9
|
+
/** The row data; mutated in place via FieldWidget's bind:value. */
|
|
10
|
+
row: Record<string, any>;
|
|
5
11
|
canMoveUp: boolean;
|
|
6
12
|
canMoveDown: boolean;
|
|
7
|
-
onChange: (next: Record<string, any>) => void;
|
|
8
13
|
onMoveUp: () => void;
|
|
9
14
|
onMoveDown: () => void;
|
|
10
15
|
onDelete: () => void;
|
|
11
16
|
}
|
|
12
|
-
let {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function save() {
|
|
24
|
-
try {
|
|
25
|
-
const parsed = JSON.parse(text);
|
|
26
|
-
parseError = '';
|
|
27
|
-
onChange({ ...parsed, id: value.id });
|
|
28
|
-
} catch (e: any) {
|
|
29
|
-
parseError = e.message;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
17
|
+
let {
|
|
18
|
+
title,
|
|
19
|
+
fields,
|
|
20
|
+
row = $bindable(),
|
|
21
|
+
canMoveUp,
|
|
22
|
+
canMoveDown,
|
|
23
|
+
onMoveUp,
|
|
24
|
+
onMoveDown,
|
|
25
|
+
onDelete,
|
|
26
|
+
}: Props = $props();
|
|
32
27
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
28
|
+
const visibleFields = $derived(
|
|
29
|
+
(fields ?? []).filter((f) => !f.hidden && !f.adminHidden),
|
|
30
|
+
);
|
|
37
31
|
</script>
|
|
38
32
|
|
|
39
33
|
<div class="card">
|
|
@@ -45,11 +39,11 @@
|
|
|
45
39
|
<button type="button" onclick={onDelete} aria-label="Delete">×</button>
|
|
46
40
|
</div>
|
|
47
41
|
</header>
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
<div class="body">
|
|
43
|
+
{#each visibleFields as sf (sf.name)}
|
|
44
|
+
<FieldWidget field={sf} bind:value={row[sf.name]} formData={row} />
|
|
45
|
+
{/each}
|
|
46
|
+
</div>
|
|
53
47
|
</div>
|
|
54
48
|
|
|
55
49
|
<style>
|
|
@@ -57,7 +51,5 @@
|
|
|
57
51
|
header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
|
|
58
52
|
.title { font-weight: 600; font-family: monospace; font-size: 13px; }
|
|
59
53
|
.actions button { margin-left: 4px; }
|
|
60
|
-
|
|
61
|
-
textarea.error { border-color: #c00; }
|
|
62
|
-
.parse-error { color: #c00; font-size: 12px; margin: 4px 0; }
|
|
54
|
+
.body { display: flex; flex-direction: column; gap: 12px; }
|
|
63
55
|
</style>
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import type { FieldSchema } from '$lib/types/schema.js';
|
|
2
3
|
import BlockCard from './BlockCard.svelte';
|
|
3
4
|
|
|
4
5
|
interface BlockDef {
|
|
5
6
|
slug: string;
|
|
6
7
|
label: string;
|
|
7
|
-
fields?:
|
|
8
|
+
fields?: FieldSchema[];
|
|
8
9
|
}
|
|
9
10
|
interface Props {
|
|
10
11
|
field: {
|
|
@@ -33,15 +34,14 @@
|
|
|
33
34
|
function defaultsFor(slug: string): Record<string, any> {
|
|
34
35
|
return { id: genId(), blockType: slug };
|
|
35
36
|
}
|
|
37
|
+
function fieldsForRow(row: Record<string, any>): FieldSchema[] {
|
|
38
|
+
const def = field.blocks.find((b) => b.slug === row?.blockType);
|
|
39
|
+
return def?.fields ?? [];
|
|
40
|
+
}
|
|
36
41
|
function add() {
|
|
37
42
|
if (!pickerSlug) return;
|
|
38
43
|
value = [...rows, defaultsFor(pickerSlug)];
|
|
39
44
|
}
|
|
40
|
-
function update(i: number, next: any) {
|
|
41
|
-
const out = [...rows];
|
|
42
|
-
out[i] = next;
|
|
43
|
-
value = out;
|
|
44
|
-
}
|
|
45
45
|
function remove(i: number) {
|
|
46
46
|
value = rows.filter((_, j) => j !== i);
|
|
47
47
|
}
|
|
@@ -64,10 +64,10 @@
|
|
|
64
64
|
{#each rows as row, i (row.id)}
|
|
65
65
|
<BlockCard
|
|
66
66
|
title="Block #{i + 1} · {row.blockType ?? '?'}"
|
|
67
|
-
|
|
67
|
+
fields={fieldsForRow(row)}
|
|
68
|
+
bind:row={value![i]}
|
|
68
69
|
canMoveUp={i > 0}
|
|
69
70
|
canMoveDown={i < rows.length - 1}
|
|
70
|
-
onChange={(next) => update(i, next)}
|
|
71
71
|
onMoveUp={() => moveUp(i)}
|
|
72
72
|
onMoveDown={() => moveDown(i)}
|
|
73
73
|
onDelete={() => remove(i)}
|