runeforge 0.0.28 → 0.0.29
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
|
@@ -508,6 +508,8 @@ createdTo: {
|
|
|
508
508
|
|
|
509
509
|
A `row` only merges fields that are also in the same `groupedAs` fieldset (or both ungrouped) — it never pulls fields together across two different fieldsets. If one of the fields in a row is conditionally [hidden](#conditional-fields), the remaining field(s) simply expand to fill the row instead of leaving a gap.
|
|
510
510
|
|
|
511
|
+
`groupedAs` and `row` both work the same way inside an [embedded field](#embedded-fields-sub-documents)'s `fields` sub-schema — the "+ Add"/edit modal groups and lays out its own fields identically to a top-level form.
|
|
512
|
+
|
|
511
513
|
### Default values
|
|
512
514
|
|
|
513
515
|
`default` can be a plain value or a function of the page `data` object, evaluated once when the create form's fields are resolved — handy for defaulting a select to something derived from prefetched data.
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { emptyRecord, seedField, defaultItemLabel } from './utils/embedded.js';
|
|
6
6
|
import { fieldLabel } from './utils/misc.js';
|
|
7
7
|
import { validateAll } from './utils/validation.js';
|
|
8
|
+
import { groupFields } from './utils/grouping.js';
|
|
8
9
|
import type { FieldDefinition } from '../../types/crud.js';
|
|
9
10
|
import { getStrings } from '../../i18n/context.js';
|
|
10
11
|
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
} = $props();
|
|
22
23
|
|
|
23
24
|
const subFields = $derived(field.fields ?? []);
|
|
25
|
+
const subGroups = $derived(groupFields(subFields));
|
|
24
26
|
const items = $derived((record[field.attribute] as Record<string, unknown>[] | undefined) ?? []);
|
|
25
27
|
|
|
26
28
|
let modalOpen = $state(false);
|
|
@@ -130,8 +132,37 @@
|
|
|
130
132
|
{#if modalOpen}
|
|
131
133
|
<Modal title={fieldLabel(field)} onClose={closeModal}>
|
|
132
134
|
<div class="flex flex-col gap-4">
|
|
133
|
-
{#each
|
|
134
|
-
|
|
135
|
+
{#each subGroups as group, i (group.title ?? `_ungrouped_${i}`)}
|
|
136
|
+
{#if group.title}
|
|
137
|
+
<fieldset class="fieldset border border-base-300 rounded-box p-4">
|
|
138
|
+
<legend class="fieldset-legend px-2">{group.title}</legend>
|
|
139
|
+
<div class="flex flex-col gap-4">
|
|
140
|
+
{#each group.rows as row (row.map((f) => f.attribute).join('|'))}
|
|
141
|
+
{#if row.length > 1}
|
|
142
|
+
<div class="flex flex-col gap-4 md:flex-row">
|
|
143
|
+
{#each row as f (f.attribute)}
|
|
144
|
+
<Field field={f} bind:record={draft} error={draftErrors[f.attribute] ?? ''} class="md:min-w-0 md:flex-1" />
|
|
145
|
+
{/each}
|
|
146
|
+
</div>
|
|
147
|
+
{:else}
|
|
148
|
+
<Field field={row[0]} bind:record={draft} error={draftErrors[row[0].attribute] ?? ''} />
|
|
149
|
+
{/if}
|
|
150
|
+
{/each}
|
|
151
|
+
</div>
|
|
152
|
+
</fieldset>
|
|
153
|
+
{:else}
|
|
154
|
+
{#each group.rows as row (row.map((f) => f.attribute).join('|'))}
|
|
155
|
+
{#if row.length > 1}
|
|
156
|
+
<div class="flex flex-col gap-4 md:flex-row">
|
|
157
|
+
{#each row as f (f.attribute)}
|
|
158
|
+
<Field field={f} bind:record={draft} error={draftErrors[f.attribute] ?? ''} class="md:min-w-0 md:flex-1" />
|
|
159
|
+
{/each}
|
|
160
|
+
</div>
|
|
161
|
+
{:else}
|
|
162
|
+
<Field field={row[0]} bind:record={draft} error={draftErrors[row[0].attribute] ?? ''} />
|
|
163
|
+
{/if}
|
|
164
|
+
{/each}
|
|
165
|
+
{/if}
|
|
135
166
|
{/each}
|
|
136
167
|
<div class="flex flex-col-reverse gap-2 pt-2 sm:flex-row sm:justify-end">
|
|
137
168
|
<Button variant="ghost" onclick={closeModal}>{strings.cancel}</Button>
|