feat(admin): footer record actions, deletable flag, mail row states and diff styles

- FormView footer RecordActions when there is no preview; meta.deletable hides Delete
- Partial fields reload after save and record actions; customized/outdated badges
- .summer-diff kit and docs for codeeditor, mailpreview and footer actions

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-13 13:37:55 +01:00
parent aba512800e
commit d13340672f
9 changed files with 155 additions and 25 deletions

View File

@@ -1,14 +1,18 @@
<script setup lang="ts">
import { inject, ref } from 'vue'
import { t } from '../../../app/i18n'
import PartialHost from '../../partial/PartialHost.vue'
import ExtensionFailure from '../../ui/ExtensionFailure.vue'
import type { FieldControlProps } from '../control'
import { FORM_PARTIAL_RELOAD } from '../formContext'
// A `type: partial` form row (D-09; UI-SPEC S2): the controller partial
// named by `path`, rendered on create (no record) and update (?id=). It holds
// no value. The row's visible label, when declared, names the group. A form
// without a controller (a settings page) has no partial route to call.
// Phase 35: reloads when FormView bumps FORM_PARTIAL_RELOAD after save/action.
const props = defineProps<FieldControlProps>()
const reloadKey = inject(FORM_PARTIAL_RELOAD, ref(0))
</script>
<template>
@@ -25,6 +29,7 @@ const props = defineProps<FieldControlProps>()
:source="source"
:name="props.field.path || props.field.name"
:record-id="recordId ?? null"
:reload-key="reloadKey"
/>
<ExtensionFailure v-else data-partial-failed :text="t('backend::lang.extension.partial_failed')" />
</div>

View File

@@ -16,6 +16,12 @@ export const FORM_PATCH: InjectionKey<(name: string, value: unknown) => void> =
/** The form schema's locale (meta.locale). */
export const FORM_LOCALE: InjectionKey<Readonly<Ref<string>>> = Symbol('summer.form.locale')
/**
* Bumped after every successful save and record action so `type: partial`
* fields re-fetch (Phase 35, UI-SPEC C8).
*/
export const FORM_PARTIAL_RELOAD: InjectionKey<Readonly<Ref<number>>> = Symbol('summer.form.partialReload')
/** Enabled content locales for ML controls (schema meta.enabledLocales). */
export const FORM_ENABLED_LOCALES: InjectionKey<Readonly<Ref<readonly string[]>>> = Symbol('summer.form.enabledLocales')

View File

@@ -157,7 +157,7 @@ function initials(value: unknown): string {
.join('')
}
const ROW_STATES = ['deleted', 'negative', 'disabled']
const ROW_STATES = ['deleted', 'negative', 'disabled', 'customized', 'outdated']
/** The row's known states in the fixed order; anything else is dropped. */
function statesOf(row: AdminRecord): string[] {

View File

@@ -15,8 +15,10 @@ const STYLES: Record<string, string> = {
deleted: 'border border-border-strong text-muted',
negative: 'bg-danger-soft text-danger',
disabled: 'bg-subtle text-muted',
customized: 'border border-border-strong text-text',
outdated: 'bg-sel text-text',
}
const ORDER = ['deleted', 'negative', 'disabled']
const ORDER = ['deleted', 'negative', 'disabled', 'customized', 'outdated']
const badges = computed(() => ORDER.filter((state) => props.states.includes(state)))
</script>

View File

@@ -492,6 +492,42 @@
margin: 0;
font-weight: 400;
}
/* Unified diff kit for mail file-version partials (Phase 35, UI-SPEC C7). */
.summer-diff {
margin: 0;
max-height: 480px;
overflow: auto;
padding: 12px 16px;
border: 1px solid var(--c-border);
border-radius: 12px;
background: var(--c-subtle);
font-family: var(--font-mono);
font-size: 13px;
line-height: 1.5;
white-space: pre;
color: var(--c-text);
}
.summer-diff__add,
.summer-diff__del,
.summer-diff__ctx {
display: block;
}
.summer-diff__add {
background: var(--c-ok-bg);
color: var(--c-ok-text);
}
.summer-diff__del {
background: var(--c-danger-soft);
color: var(--c-danger);
}
.summer-diff__ctx {
color: var(--c-text);
}
}
@media (prefers-reduced-motion: reduce) {

View File

@@ -4,7 +4,15 @@ import { onBeforeRouteLeave, onBeforeRouteUpdate, useRoute, useRouter } from 'vu
import { ArrowLeft, Trash2 } from '@lucide/vue'
import { api } from '../api/client'
import { parentFileRoutes } from '../api/files'
import type { AdminRecord, ErrorEnvelope, FormView, RecordEnvelope, RecordMeta, RelationOption } from '../api/types'
import type {
AdminRecord,
ErrorEnvelope,
FormView,
RecordAction,
RecordEnvelope,
RecordMeta,
RelationOption,
} from '../api/types'
import { controllerIdFromParams, controllerPath } from '../app/controllerRoutes'
import { shortcutHint } from '../app/hotkeys'
import { currentLocale, message, t } from '../app/i18n'
@@ -20,6 +28,7 @@ import {
FORM_ENABLED_LOCALES,
FORM_FEEDBACK,
FORM_LOCALE,
FORM_PARTIAL_RELOAD,
FORM_PATCH,
FORM_PERMISSION_LOCKS,
FORM_REMEMBER_LABEL,
@@ -28,6 +37,7 @@ import {
FORM_VALUES,
createUploadGate,
} from '../components/form/formContext'
import RecordActions from '../components/form/RecordActions.vue'
import type { AdminDependentOptionsResult } from '../api/types'
import { RELATION_MANAGER, needsRecord } from '../components/form/registry'
import { applyTriggers } from '../components/form/trigger'
@@ -91,6 +101,12 @@ const labels = ref<RecordMeta['labels']>({})
const permissionLocks = ref<NonNullable<RecordMeta['permissionLocks']>>({})
/** The controller's record title (meta.title, pact.FormRecordTitle); '' when it names none. */
const recordTitle = ref('')
/** Record actions from the show response (footer when there is no preview). */
const actions = ref<RecordAction[]>([])
/** When false, Delete is hidden; absent means true (existing controllers). */
const deletable = ref(true)
const acting = ref(false)
const partialReload = ref(0)
const errors = ref<Record<string, string[]>>({})
// The text of a save the server refused with 403 (UI-SPEC S6). It is a
// banner, not a toast: it stays readable until the next save attempt.
@@ -248,6 +264,8 @@ function adopt(record: RecordEnvelope | undefined): void {
labels.value = record.meta.labels ?? {}
permissionLocks.value = record.meta.permissionLocks ?? {}
recordTitle.value = record.meta.title ?? ''
actions.value = record.meta.actions ?? []
deletable.value = record.meta.deletable !== false
}
saved.value = snapshot(editablePayload(fields.value, values.value, mode, permissionLocks.value))
}
@@ -359,6 +377,7 @@ provide(FORM_ENABLED_LOCALES, computed(() => schemaEnabledLocales(schema.value?.
provide(FORM_ASSETS, () => assetsReady)
provide(FORM_PERMISSION_LOCKS, computed(() => permissionLocks.value))
provide(FORM_TRIGGER_NOTES, computed(() => triggered.value.notes))
provide(FORM_PARTIAL_RELOAD, partialReload)
// The form's single polite live region (dependent dropdown clears, repeater
// moves) and the feedback nested controls read: errors and notices by row
// path, the confirm dialog (Phase 17, D-07, D-08).
@@ -480,6 +499,7 @@ async function save(): Promise<RecordEnvelope | null> {
// The save committed everything held against the session.
pendingChanges.value = 0
revision.value++
partialReload.value++
const savedText = message(schema.value.messages.saved, undefined, { name: recordName.value })
// The toast repeats the notices, so a save that navigates away (save
// and close) still tells the administrator what changed.
@@ -543,6 +563,46 @@ async function onSaveAndNew(): Promise<void> {
}
}
const footerActions = computed(
() => mode === 'update' && !singleton.value && !backToPreview.value && actions.value.length > 0,
)
const showDelete = computed(() => mode === 'update' && !singleton.value && deletable.value)
const footerBusy = computed(() => busy.value || acting.value)
async function onActionDone(text: string): Promise<void> {
showToast(text)
if (recordId === null) {
return
}
const result = await api.GET('/{vendor}/{plugin}/{controller}/{id}', {
params: { path: { ...path, id: recordId } },
})
if (result.data) {
adopt(result.data)
partialReload.value++
} else if (result.response.status === 404) {
failed.value = true
}
}
async function onActionStale(): Promise<void> {
// RecordActions already toasted action_stale; reload the record in place.
if (recordId === null) {
return
}
const result = await api.GET('/{vendor}/{plugin}/{controller}/{id}', {
params: { path: { ...path, id: recordId } },
})
if (result.data) {
adopt(result.data)
partialReload.value++
}
}
function onActionGone(): void {
failed.value = true
}
async function onDelete(): Promise<void> {
if (recordId === null || busy.value || !schema.value) {
return
@@ -678,27 +738,40 @@ void load()
</template>
<footer
class="fixed right-0 bottom-0 left-[var(--shell-offset,0px)] z-30 flex items-center gap-2.5 border-t border-border bg-surface px-8 py-3.5"
class="fixed right-0 bottom-0 left-[var(--shell-offset,0px)] z-30 flex flex-wrap items-center gap-2.5 border-t border-border bg-surface px-8 py-3.5"
>
<Button
v-if="mode === 'update' && !singleton"
variant="danger"
data-action="delete"
:icon="Trash2"
:disabled="busy || loading || !schema"
@click="onDelete"
>
{{ t('backend::lang.form.delete') }}
</Button>
<div class="ml-auto flex items-center gap-2.5">
<Button variant="ghost" data-action="cancel" hotkey="escape" @click="onLeave">{{ t('backend::lang.form.cancel') }}</Button>
<div class="flex flex-wrap items-center gap-2.5">
<Button
v-if="showDelete"
variant="danger"
data-action="delete"
:icon="Trash2"
:disabled="footerBusy || loading || !schema"
@click="onDelete"
>
{{ t('backend::lang.form.delete') }}
</Button>
<RecordActions
v-if="footerActions && recordId !== null"
:source="path"
:record-id="recordId"
:actions="actions"
:disabled="footerBusy || loading || !schema"
@busy="(running: boolean) => (acting = running)"
@done="onActionDone"
@stale="onActionStale"
@gone="onActionGone"
/>
</div>
<div class="ml-auto flex flex-wrap items-center gap-2.5">
<Button variant="ghost" data-action="cancel" hotkey="escape" :disabled="footerBusy" @click="onLeave">{{ t('backend::lang.form.cancel') }}</Button>
<Button
v-if="mode === 'create'"
variant="outline"
data-action="save-new"
hotkey="mod+shift+s"
:title="shortcutHint(t('backend::lang.form.create_and_new'), 'mod+shift+s')"
:disabled="busy || loading || !schema || activeUploads > 0"
:disabled="footerBusy || loading || !schema || activeUploads > 0"
@click="onSaveAndNew"
>
{{ t('backend::lang.form.create_and_new') }}
@@ -708,7 +781,7 @@ void load()
data-action="save-close"
hotkey="mod+enter"
:title="shortcutHint(t('backend::lang.form.save_and_close'), 'mod+enter')"
:disabled="busy || loading || !schema || activeUploads > 0"
:disabled="footerBusy || loading || !schema || activeUploads > 0"
@click="onSaveAndClose"
>
{{ t('backend::lang.form.save_and_close') }}
@@ -718,7 +791,7 @@ void load()
data-action="save"
hotkey="mod+s"
:title="shortcutHint(t('backend::lang.form.save'), 'mod+s')"
:disabled="busy || loading || !schema || activeUploads > 0"
:disabled="footerBusy || loading || !schema || activeUploads > 0"
@click="onSave"
>
{{ busy ? t('backend::lang.form.saving') : t('backend::lang.form.save') }}

View File

@@ -106,6 +106,8 @@ const stateLabels = computed(() => ({
deleted: message(messages.value?.rowStateDeleted),
negative: message(messages.value?.rowStateNegative),
disabled: message(messages.value?.rowStateDisabled),
customized: message(messages.value?.rowStateCustomized),
outdated: message(messages.value?.rowStateOutdated),
}))
// Declared bulk actions the admin may run (D-09), in declared order. The
// built-in delete stays the toolbar button and is not part of the menu.

View File

@@ -66,6 +66,10 @@ As in WinterCMS, a shortcut presses a button on the screen. Ctrl and Cmd are bot
A shortcut does what its button does, and nothing while the button is disabled (while saving, while loading, with an upload in progress). The save keys also work while typing in a field, a code field or the rich editor. There, on a record form, Ctrl+Enter saves and closes instead of inserting a line break (Shift+Enter still does), and on a create form Ctrl+Shift+S creates and starts a new record instead of toggling strikethrough; this is a known trade-off. Ctrl+S never opens the browser's Save page dialog.
The `codeeditor` field (CodeMirror 6) keeps the same model: Tab is not bound to indent, so focus leaves the editor; Mod+S and Mod+Enter still save the form; Esc does not cancel while the caret is in the editor. A load failure falls back to a monospace textarea that still saves.
The `mailpreview` field posts the unsaved draft to `POST /mail/preview` and shows the server HTML in a sandboxed iframe (`sandbox=""` with `srcdoc` only). **Send test to me** posts the same draft to `POST /mail/test-send` with no recipient; a 429 disables the button for `Retry-After` seconds.
Esc, / and ? do nothing while typing in a field, or while a dialog, popover or menu is open; those close on Esc themselves. When a dialog with a form is open (a related record, a pivot, the record picker, file details, a new API token), Ctrl+S and Ctrl+Enter submit that dialog and never the form underneath. Settings forms and My account have no unsaved-changes question, so Esc does not leave them. Save buttons show their shortcut in their tooltip.
## Types from OpenAPI

View File

@@ -29,7 +29,9 @@ update:
On a create form Save follows `redirect` and Save and close follows `redirectClose`; on an update form Save stays on the record. The create form also has Create and new, which saves the record and opens an empty create form of the same controller, ignoring both redirects. The buttons answer Ctrl+S (Cmd+S on macOS), Ctrl+Enter and, on the create form, Ctrl+Shift+S.
An optional `recordActions` key lists the record actions the form offers, by the names the controller registers through `pact.HasAdminRecordActions`. It needs a `preview` block, because record actions are offered on the [preview screen](#preview-screen). The show response of a record then carries `meta.actions`: the declared actions the administrator may run and that apply to the record in its current state. See [Record actions](admin-controllers.md#record-actions).
An optional `recordActions` key lists the record actions the form offers, by the names the controller registers through `pact.HasAdminRecordActions`. When the form has a `preview` block, those actions appear on the [preview screen](#preview-screen). When it has no preview, the update form footer shows them after Delete (outline buttons; a `danger` action uses the danger confirm). The show response of a record carries `meta.actions`: the declared actions the administrator may run and that apply to the record in its current state. See [Record actions](admin-controllers.md#record-actions).
`meta.deletable` on the show response hides Delete when it is `false`. When the key is absent, Delete behaves as before (`true`), so existing controllers are unchanged. After every successful save and record action, `type: partial` fields reload so status hints and diffs stay current.
## fields.yaml
@@ -107,12 +109,12 @@ for _, f := range form.Fields {
| `repeater` | A list of rows, each with its own small form, stored as JSON in one column; see [Repeater](#repeater). |
| `money` | An exact decimal amount with a currency suffix, never a float and never rounded; see [Money](#money). |
| `taglist` | A list of tags edited as chips, stored as a JSON array or as one separator-joined string; see [Taglist](#taglist). |
| `codeeditor` | A source editor for HTML, CSS or plain text (`language` required: `html`, `css` or `text`); optional `size` and `mailImages: true` for the mail image insert control. |
| `colorpicker` | A `#rrggbb` colour (or empty); Winter's `availableColors` is not supported. Invalid colours are a 422 with `backend::lang.colorpicker.invalid`. |
| `mailimage` | A single image chosen from the mail image library (stores a file id). Missing library images are a 422 with `backend::lang.mailimage.missing`. |
| `mailpreview` | A valueless live preview control (`mode` required: `template`, `layout`, `partial` or `branding`); never bound or accepted in a save body. |
| `codeeditor` | A CodeMirror 6 source editor for HTML, CSS or plain text (`language` required: `html`, `css` or `text`); optional `size` and `mailImages: true` for the mail image insert control. Tab leaves the editor; Mod+S / Mod+Enter still save. A load failure falls back to a monospace textarea. |
| `colorpicker` | A `#rrggbb` colour (or empty) with a native swatch and hex text; Winter's `availableColors` is not supported. Invalid colours are a 422 with `backend::lang.colorpicker.invalid`. |
| `mailimage` | A single image chosen from the mail image library (stores a file id or null). Missing library images show `backend::lang.mailimage.missing` in the admin and are a 422 on save. |
| `mailpreview` | A valueless live preview control (`mode` required: `template`, `layout`, `partial` or `branding`); never bound or accepted in a save body. Renders the server HTML in a sandboxed iframe and can send a test to the signed-in administrator. |
The WinterCMS widgets that are not in this list (the code editor, the color picker, the media finder and the others) are not provided. A field with one of those types stops the start-up, unless a plugin registers that alias as its own field type: plugins add field types with a custom element and Go code that decides what is stored; see [Plugin field types](field-types.md).
The WinterCMS widgets that are not in this list (the media finder and the others) are not provided. A field with one of those types stops the start-up, unless a plugin registers that alias as its own field type: plugins add field types with a custom element and Go code that decides what is stored; see [Plugin field types](field-types.md).
### Field options