From fbfb16819fd42d4410526113b81292a5e2e820b6 Mon Sep 17 00:00:00 2001 From: erKam Date: Sat, 7 Nov 2026 16:21:03 +0000 Subject: [PATCH 01/14] refactor(forms): split the forms panel page into smaller components The forms page was one component of about 1,800 lines. Move the setup error notice, the form list, the action bar and the Fields tab into their own components, and share the status badge styles. The page keeps the state and the behaviour stays the same. --- app/src/pages/forms-action-bar.ts | 142 ++++ app/src/pages/forms-fields.ts | 606 ++++++++++++++++ app/src/pages/forms-inspector.ts | 1024 ++------------------------- app/src/pages/forms-list.ts | 234 ++++++ app/src/pages/forms-setup-errors.ts | 73 ++ app/src/pages/forms-types.ts | 36 + 6 files changed, 1138 insertions(+), 977 deletions(-) create mode 100644 app/src/pages/forms-action-bar.ts create mode 100644 app/src/pages/forms-fields.ts create mode 100644 app/src/pages/forms-list.ts create mode 100644 app/src/pages/forms-setup-errors.ts diff --git a/app/src/pages/forms-action-bar.ts b/app/src/pages/forms-action-bar.ts new file mode 100644 index 00000000..59174d61 --- /dev/null +++ b/app/src/pages/forms-action-bar.ts @@ -0,0 +1,142 @@ +import { Component, input, output } from '@angular/core'; +import { FORMS_STYLES } from './forms-types'; + +/** The form-level actions: touch, revalidate, pick, snapshot and restore, reset and submit. */ +@Component({ + selector: 'app-forms-action-bar', + template: ` +
+
+ + + + + + + @if (snapshot()) { + + } + + + +
+ @if (!canWrite()) { +

{{ writesOff }}

+ } +

{{ message() }}

+
+ `, + styles: ` + ${FORMS_STYLES} + :host { + display: block; + min-width: 0; + } + .action-bar { + display: flex; + flex-direction: column; + gap: 8px; + padding-bottom: 16px; + border-bottom: 1px solid var(--border); + } + .actions { + display: flex; + flex-wrap: wrap; + gap: 8px; + align-items: center; + } + .divider { + width: 1px; + height: 20px; + background: var(--border-strong); + } + .spacer { + flex: 1 1 0; + } + .actions .small:not(.primary):not(.danger) { + max-width: 240px; + } + .small.on { + background: var(--accent-soft); + border-color: var(--accent-line); + color: var(--text-strong); + } + .status:empty { + height: 0; + margin-top: -8px; + } + @media (max-width: 480px) { + .spacer, + .divider { + display: none; + } + } + `, +}) +export class FormsActionBar { + readonly canWrite = input(false); + readonly writesOff = input(''); + /** The form being picked on the page, or null. */ + readonly picking = input(null); + readonly snapshot = input(null); + readonly armed = input(null); + readonly message = input(''); + readonly act = output(); + readonly confirmAct = output<'reset' | 'submit' | 'restore'>(); + readonly pick = output(); + readonly cancelPick = output(); +} diff --git a/app/src/pages/forms-fields.ts b/app/src/pages/forms-fields.ts new file mode 100644 index 00000000..4d6ada8d --- /dev/null +++ b/app/src/pages/forms-fields.ts @@ -0,0 +1,606 @@ +import { Component, input, model, output } from '@angular/core'; +import { JsonPipe } from '@angular/common'; +import type { DevframeRpcClient } from 'devframe/client'; +import { FormsFieldDetail } from './forms-field-detail'; +import { + BADGE_STYLES, + FORMS_STYLES, + SOURCE_LABELS, + redactLabel, + type CollectedForm, + type FormFieldError, + type FormFieldNode, +} from './forms-types'; + +export type Chip = 'invalid' | 'dirty' | 'touched' | 'disabled' | 'hidden-error'; + +export const CHIPS: { id: Chip; label: string }[] = [ + { id: 'invalid', label: 'Invalid' }, + { id: 'dirty', label: 'Dirty' }, + { id: 'touched', label: 'Touched' }, + { id: 'disabled', label: 'Disabled' }, + { id: 'hidden-error', label: 'Error not shown' }, +]; + +export function matchesChip(node: FormFieldNode, chip: Chip): boolean { + switch (chip) { + case 'invalid': + return node.errors.length > 0; + case 'dirty': + return node.dirty && node.type === 'control'; + case 'touched': + return node.touched && node.type === 'control'; + case 'disabled': + return node.status === 'DISABLED'; + case 'hidden-error': + return node.dom?.errorShown === false; + } +} + +export interface FieldRow { + node: FormFieldNode; + depth: number; +} + +/** The Fields tab: the path search, the state chips, the field table and the open field's detail. */ +@Component({ + selector: 'app-forms-fields', + imports: [JsonPipe, FormsFieldDetail], + template: ` +
+ +
+ Show only fields that are + @for (chip of chips; track chip.id) { + + } +
+
+

{{ filterStatus() }}

+ +
+ + + + + + + + + + + + @for (row of rows(); track row.node.path) { + + + + + + + + @if (row.node.truncated) { + + + + } + } @empty { + + + + } + +
FieldValueStatusStateErrors
+ + {{ row.node.type }} + + @if (row.node.type === 'control') { + {{ row.node.value | json }} + @if (row.node.uncommitted !== undefined) { +
+ typed {{ row.node.uncommitted | json }}, not in the model yet +
+ } + @if (row.node.defaultValue !== undefined) { +
+ resets to {{ row.node.defaultValue | json }} +
+ } + } +
+ @if (row.node.materialized === false) { + not created yet + } @else { + {{ + row.node.status + }} + } + + @if (row.node.touched) { + touched + } + @if (row.node.dirty) { + {{ row.node.changed === false ? 'dirty, unchanged' : 'dirty' }} + } + @if (row.node.skipped) { + not validated ({{ row.node.skipped }}) + } + @if (row.node.stale?.length) { + stale: {{ row.node.stale!.join(', ') }} + } + @if (row.node.dom?.drift !== undefined) { + view out of sync + } + @if (row.node.redacted) { + redacted: {{ redactLabel(row.node.redacted) }} + } + @if (row.node.required) { + required + } + @if (row.node.readonly) { + readonly + } + @if (row.node.hidden) { + hidden + } + @if (row.node.updateOn) { + updates on {{ row.node.updateOn }} + } + @if (row.node.debouncing) { + debouncing + } + @if (row.node.validators?.sync) { + validators + } + @if (row.node.validators?.async) { + async validator + } + @for (rule of constraintList(row.node); track rule) { + {{ rule }} + } + @if (row.node.accessor) { + {{ row.node.accessor }} + } + @if (row.node.name) { + name {{ row.node.name }} + } + @for (value of row.node.metadata ?? []; track $index) { + metadata {{ value | json }} + } + @for (reason of row.node.disabledReasons ?? []; track $index) { + disabled: {{ reason }} + } + + @for (error of row.node.errors; track $index) { +
+ {{ errorText(row.node, error) }} + {{ error.kind }} + @if (error.kind === 'standardSchema' && error.params?.['path']) { + at {{ error.params!['path'] }} + } + @if (error.source) { + {{ sourceText(error) }} + } +
+ } + @if (row.node.errors.length && row.node.dom?.errorShown === false) { +
not shown to the user
+ } +
+ {{ row.node.truncated }} more fields under {{ row.node.path || 'the form' }} not + shown +
+

+ @if (filter()) { + No field path matches "{{ filter() }}". + } @else { + No field matches the selected filters. + } +

+ @if (filtering()) { + + } +
+
+ + @if (selectedNode(); as node) { + + } + `, + styles: ` + ${FORMS_STYLES} + ${BADGE_STYLES} + :host { + display: contents; + } + .search { + position: relative; + display: flex; + flex: 1 1 220px; + min-width: 0; + } + .search > input { + flex: 1 1 auto; + width: 100%; + padding-left: 34px; + } + .search-icon { + position: absolute; + top: 50%; + left: 12px; + width: 14px; + height: 14px; + transform: translateY(-50%); + fill: none; + stroke: var(--text-3); + stroke-width: 2.2; + stroke-linecap: round; + pointer-events: none; + } + .search:focus-within .search-icon { + stroke: var(--accent); + } + .filters { + display: flex; + flex-wrap: wrap; + gap: 8px 12px; + align-items: center; + } + .chips { + display: flex; + flex-wrap: wrap; + gap: 6px; + min-width: 0; + margin: 0; + padding: 0; + border: 0; + } + .chips label { + position: relative; + display: inline-flex; + align-items: center; + height: 28px; + padding: 0 12px; + border: 1px solid var(--control-border); + border-radius: 99px; + background: var(--surface-2); + color: var(--text-2); + font-size: 12px; + font-weight: 500; + white-space: nowrap; + cursor: pointer; + user-select: none; + transition: + background-color 150ms var(--ease), + border-color 150ms var(--ease), + color 150ms var(--ease); + } + .chips label:hover { + color: var(--text); + border-color: var(--text-3); + } + .chips input { + position: absolute; + inset: 0; + width: 100%; + height: 100%; + margin: 0; + opacity: 0; + cursor: pointer; + } + .chips label:has(input:checked) { + border-color: var(--accent-line); + background: var(--accent-soft); + color: var(--accent); + } + .chips label:has(input:focus-visible) { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + .filter { + flex: 1 1 220px; + min-width: 0; + height: 34px; + padding: 0 12px 0 34px; + background: var(--bg); + border: 1px solid var(--control-border); + border-radius: var(--radius-sm); + color: var(--text); + font: inherit; + font-size: 13px; + transition: + border-color 150ms var(--ease), + box-shadow 150ms var(--ease); + } + .filter::placeholder { + color: var(--text-3); + } + .filter:hover { + border-color: color-mix(in srgb, var(--text-3) 55%, var(--control-border)); + } + .filter:focus, + .filter:focus-visible { + outline: none; + border-color: var(--accent); + box-shadow: 0 0 0 3px var(--accent-soft); + } + .table-scroll { + overflow-x: auto; + border: 1px solid var(--border); + border-radius: var(--radius-sm); + } + .table-scroll:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + .fields { + width: 100%; + min-width: 680px; + border-collapse: collapse; + font-size: 13px; + } + .fields th, + .fields td { + padding: 8px 12px; + border-bottom: 1px solid var(--border); + text-align: left; + vertical-align: top; + line-height: 20px; + } + .fields tbody tr:last-child > * { + border-bottom: 0; + } + .fields thead th { + background: var(--surface-2); + color: var(--text-3); + font-size: 11px; + font-weight: 600; + letter-spacing: 0.06em; + line-height: 16px; + text-transform: uppercase; + white-space: nowrap; + } + .fields tbody th { + color: var(--text); + font-weight: 500; + white-space: nowrap; + } + .fields tbody tr { + transition: background-color 150ms var(--ease); + } + .fields tbody tr:hover { + background: var(--surface-2); + } + .fields tbody tr.invalid > th { + box-shadow: inset 2px 0 0 color-mix(in srgb, var(--danger) 60%, transparent); + } + .fields tbody tr:has(.field[aria-pressed='true']) { + background: var(--accent-soft); + } + .fields tbody tr:has(.field[aria-pressed='true']) > th { + box-shadow: inset 2px 0 0 var(--accent); + color: var(--text-strong); + } + .name { + max-width: 280px; + } + .field { + display: inline-block; + max-width: 200px; + padding: 0; + overflow: hidden; + border: none; + border-radius: 4px; + background: none; + color: inherit; + font-family: var(--font-mono); + font-size: 12.5px; + font-weight: 500; + line-height: 20px; + text-align: left; + text-overflow: ellipsis; + vertical-align: top; + white-space: nowrap; + cursor: pointer; + transition: color 150ms var(--ease); + } + .field:hover { + color: var(--accent-hover); + text-decoration: underline; + text-underline-offset: 3px; + } + .field[aria-pressed='true'] { + color: var(--accent); + } + .field:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + .type { + margin-left: 8px; + color: var(--text-3); + font-size: 11px; + font-weight: 400; + vertical-align: top; + } + .value { + min-width: 140px; + max-width: 320px; + } + .value code, + .errors code { + color: #fde68a; + overflow-wrap: anywhere; + + @include m.light { + color: var(--accent); + } + } + .value .muted { + margin-top: 2px; + font-size: 12px; + } + .status-cell { + white-space: nowrap; + } + .flags { + min-width: 160px; + } + .flags span { + display: inline-block; + margin: 0 4px 4px 0; + padding: 0 8px; + border: 1px solid var(--border); + border-radius: 99px; + background: var(--surface-2); + color: var(--text-2); + font-size: 11px; + line-height: 18px; + white-space: nowrap; + } + .flags span.warn { + border-color: color-mix(in srgb, var(--warn) 30%, transparent); + background: color-mix(in srgb, var(--warn) 12%, var(--surface)); + color: var(--warn-text); + } + .errors { + min-width: 180px; + } + .errors div { + color: var(--danger); + overflow-wrap: anywhere; + } + .errors div + div { + margin-top: 4px; + } + .errors .kind-tag { + margin-left: 6px; + color: var(--text-3); + font-size: 11px; + } + .source { + margin-left: 6px; + color: var(--text-2); + font-size: 11px; + } + .errors .unseen { + color: var(--warn); + font-size: 11px; + } + .truncated { + color: var(--text-3); + font-size: 12px; + font-style: italic; + } + .fields .no-match { + padding: 24px 12px; + color: var(--text-2); + text-align: center; + } + .fields .no-match p { + margin: 0 0 10px; + } + .fields .no-match p:last-child { + margin-bottom: 0; + } + `, +}) +export class FormsFields { + readonly form = input.required(); + readonly rows = input.required(); + /** The path of the field whose detail is open, or null. */ + readonly fieldPath = input(null); + readonly selectedNode = input(null); + readonly version = input(0); + readonly rpc = input(null); + readonly filtering = input(false); + readonly filterStatus = input(''); + readonly filter = model(''); + readonly active = model(new Set()); + readonly toggleField = output(); + readonly closeField = output(); + readonly clearFilters = output(); + readonly highlight = output<{ formId: string; path: string } | null>(); + + protected readonly chips = CHIPS; + protected readonly redactLabel = redactLabel; + + toggleChip(chip: Chip) { + this.active.update((set) => { + const next = new Set(set); + if (next.has(chip)) next.delete(chip); + else next.add(chip); + return next; + }); + } + + onFilter(event: Event) { + this.filter.set((event.target as HTMLInputElement).value); + } + + sourceText(error: FormFieldError) { + const label = SOURCE_LABELS[error.source ?? ''] ?? error.source ?? ''; + return error.from !== undefined ? `${label} on ${error.from || 'the form'}` : label; + } + + constraintList(node: FormFieldNode) { + return Object.entries(node.constraints ?? {}).map(([name, value]) => `${name} ${value}`); + } + + errorText(node: FormFieldNode, error: FormFieldError) { + return /^[a-z]/.test(error.message) + ? `${node.key || 'The form'} ${error.message}` + : error.message; + } +} diff --git a/app/src/pages/forms-inspector.ts b/app/src/pages/forms-inspector.ts index aed5c06f..6d3f9df2 100644 --- a/app/src/pages/forms-inspector.ts +++ b/app/src/pages/forms-inspector.ts @@ -13,33 +13,32 @@ import { signal, untracked, } from '@angular/core'; -import { JsonPipe } from '@angular/common'; import type { DevframeRpcClient } from 'devframe/client'; import { hostPageId } from '../page-id'; import { actionAllowed, actionBlockedMessage, panelConfig } from '../devtools-config'; import { LimitNote } from '../ui/limit-note'; -import { FormsFieldDetail } from './forms-field-detail'; +import { FormsActionBar } from './forms-action-bar'; +import { FormsFields, matchesChip, type Chip, type FieldRow } from './forms-fields'; +import { FormsList } from './forms-list'; import { FormsLint, FormsSubmit } from './forms-report'; +import { FormsSetupErrors } from './forms-setup-errors'; import { FormsTimeline } from './forms-timeline'; import { FormsWebMcp, FormsWebMcpOthers } from './forms-webmcp'; import { + BADGE_STYLES, FORMS_STYLES, KIND_LABELS, - SOURCE_LABELS, actionMessage, formAction, pageOf, - redactLabel, type CollectedForm, type FormEvent, - type FormFieldError, type FormFieldNode, type FormSetupError, type WebMcpPage, } from './forms-types'; type Tab = 'fields' | 'timeline' | 'submit' | 'lint'; -type Chip = 'invalid' | 'dirty' | 'touched' | 'disabled' | 'hidden-error'; const TABS: { id: Tab; label: string }[] = [ { id: 'fields', label: 'Fields' }, @@ -48,29 +47,6 @@ const TABS: { id: Tab; label: string }[] = [ { id: 'lint', label: 'Lint' }, ]; -const CHIPS: { id: Chip; label: string }[] = [ - { id: 'invalid', label: 'Invalid' }, - { id: 'dirty', label: 'Dirty' }, - { id: 'touched', label: 'Touched' }, - { id: 'disabled', label: 'Disabled' }, - { id: 'hidden-error', label: 'Error not shown' }, -]; - -function matchesChip(node: FormFieldNode, chip: Chip): boolean { - switch (chip) { - case 'invalid': - return node.errors.length > 0; - case 'dirty': - return node.dirty && node.type === 'control'; - case 'touched': - return node.touched && node.type === 'control'; - case 'disabled': - return node.status === 'DISABLED'; - case 'hidden-error': - return node.dom?.errorShown === false; - } -} - interface FormsSnapshot { forms?: CollectedForm[]; events?: FormEvent[]; @@ -80,11 +56,6 @@ interface FormsSnapshot { setupErrors?: FormSetupError[]; } -interface FieldRow { - node: FormFieldNode; - depth: number; -} - function countErrors(node: FormFieldNode): number { return node.errors.length + (node.children ?? []).reduce((sum, c) => sum + countErrors(c), 0); } @@ -97,8 +68,10 @@ function countFields(node: FormFieldNode): number { @Component({ selector: 'app-forms-inspector', imports: [ - JsonPipe, - FormsFieldDetail, + FormsActionBar, + FormsFields, + FormsList, + FormsSetupErrors, FormsTimeline, FormsSubmit, FormsLint, @@ -113,26 +86,7 @@ function countFields(node: FormFieldNode): number { errors, a change timeline, submit explanations and a lint. Development builds only.

@if (pageSetupErrors().length) { -
-

- Angular reported {{ pageSetupErrors().length }} forms setup - {{ pageSetupErrors().length === 1 ? 'error' : 'errors' }} -

-

- A form with a setup error can be missing from the list or behave unlike its template. - Check the directives and value accessors it names. -

-
    - @for (error of pageSetupErrors(); track $index) { -
  • - {{ error.message }} - @if (setupErrorPages()) { - on page {{ error.pageId }} - } -
  • - } -
-
+ } @if (!rpc()) {
@@ -173,47 +127,14 @@ function countFields(node: FormFieldNode): number {
} @else {
- + @if (missing(); as label) {
@@ -284,80 +205,18 @@ function countFields(node: FormFieldNode): number { [signalForm]="form.kind === 'signal'" /> -
-
- - - - - - - @if (snapshot()) { - - } - - - -
- @if (!canWrite()) { -

{{ writesOff }}

- } -

{{ message() }}

-
+
@for (tab of tabs; track tab.id) { @@ -382,228 +241,22 @@ function countFields(node: FormFieldNode): number { > @switch (tab_()) { @case ('fields') { -
- -
- Show only fields that are - @for (chip of chips; track chip.id) { - - } -
-
-

{{ filterStatus() }}

- -
- - - - - - - - - - - - @for (row of rows(); track row.node.path) { - - - - - - - - @if (row.node.truncated) { - - - - } - } @empty { - - - - } - -
FieldValueStatusStateErrors
- - {{ row.node.type }} - - @if (row.node.type === 'control') { - {{ row.node.value | json }} - @if (row.node.uncommitted !== undefined) { -
- typed {{ row.node.uncommitted | json }}, not in the model yet -
- } - @if (row.node.defaultValue !== undefined) { -
- resets to {{ row.node.defaultValue | json }} -
- } - } -
- @if (row.node.materialized === false) { - not created yet - } @else { - {{ - row.node.status - }} - } - - @if (row.node.touched) { - touched - } - @if (row.node.dirty) { - {{ - row.node.changed === false ? 'dirty, unchanged' : 'dirty' - }} - } - @if (row.node.skipped) { - not validated ({{ row.node.skipped }}) - } - @if (row.node.stale?.length) { - stale: {{ row.node.stale!.join(', ') }} - } - @if (row.node.dom?.drift !== undefined) { - view out of sync - } - @if (row.node.redacted) { - redacted: {{ redactLabel(row.node.redacted) }} - } - @if (row.node.required) { - required - } - @if (row.node.readonly) { - readonly - } - @if (row.node.hidden) { - hidden - } - @if (row.node.updateOn) { - updates on {{ row.node.updateOn }} - } - @if (row.node.debouncing) { - debouncing - } - @if (row.node.validators?.sync) { - validators - } - @if (row.node.validators?.async) { - async validator - } - @for (rule of constraintList(row.node); track rule) { - {{ rule }} - } - @if (row.node.accessor) { - {{ row.node.accessor }} - } - @if (row.node.name) { - name {{ row.node.name }} - } - @for (value of row.node.metadata ?? []; track $index) { - metadata {{ value | json }} - } - @for (reason of row.node.disabledReasons ?? []; track $index) { - disabled: {{ reason }} - } - - @for (error of row.node.errors; track $index) { -
- {{ errorText(row.node, error) }} - {{ error.kind }} - @if (error.kind === 'standardSchema' && error.params?.['path']) { - at {{ error.params!['path'] }} - } - @if (error.source) { - {{ sourceText(error) }} - } -
- } - @if (row.node.errors.length && row.node.dom?.errorShown === false) { -
not shown to the user
- } -
- {{ row.node.truncated }} more fields under - {{ row.node.path || 'the form' }} not shown -
-

- @if (filter()) { - No field path matches "{{ filter() }}". - } @else { - No field matches the selected filters. - } -

- @if (filtering()) { - - } -
-
- - @if (selectedNode(); as node) { - - } + } @case ('timeline') { input { - flex: 1 1 auto; - width: 100%; - padding-left: 34px; - } - .search-icon { - position: absolute; - top: 50%; - left: 12px; - width: 14px; - height: 14px; - transform: translateY(-50%); - fill: none; - stroke: var(--text-3); - stroke-width: 2.2; - stroke-linecap: round; - pointer-events: none; - } - .search:focus-within .search-icon { - stroke: var(--accent); - } :host { display: block; } @@ -714,145 +308,6 @@ function countFields(node: FormFieldNode): number { gap: 16px; align-items: start; } - .sidebar { - min-width: 0; - padding: 8px; - background: var(--surface); - border: 1px solid var(--border); - border-radius: var(--radius); - animation: enter 0.35s var(--ease) both; - } - .list-heading { - display: flex; - gap: 8px; - align-items: center; - margin: 4px 8px 8px; - color: var(--text-3); - font-size: 11px; - font-weight: 600; - letter-spacing: 0.08em; - text-transform: uppercase; - } - .list-count { - padding: 0 6px; - border-radius: 99px; - background: var(--surface-3); - color: var(--text-2); - font-size: 11px; - letter-spacing: 0; - line-height: 18px; - font-variant-numeric: tabular-nums; - } - .form-list { - display: grid; - gap: 2px; - align-content: start; - margin: 0; - padding: 0; - list-style: none; - } - .form-list > li { - /* A page with many forms skips layout and paint for the entries out of view. */ - content-visibility: auto; - contain-intrinsic-size: auto 52px; - } - .form-item { - width: 100%; - display: grid; - grid-template-columns: 8px minmax(0, 1fr) auto; - grid-template-areas: 'dot label count' '. kind kind'; - gap: 2px 10px; - align-items: center; - padding: 8px 10px; - border: 0; - border-radius: var(--radius-sm); - background: transparent; - color: var(--text); - font: inherit; - text-align: left; - cursor: pointer; - transition: - background-color 150ms var(--ease), - color 150ms var(--ease), - box-shadow 150ms var(--ease); - } - .form-item:hover { - background: var(--surface-2); - } - .form-item:active { - background: var(--surface-3); - } - .form-item.active { - background: var(--accent-soft); - box-shadow: inset 2px 0 0 var(--accent); - color: var(--text-strong); - } - .form-item:focus-visible { - /* Inside the entry: its paint containment would clip a ring drawn outside. */ - outline: 2px solid var(--accent); - outline-offset: -2px; - } - .form-item .dot { - grid-area: dot; - } - .form-item .label { - grid-area: label; - min-width: 0; - overflow: hidden; - font-size: 13px; - font-weight: 500; - text-overflow: ellipsis; - white-space: nowrap; - } - .form-item .kind { - grid-area: kind; - min-width: 0; - overflow: hidden; - color: var(--text-3); - font-size: 12px; - text-overflow: ellipsis; - white-space: nowrap; - } - .form-item .id { - font-family: var(--font-mono); - font-size: 11.5px; - } - .form-item.active .kind { - color: var(--text-2); - } - .form-item .count { - grid-area: count; - min-width: 20px; - padding: 0 7px; - border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); - border-radius: 99px; - background: color-mix(in srgb, var(--danger) 12%, var(--surface)); - color: var(--danger-text); - font-size: 11px; - font-weight: 600; - line-height: 18px; - text-align: center; - font-variant-numeric: tabular-nums; - } - .dot { - width: 8px; - height: 8px; - border-radius: 50%; - background: var(--ok); - box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 15%, transparent); - } - .dot[data-status='INVALID'] { - background: var(--danger); - box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 15%, transparent); - } - .dot[data-status='PENDING'] { - background: var(--warn); - box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 15%, transparent); - } - .dot[data-status='DISABLED'] { - background: var(--text-3); - box-shadow: none; - } .detail { display: grid; gap: 16px; @@ -900,26 +355,6 @@ function countFields(node: FormFieldNode): number { .gone p { margin: 0; } - .page-toggle { - display: flex; - gap: 8px; - align-items: center; - min-height: 32px; - margin: 0 8px 8px; - color: var(--text-2); - font-size: 13px; - cursor: pointer; - } - .page-toggle input { - width: 16px; - height: 16px; - margin: 0; - accent-color: var(--accent); - } - .page-toggle input:focus-visible { - outline: 2px solid var(--accent); - outline-offset: 2px; - } .error-summary { min-width: 0; padding: 8px 12px; @@ -978,71 +413,7 @@ function countFields(node: FormFieldNode): number { .totals b.has-errors { color: var(--danger); } - /* Opaque tints so a selected or hovered row behind the badge cannot lower its contrast. */ - .badge { - display: inline-block; - padding: 0 8px; - border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent); - border-radius: 99px; - background: color-mix(in srgb, var(--ok) 12%, var(--surface)); - color: var(--ok-text); - font-size: 11px; - font-weight: 600; - letter-spacing: 0.04em; - line-height: 20px; - white-space: nowrap; - } - .summary > .badge { - line-height: 22px; - } - .badge[data-status='INVALID'] { - border-color: color-mix(in srgb, var(--danger) 30%, transparent); - background: color-mix(in srgb, var(--danger) 12%, var(--surface)); - color: var(--danger-text); - } - .badge[data-status='PENDING'] { - border-color: color-mix(in srgb, var(--warn) 30%, transparent); - background: color-mix(in srgb, var(--warn) 12%, var(--surface)); - color: var(--warn-text); - } - .badge[data-status='DISABLED'] { - border-color: var(--border-strong); - background: var(--surface-2); - color: var(--text-2); - } - .action-bar { - display: flex; - flex-direction: column; - gap: 8px; - padding-bottom: 16px; - border-bottom: 1px solid var(--border); - } - .actions { - display: flex; - flex-wrap: wrap; - gap: 8px; - align-items: center; - } - .divider { - width: 1px; - height: 20px; - background: var(--border-strong); - } - .spacer { - flex: 1 1 0; - } - .actions .small:not(.primary):not(.danger) { - max-width: 240px; - } - .small.on { - background: var(--accent-soft); - border-color: var(--accent-line); - color: var(--text-strong); - } - .status:empty { - height: 0; - margin-top: -8px; - } + ${BADGE_STYLES} .tabs { display: inline-flex; justify-self: start; @@ -1091,269 +462,6 @@ function countFields(node: FormFieldNode): number { min-width: 0; animation: enter 0.35s var(--ease) both; } - .filters { - display: flex; - flex-wrap: wrap; - gap: 8px 12px; - align-items: center; - } - .chips { - display: flex; - flex-wrap: wrap; - gap: 6px; - min-width: 0; - margin: 0; - padding: 0; - border: 0; - } - .chips label { - position: relative; - display: inline-flex; - align-items: center; - height: 28px; - padding: 0 12px; - border: 1px solid var(--control-border); - border-radius: 99px; - background: var(--surface-2); - color: var(--text-2); - font-size: 12px; - font-weight: 500; - white-space: nowrap; - cursor: pointer; - user-select: none; - transition: - background-color 150ms var(--ease), - border-color 150ms var(--ease), - color 150ms var(--ease); - } - .chips label:hover { - color: var(--text); - border-color: var(--text-3); - } - .chips input { - position: absolute; - inset: 0; - width: 100%; - height: 100%; - margin: 0; - opacity: 0; - cursor: pointer; - } - .chips label:has(input:checked) { - border-color: var(--accent-line); - background: var(--accent-soft); - color: var(--accent); - } - .chips label:has(input:focus-visible) { - outline: 2px solid var(--accent); - outline-offset: 2px; - } - .filter { - flex: 1 1 220px; - min-width: 0; - height: 34px; - padding: 0 12px 0 34px; - background: var(--bg); - border: 1px solid var(--control-border); - border-radius: var(--radius-sm); - color: var(--text); - font: inherit; - font-size: 13px; - transition: - border-color 150ms var(--ease), - box-shadow 150ms var(--ease); - } - .filter::placeholder { - color: var(--text-3); - } - .filter:hover { - border-color: color-mix(in srgb, var(--text-3) 55%, var(--control-border)); - } - .filter:focus, - .filter:focus-visible { - outline: none; - border-color: var(--accent); - box-shadow: 0 0 0 3px var(--accent-soft); - } - .table-scroll { - overflow-x: auto; - border: 1px solid var(--border); - border-radius: var(--radius-sm); - } - .table-scroll:focus-visible { - outline: 2px solid var(--accent); - outline-offset: 2px; - } - .fields { - width: 100%; - min-width: 680px; - border-collapse: collapse; - font-size: 13px; - } - .fields th, - .fields td { - padding: 8px 12px; - border-bottom: 1px solid var(--border); - text-align: left; - vertical-align: top; - line-height: 20px; - } - .fields tbody tr:last-child > * { - border-bottom: 0; - } - .fields thead th { - background: var(--surface-2); - color: var(--text-3); - font-size: 11px; - font-weight: 600; - letter-spacing: 0.06em; - line-height: 16px; - text-transform: uppercase; - white-space: nowrap; - } - .fields tbody th { - color: var(--text); - font-weight: 500; - white-space: nowrap; - } - .fields tbody tr { - transition: background-color 150ms var(--ease); - } - .fields tbody tr:hover { - background: var(--surface-2); - } - .fields tbody tr.invalid > th { - box-shadow: inset 2px 0 0 color-mix(in srgb, var(--danger) 60%, transparent); - } - .fields tbody tr:has(.field[aria-pressed='true']) { - background: var(--accent-soft); - } - .fields tbody tr:has(.field[aria-pressed='true']) > th { - box-shadow: inset 2px 0 0 var(--accent); - color: var(--text-strong); - } - .name { - max-width: 280px; - } - .field { - display: inline-block; - max-width: 200px; - padding: 0; - overflow: hidden; - border: none; - border-radius: 4px; - background: none; - color: inherit; - font-family: var(--font-mono); - font-size: 12.5px; - font-weight: 500; - line-height: 20px; - text-align: left; - text-overflow: ellipsis; - vertical-align: top; - white-space: nowrap; - cursor: pointer; - transition: color 150ms var(--ease); - } - .field:hover { - color: var(--accent-hover); - text-decoration: underline; - text-underline-offset: 3px; - } - .field[aria-pressed='true'] { - color: var(--accent); - } - .field:focus-visible { - outline: 2px solid var(--accent); - outline-offset: 2px; - } - .type { - margin-left: 8px; - color: var(--text-3); - font-size: 11px; - font-weight: 400; - vertical-align: top; - } - .value { - min-width: 140px; - max-width: 320px; - } - .value code, - .errors code { - color: #fde68a; - overflow-wrap: anywhere; - - @include m.light { - color: var(--accent); - } - } - .value .muted { - margin-top: 2px; - font-size: 12px; - } - .status-cell { - white-space: nowrap; - } - .flags { - min-width: 160px; - } - .flags span { - display: inline-block; - margin: 0 4px 4px 0; - padding: 0 8px; - border: 1px solid var(--border); - border-radius: 99px; - background: var(--surface-2); - color: var(--text-2); - font-size: 11px; - line-height: 18px; - white-space: nowrap; - } - .flags span.warn { - border-color: color-mix(in srgb, var(--warn) 30%, transparent); - background: color-mix(in srgb, var(--warn) 12%, var(--surface)); - color: var(--warn-text); - } - .errors { - min-width: 180px; - } - .errors div { - color: var(--danger); - overflow-wrap: anywhere; - } - .errors div + div { - margin-top: 4px; - } - .errors .kind-tag { - margin-left: 6px; - color: var(--text-3); - font-size: 11px; - } - .source { - margin-left: 6px; - color: var(--text-2); - font-size: 11px; - } - .errors .unseen { - color: var(--warn); - font-size: 11px; - } - .truncated { - color: var(--text-3); - font-size: 12px; - font-style: italic; - } - .fields .no-match { - padding: 24px 12px; - color: var(--text-2); - text-align: center; - } - .fields .no-match p { - margin: 0 0 10px; - } - .fields .no-match p:last-child { - margin-bottom: 0; - } .empty { display: grid; justify-items: center; @@ -1385,10 +493,6 @@ function countFields(node: FormFieldNode): number { .layout { grid-template-columns: minmax(0, 1fr); } - .form-list { - max-height: 240px; - overflow-y: auto; - } } @media (max-width: 480px) { .detail { @@ -1398,10 +502,6 @@ function countFields(node: FormFieldNode): number { flex-basis: 100%; margin-left: 0; } - .spacer, - .divider { - display: none; - } } `, }) @@ -1409,7 +509,6 @@ export class FormsInspector { rpc = input(null); focus = input<{ id: string } | null>(null); readonly canWrite = computed(() => actionAllowed(this.rpc(), 'forms')); - protected readonly redactLabel = redactLabel; protected readonly writesOff = actionBlockedMessage('forms'); readonly focusHandled = output(); @@ -1435,7 +534,6 @@ export class FormsInspector { }); readonly filter = signal(''); readonly tabs = TABS; - readonly chips = CHIPS; readonly tab_ = signal('fields'); readonly active = signal(new Set()); /** True while the path search or a chip hides fields, the same test `rows` applies. */ @@ -1705,15 +803,6 @@ export class FormsInspector { ); } - toggleChip(chip: Chip) { - this.active.update((set) => { - const next = new Set(set); - if (next.has(chip)) next.delete(chip); - else next.add(chip); - return next; - }); - } - async act(action: string, extra: Record = {}) { const form = this.selected(); if (!form) return; @@ -1747,11 +836,6 @@ export class FormsInspector { queueMicrotask(() => host.querySelector(`#forms-tab-${order[next]}`)?.focus()); } - sourceText(error: FormFieldError) { - const label = SOURCE_LABELS[error.source ?? ''] ?? error.source ?? ''; - return error.from !== undefined ? `${label} on ${error.from || 'the form'}` : label; - } - /** Resets the path search and the chips, then hands focus back to the search field. */ clearFilters(search: HTMLInputElement) { this.filter.set(''); @@ -1762,10 +846,6 @@ export class FormsInspector { search.focus(); } - onFilter(event: Event) { - this.filter.set((event.target as HTMLInputElement).value); - } - highlight(formId: string | null, path: string) { const client = this.rpc(); if (!client) return; @@ -1777,14 +857,4 @@ export class FormsInspector { kindLabel(kind: CollectedForm['kind']) { return KIND_LABELS[kind]; } - - constraintList(node: FormFieldNode) { - return Object.entries(node.constraints ?? {}).map(([name, value]) => `${name} ${value}`); - } - - errorText(node: FormFieldNode, error: FormFieldError) { - return /^[a-z]/.test(error.message) - ? `${node.key || 'The form'} ${error.message}` - : error.message; - } } diff --git a/app/src/pages/forms-list.ts b/app/src/pages/forms-list.ts new file mode 100644 index 00000000..e5a58397 --- /dev/null +++ b/app/src/pages/forms-list.ts @@ -0,0 +1,234 @@ +import { Component, input, model, output } from '@angular/core'; +import { KIND_LABELS, type CollectedForm } from './forms-types'; + +/** The list of forms on the shown pages, with the "All pages" toggle. */ +@Component({ + selector: 'app-forms-list', + template: ` + + `, + styles: ` + :host { + display: block; + min-width: 0; + } + .sidebar { + min-width: 0; + padding: 8px; + background: var(--surface); + border: 1px solid var(--border); + border-radius: var(--radius); + animation: enter 0.35s var(--ease) both; + } + .list-heading { + display: flex; + gap: 8px; + align-items: center; + margin: 4px 8px 8px; + color: var(--text-3); + font-size: 11px; + font-weight: 600; + letter-spacing: 0.08em; + text-transform: uppercase; + } + .list-count { + padding: 0 6px; + border-radius: 99px; + background: var(--surface-3); + color: var(--text-2); + font-size: 11px; + letter-spacing: 0; + line-height: 18px; + font-variant-numeric: tabular-nums; + } + .form-list { + display: grid; + gap: 2px; + align-content: start; + margin: 0; + padding: 0; + list-style: none; + } + .form-list > li { + /* A page with many forms skips layout and paint for the entries out of view. */ + content-visibility: auto; + contain-intrinsic-size: auto 52px; + } + .form-item { + width: 100%; + display: grid; + grid-template-columns: 8px minmax(0, 1fr) auto; + grid-template-areas: 'dot label count' '. kind kind'; + gap: 2px 10px; + align-items: center; + padding: 8px 10px; + border: 0; + border-radius: var(--radius-sm); + background: transparent; + color: var(--text); + font: inherit; + text-align: left; + cursor: pointer; + transition: + background-color 150ms var(--ease), + color 150ms var(--ease), + box-shadow 150ms var(--ease); + } + .form-item:hover { + background: var(--surface-2); + } + .form-item:active { + background: var(--surface-3); + } + .form-item.active { + background: var(--accent-soft); + box-shadow: inset 2px 0 0 var(--accent); + color: var(--text-strong); + } + .form-item:focus-visible { + /* Inside the entry: its paint containment would clip a ring drawn outside. */ + outline: 2px solid var(--accent); + outline-offset: -2px; + } + .form-item .dot { + grid-area: dot; + } + .form-item .label { + grid-area: label; + min-width: 0; + overflow: hidden; + font-size: 13px; + font-weight: 500; + text-overflow: ellipsis; + white-space: nowrap; + } + .form-item .kind { + grid-area: kind; + min-width: 0; + overflow: hidden; + color: var(--text-3); + font-size: 12px; + text-overflow: ellipsis; + white-space: nowrap; + } + .form-item .id { + font-family: var(--font-mono); + font-size: 11.5px; + } + .form-item.active .kind { + color: var(--text-2); + } + .form-item .count { + grid-area: count; + min-width: 20px; + padding: 0 7px; + border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); + border-radius: 99px; + background: color-mix(in srgb, var(--danger) 12%, var(--surface)); + color: var(--danger-text); + font-size: 11px; + font-weight: 600; + line-height: 18px; + text-align: center; + font-variant-numeric: tabular-nums; + } + .dot { + width: 8px; + height: 8px; + border-radius: 50%; + background: var(--ok); + box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 15%, transparent); + } + .dot[data-status='INVALID'] { + background: var(--danger); + box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 15%, transparent); + } + .dot[data-status='PENDING'] { + background: var(--warn); + box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 15%, transparent); + } + .dot[data-status='DISABLED'] { + background: var(--text-3); + box-shadow: none; + } + .page-toggle { + display: flex; + gap: 8px; + align-items: center; + min-height: 32px; + margin: 0 8px 8px; + color: var(--text-2); + font-size: 13px; + cursor: pointer; + } + .page-toggle input { + width: 16px; + height: 16px; + margin: 0; + accent-color: var(--accent); + } + .page-toggle input:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + @media (max-width: 720px) { + .form-list { + max-height: 240px; + overflow-y: auto; + } + } + `, +}) +export class FormsList { + readonly forms = input.required(); + readonly selectedId = input(null); + readonly counts = input.required>(); + /** Offer the "All pages" checkbox (the panel runs in one tab and other tabs report forms). */ + readonly showToggle = input(false); + readonly allPages = model(false); + readonly selectForm = output(); + + kindLabel(kind: CollectedForm['kind']) { + return KIND_LABELS[kind]; + } +} diff --git a/app/src/pages/forms-setup-errors.ts b/app/src/pages/forms-setup-errors.ts new file mode 100644 index 00000000..0bc98d4f --- /dev/null +++ b/app/src/pages/forms-setup-errors.ts @@ -0,0 +1,73 @@ +import { Component, input } from '@angular/core'; +import type { FormSetupError } from './forms-types'; + +/** The notice listing the forms setup errors (NG01xxx) Angular logged on the shown pages. */ +@Component({ + selector: 'app-forms-setup-errors', + template: ` +
+

+ Angular reported {{ errors().length }} forms setup + {{ errors().length === 1 ? 'error' : 'errors' }} +

+

+ A form with a setup error can be missing from the list or behave unlike its template. Check + the directives and value accessors it names. +

+
    + @for (error of errors(); track $index) { +
  • + {{ error.message }} + @if (showPages()) { + on page {{ error.pageId }} + } +
  • + } +
+
+ `, + styles: ` + @use 'mixins' as m; + + :host { + display: block; + } + .setup-errors { + display: grid; + gap: 4px; + margin: 0 0 12px; + padding: 10px 12px; + border: 1px solid; + @include m.tint(warn); + border-radius: var(--radius-sm); + font-size: 13px; + line-height: 1.5; + } + .setup-errors p { + margin: 0; + } + .setup-title { + font-weight: 600; + } + .setup-errors ul { + display: grid; + gap: 2px; + margin: 0; + padding: 0 0 0 16px; + min-width: 0; + } + .setup-errors code { + font-family: var(--font-mono); + font-size: 12.5px; + overflow-wrap: anywhere; + } + .setup-page { + margin-left: 6px; + } + `, +}) +export class FormsSetupErrors { + readonly errors = input.required(); + /** Errors come from more than one page, so each names its page. */ + readonly showPages = input(false); +} diff --git a/app/src/pages/forms-types.ts b/app/src/pages/forms-types.ts index c24afbe0..4e0a2d85 100644 --- a/app/src/pages/forms-types.ts +++ b/app/src/pages/forms-types.ts @@ -407,3 +407,39 @@ export const FORMS_STYLES = ` animation: spin 0.8s linear infinite; } `; + +/** Status badges (VALID, INVALID, PENDING, DISABLED) shared by the form summary and the field table. */ +export const BADGE_STYLES = ` + /* Opaque tints so a selected or hovered row behind the badge cannot lower its contrast. */ + .badge { + display: inline-block; + padding: 0 8px; + border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent); + border-radius: 99px; + background: color-mix(in srgb, var(--ok) 12%, var(--surface)); + color: var(--ok-text); + font-size: 11px; + font-weight: 600; + letter-spacing: 0.04em; + line-height: 20px; + white-space: nowrap; + } + .summary > .badge { + line-height: 22px; + } + .badge[data-status='INVALID'] { + border-color: color-mix(in srgb, var(--danger) 30%, transparent); + background: color-mix(in srgb, var(--danger) 12%, var(--surface)); + color: var(--danger-text); + } + .badge[data-status='PENDING'] { + border-color: color-mix(in srgb, var(--warn) 30%, transparent); + background: color-mix(in srgb, var(--warn) 12%, var(--surface)); + color: var(--warn-text); + } + .badge[data-status='DISABLED'] { + border-color: var(--border-strong); + background: var(--surface-2); + color: var(--text-2); + } +`; From f3188580b065fdf1031784514939665b152f4715 Mon Sep 17 00:00:00 2001 From: erKam Date: Sat, 7 Nov 2026 16:23:41 +0000 Subject: [PATCH 02/14] feat(forms): edit a field's value, touched and dirty state in its row Each control in the Fields view gets an Edit button that opens an editor under its row: a value input read as the current value's type, and Touched and Dirty checkboxes that mark the control touched or untouched, dirty or pristine. The writes go through the same gated form actions as the field details, so Edit is off when actions.forms is false, and a refused write puts the checkbox back. --- app/src/__tests__/forms-panels.test.ts | 95 +++++++++ app/src/pages/forms-fields.ts | 248 +++++++++++++++++++++- apps/docs/src/content/inspectors/forms.md | 6 + packages/devtools/CHANGELOG.md | 1 + 4 files changed, 349 insertions(+), 1 deletion(-) diff --git a/app/src/__tests__/forms-panels.test.ts b/app/src/__tests__/forms-panels.test.ts index f9869d41..3d1d0237 100644 --- a/app/src/__tests__/forms-panels.test.ts +++ b/app/src/__tests__/forms-panels.test.ts @@ -1055,3 +1055,98 @@ describe('FormsTimeline', () => { expect(box.checked).toBe(true); }); }); + +describe('FormsFields inline editing', () => { + function client(call: Call, meta: Record = {}): DevframeRpcClient { + const rpc = { + call, + callEvent: () => Promise.resolve(), + sharedState: () => Promise.resolve({ value: () => ({ forms: [form] }), on: () => () => {} }), + }; + return { connectionMeta: meta, scope: () => ({ rpc }) } as unknown as DevframeRpcClient; + } + + it('edits the value, touched and dirty of a control in its row, then hands focus back', async () => { + const calls: Record[] = []; + const fixture = TestBed.createComponent(FormsInspector); + fixture.componentRef.setInput( + 'rpc', + client((name, arg) => { + if (name === 'request-form-action') calls.push(arg); + return Promise.resolve({ ok: true, message: 'Done.' }); + }), + ); + document.body.append(fixture.nativeElement); + await settle(fixture); + const host = fixture.nativeElement as HTMLElement; + const edit = button(fixture, 'Edit email'); + expect(edit.getAttribute('aria-expanded')).toBe('false'); + + edit.click(); + await settle(fixture); + expect(edit.getAttribute('aria-expanded')).toBe('true'); + const input = host.querySelector('#forms-inline-value')!; + expect(input.value).toBe('x'); + expect(document.activeElement).toBe(input); + + input.value = 'a@b.c'; + input.dispatchEvent(new Event('input')); + input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter' })); + await settle(fixture); + expect(calls.at(-1)).toEqual({ + action: 'set-value', + formId: form.id, + path: 'email', + value: 'a@b.c', + coerce: true, + mode: 'user', + }); + expect(host.querySelector('.edit-row [role="status"]')?.textContent).toContain('Done.'); + + const [touched, dirty] = Array.from( + host.querySelectorAll('.edit-row input[type="checkbox"]'), + ); + touched.click(); + await settle(fixture); + expect(calls.at(-1)).toEqual({ action: 'mark-touched', formId: form.id, path: 'email' }); + dirty.click(); + await settle(fixture); + expect(calls.at(-1)).toEqual({ action: 'mark-dirty', formId: form.id, path: 'email' }); + + button(fixture, 'Done').click(); + await settle(fixture); + expect(host.querySelector('#forms-inline-editor')).toBeNull(); + expect(document.activeElement).toBe(edit); + }); + + it('puts a checkbox back when the page refuses the write', async () => { + const fixture = TestBed.createComponent(FormsInspector); + fixture.componentRef.setInput( + 'rpc', + client(() => Promise.resolve({ ok: false, error: 'No field at email.' })), + ); + document.body.append(fixture.nativeElement); + await settle(fixture); + button(fixture, 'Edit email').click(); + await settle(fixture); + const host = fixture.nativeElement as HTMLElement; + const touched = host.querySelector('.edit-row input[type="checkbox"]')!; + touched.click(); + await settle(fixture); + expect(touched.checked).toBe(false); + expect(text(fixture)).toContain('No field at email.'); + }); + + it('turns Edit off when form writes are off', async () => { + const fixture = TestBed.createComponent(FormsInspector); + fixture.componentRef.setInput( + 'rpc', + client(fail, { configs: { pangular: { actions: { forms: false } } } }), + ); + document.body.append(fixture.nativeElement); + await settle(fixture); + const edit = button(fixture, 'Edit email'); + expect(edit.disabled).toBe(true); + expect(edit.getAttribute('aria-describedby')).toBe('forms-writes-off'); + }); +}); diff --git a/app/src/pages/forms-fields.ts b/app/src/pages/forms-fields.ts index 4d6ada8d..f8e0c0e4 100644 --- a/app/src/pages/forms-fields.ts +++ b/app/src/pages/forms-fields.ts @@ -1,11 +1,26 @@ -import { Component, input, model, output } from '@angular/core'; +import { + Component, + ElementRef, + Injector, + afterNextRender, + computed, + inject, + input, + linkedSignal, + model, + output, + signal, +} from '@angular/core'; import { JsonPipe } from '@angular/common'; import type { DevframeRpcClient } from 'devframe/client'; +import { actionAllowed } from '../devtools-config'; import { FormsFieldDetail } from './forms-field-detail'; import { BADGE_STYLES, FORMS_STYLES, SOURCE_LABELS, + actionMessage, + formAction, redactLabel, type CollectedForm, type FormFieldError, @@ -37,6 +52,17 @@ export function matchesChip(node: FormFieldNode, chip: Chip): boolean { } } +/** The text the inline editor starts with: a string as it is, anything else as JSON. */ +export function draftOf(value: unknown): string { + if (typeof value === 'string') return value; + if (value === undefined) return ''; + try { + return JSON.stringify(value) ?? ''; + } catch { + return ''; + } +} + export interface FieldRow { node: FormFieldNode; depth: number; @@ -118,6 +144,22 @@ export interface FieldRow { @if (row.node.type === 'control') { {{ row.node.value | json }} + @if (row.node.materialized !== false) { + + } @if (row.node.uncommitted !== undefined) {
typed {{ row.node.uncommitted | json }} + @if (editing() === row.node.path) { + + +
+ @if (!row.node.redacted) { + + + + } @else { + The value is redacted ({{ redactLabel(row.node.redacted) }}), so it cannot + be edited here. + } + + + +
+

{{ editMessage() }}

+ + + } @if (row.node.truncated) { actionAllowed(this.rpc(), 'forms')); + private readonly formId = computed(() => this.form().id); + /** The path of the control whose inline editor is open; closes when the form changes. */ + readonly editing = linkedSignal({ + source: this.formId, + computation: () => null, + }); + readonly draft = signal(''); + readonly editMessage = linkedSignal({ source: this.editing, computation: () => '' }); + private readonly host = inject>(ElementRef); + private readonly injector = inject(Injector); + + /** Opens the inline editor of a control with its current value, or closes it. */ + toggleEdit(node: FormFieldNode) { + if (this.editing() === node.path) { + this.stopEdit(); + return; + } + this.draft.set(draftOf(node.value)); + this.editing.set(node.path); + afterNextRender( + () => + this.host.nativeElement.querySelector('#forms-inline-editor input')?.focus(), + { injector: this.injector }, + ); + } + + /** Closes the inline editor and hands focus back to its Edit button. */ + stopEdit(event?: Event) { + event?.stopPropagation(); + const path = this.editing(); + if (path === null) return; + const host = this.host.nativeElement; + const button = host + .querySelector('#forms-inline-editor') + ?.closest('tr') + ?.previousElementSibling?.querySelector('button.edit'); + this.editing.set(null); + button?.focus(); + } + + async saveValue(node: FormFieldNode) { + const formId = this.form().id; + const result = await formAction(this.rpc(), { + action: 'set-value', + formId, + path: node.path, + value: this.draft(), + coerce: true, + mode: 'user', + }); + if (this.form().id !== formId || this.editing() !== node.path) return; + this.editMessage.set(actionMessage(result)); + } + + /** Marks a control touched or untouched, dirty or pristine, from its checkbox. */ + async mark(node: FormFieldNode, flag: 'touched' | 'dirty', event: Event) { + const box = event.target as HTMLInputElement; + const on = box.checked; + const action = + flag === 'touched' + ? on + ? 'mark-touched' + : 'mark-untouched' + : on + ? 'mark-dirty' + : 'mark-pristine'; + const formId = this.form().id; + const result = await formAction(this.rpc(), { action, formId, path: node.path }); + // A refused write changed nothing, so the checkbox goes back to the reported state. + if (!result.ok) box.checked = !on; + if (this.form().id !== formId || this.editing() !== node.path) return; + this.editMessage.set(actionMessage(result)); + } toggleChip(chip: Chip) { this.active.update((set) => { diff --git a/apps/docs/src/content/inspectors/forms.md b/apps/docs/src/content/inspectors/forms.md index ebf4530d..0e7dc5f5 100644 --- a/apps/docs/src/content/inspectors/forms.md +++ b/apps/docs/src/content/inspectors/forms.md @@ -53,6 +53,12 @@ Each field shows its value, status, touched and dirty state, and errors. Extra f Filter by path, or with the **Invalid**, **Dirty**, **Touched**, **Disabled** and **Error not shown** chips. If the filters hide every field, click **Clear filters** to reset the path filter and the chips. Focus returns to the path filter. Hover a field to highlight its input in the page. +### Edit a field in its row + +Click **Edit** next to a control's value to open an editor under its row. Type a value and press Enter or click **Set value**. The value is read as the current value's type, so `42` sets a number on a number field. Tick or untick **Touched** and **Dirty** to mark the control touched or untouched, dirty or pristine. The page answers in a status line under the editor. If it refuses, the checkbox goes back to the reported state. Press Escape or click **Done** to close the editor. Focus returns to **Edit**. + +A redacted field keeps its value hidden and has no value editor, but you can still change **Touched** and **Dirty**. **Edit** is turned off when [`actions.forms`](../getting-started/configuration.md#actions) is `false`, like the other form writes. Agents make the same changes with `pangular:run-form-action` (`set-value`, `mark-touched`, `mark-untouched`, `mark-dirty`, `mark-pristine`). + ### Error sources Each error says where it comes from: diff --git a/packages/devtools/CHANGELOG.md b/packages/devtools/CHANGELOG.md index 034683a0..9aefb12b 100644 --- a/packages/devtools/CHANGELOG.md +++ b/packages/devtools/CHANGELOG.md @@ -153,6 +153,7 @@ What remains: `/config` exports `DEFAULT_POPUP_HOTKEY`, `PANGULAR_ACTIONS`, `PAN - **Audit:** one ranked list of findings across the inspectors, an axe pass, and before and after sessions. - **Capacitor:** a tab for the platform, plugins, plugin calls and listeners of a Capacitor app. - **Forms, Router, Pipes and Analog:** filters, lint navigation, **Clear filters**, a route count, routed components in the **Components** tab, and search and a failed filter for Analog server calls. +- **Forms:** edit a control's value, touched and dirty state in its row of the **Fields** view (behind `actions.forms`). - **Plugin API:** a library can add its own tab, agent tools and shared state. - Angular Native and NativeScript pages report change detection, leaks, errors, stores, TanStack Query, provider values, plugins and startup timing too (#407). - Angular features are detected at runtime, and the panel says what an older version lacks. From 2aa162067e880c55f9b19e58ab9c94a514f56e7e Mon Sep 17 00:00:00 2001 From: erKam Date: Sat, 7 Nov 2026 16:29:48 +0000 Subject: [PATCH 03/14] feat(forms): try a form's WebMCP tool from the panel The WebMCP tool block shows the tool's input schema and a JSON input prefilled with a sample of it. Try this tool runs the tool linked to the form, after a Confirm try press, through the new try-webmcp form action: it is a write action behind actions.forms, needs confirm, and is offered to agents in run-form-action. The call shows as tried from the panel and is not counted as agent activity. The schema goes through serialize, and the tool answer through the form's redaction. --- app/src/__tests__/forms-panels.test.ts | 80 ++++++++ app/src/pages/forms-inspector.ts | 2 + app/src/pages/forms-types.ts | 10 +- app/src/pages/forms-webmcp.ts | 177 +++++++++++++++++- apps/docs/src/content/agents/tools.md | 4 +- apps/docs/src/content/inspectors/forms.md | 8 +- packages/devtools/CHANGELOG.md | 2 +- .../src/__tests__/forms-actions.test.ts | 53 ++++++ .../src/__tests__/forms-webmcp.test.ts | 65 +++++++ packages/devtools/src/config.ts | 1 + packages/devtools/src/devframe.ts | 7 +- packages/devtools/src/forms-actions.ts | 24 ++- packages/devtools/src/forms-collector.ts | 1 + packages/devtools/src/forms-webmcp.ts | 88 ++++++++- 14 files changed, 500 insertions(+), 22 deletions(-) diff --git a/app/src/__tests__/forms-panels.test.ts b/app/src/__tests__/forms-panels.test.ts index 3d1d0237..827f7936 100644 --- a/app/src/__tests__/forms-panels.test.ts +++ b/app/src/__tests__/forms-panels.test.ts @@ -1150,3 +1150,83 @@ describe('FormsFields inline editing', () => { expect(edit.getAttribute('aria-describedby')).toBe('forms-writes-off'); }); }); + +describe('FormsWebMcp Try this tool', () => { + const tool = { + name: 'sign_up', + description: 'Create an account', + status: 'registered' as const, + seen: 'register' as const, + inputs: ['name: string', 'age: number'], + schema: { + type: 'object', + properties: { name: { type: 'string' }, age: { type: 'number' } }, + required: ['name'], + }, + calls: [{ at: 0, outcome: 'submitted', tried: true }], + }; + + it('shows the input schema, starts from a sample input and asks before it runs the tool', async () => { + const calls: Record[] = []; + const fixture = TestBed.createComponent(FormsWebMcp); + fixture.componentRef.setInput('tool', tool); + fixture.componentRef.setInput('formId', 'signup@p1'); + fixture.componentRef.setInput( + 'rpc', + fakeClient((_name, arg) => { + calls.push(arg); + return Promise.resolve({ + ok: true, + message: 'The tool answered: Form submitted successfully', + }); + }), + ); + await settle(fixture); + const host = fixture.nativeElement as HTMLElement; + expect(host.querySelector('.schema pre')?.textContent).toContain('"required"'); + expect(text(fixture)).toContain('tried from the panel'); + const input = host.querySelector('textarea')!; + expect(JSON.parse(input.value)).toEqual({ name: '', age: 0 }); + expect(host.querySelector(`label[for="${input.id}"]`)?.textContent).toContain('Tool input'); + + input.value = '{"name": "Ada", "age": 3}'; + input.dispatchEvent(new Event('input')); + button(fixture, 'Try this tool').click(); + await settle(fixture); + expect(calls).toEqual([]); + button(fixture, 'Confirm try').click(); + await settle(fixture); + expect(calls).toEqual([ + { action: 'try-webmcp', formId: 'signup@p1', value: { name: 'Ada', age: 3 }, confirm: true }, + ]); + expect(text(fixture)).toContain('Form submitted successfully'); + }); + + it('refuses input that is not a JSON object', async () => { + const fixture = TestBed.createComponent(FormsWebMcp); + fixture.componentRef.setInput('tool', tool); + fixture.componentRef.setInput('formId', 'signup@p1'); + fixture.componentRef.setInput('rpc', fakeClient(fail)); + await settle(fixture); + const input = (fixture.nativeElement as HTMLElement).querySelector('textarea')!; + input.value = '[1'; + input.dispatchEvent(new Event('input')); + button(fixture, 'Try this tool').click(); + await settle(fixture); + expect(text(fixture)).toContain('not valid JSON'); + }); + + it('offers no Try for a tool without a form, and turns it off when form writes are off', async () => { + const fixture = TestBed.createComponent(FormsWebMcp); + fixture.componentRef.setInput('tool', tool); + await settle(fixture); + expect(text(fixture)).not.toContain('Try this tool'); + fixture.componentRef.setInput('formId', 'signup@p1'); + fixture.componentRef.setInput('rpc', { + connectionMeta: { configs: { pangular: { actions: { forms: false } } } }, + scope: () => ({ rpc: {} }), + } as unknown as DevframeRpcClient); + await settle(fixture); + expect(button(fixture, 'Try this tool').disabled).toBe(true); + }); +}); diff --git a/app/src/pages/forms-inspector.ts b/app/src/pages/forms-inspector.ts index 6d3f9df2..63b68fc8 100644 --- a/app/src/pages/forms-inspector.ts +++ b/app/src/pages/forms-inspector.ts @@ -203,6 +203,8 @@ function countFields(node: FormFieldNode): number { [tool]="form.webMcp" [page]="webMcpPage(form.id)" [signalForm]="form.kind === 'signal'" + [formId]="form.id" + [rpc]="rpc()" /> = { threw: 'threw', }; +/** A sample input for a JSON schema: empty strings, zeros, false and one item per array. */ +export function sampleInput(schema: unknown, depth = 0): unknown { + if (!schema || typeof schema !== 'object' || depth > 10) return null; + const node = schema as Record; + switch (node['type']) { + case 'object': { + const out: Record = {}; + const properties = (node['properties'] ?? {}) as Record; + for (const [key, child] of Object.entries(properties)) + out[key] = sampleInput(child, depth + 1); + return out; + } + case 'array': + return [sampleInput(node['items'], depth + 1)]; + case 'string': + return ''; + case 'number': + case 'integer': + return 0; + case 'boolean': + return false; + default: + return null; + } +} + @Component({ selector: 'app-forms-webmcp', - imports: [DatePipe], + imports: [DatePipe, JsonPipe], template: ` @if (tool(); as tool) {
@@ -85,6 +119,9 @@ const OUTCOMES: Record = { {{ outcome(call.outcome) }} + @if (call.tried) { + tried from the panel + } @if (call.ms !== undefined) { {{ call.ms }} ms } @@ -105,6 +142,48 @@ const OUTCOMES: Record = {

No agent has called this tool since the inspector attached.

}
+ @if (tool.schema) { +
+ Input schema +
{{ tool.schema | json }}
+
+ } + @if (formId() && tool.status === 'registered') { +
+ + +

+ Runs the tool in the app the way an agent call does: it fills the form and submits it. +

+
+ +
+ @if (!canWrite()) { +

{{ writesOff }}

+ } +

{{ message() }}

+
+ }
} @else if (noModelContext()) {

@@ -114,7 +193,7 @@ const OUTCOMES: Record = { } `, styles: ` - @use 'mixins' as m; + ${FORMS_STYLES} :host { display: contents; @@ -215,6 +294,44 @@ const OUTCOMES: Record = { white-space: pre-wrap; overflow-wrap: anywhere; } + .schema summary { + color: var(--text); + font-weight: 500; + cursor: pointer; + } + .schema summary:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + .try { + display: grid; + gap: 6px; + min-width: 0; + } + .try-input { + width: 100%; + min-width: 0; + padding: 6px 8px; + border: 1px solid var(--control-border); + border-radius: var(--radius-sm); + background: var(--bg); + color: var(--text); + font-family: var(--font-mono); + font-size: 12.5px; + resize: vertical; + } + .try-input:focus, + .try-input:focus-visible { + @include m.field-focus; + } + .try-row { + display: flex; + flex-wrap: wrap; + gap: 8px; + } + .status:empty { + display: none; + } `, }) export class FormsWebMcp { @@ -222,6 +339,56 @@ export class FormsWebMcp { tool = input(); page = input(); signalForm = input(false); + /** The form the tool belongs to; Try this tool shows only with it. */ + formId = input(); + rpc = input(null); + + readonly canWrite = computed(() => actionAllowed(this.rpc(), 'forms')); + protected readonly writesOff = actionBlockedMessage('forms'); + private readonly target = computed(() => `${this.formId() ?? ''}|${this.tool()?.name ?? ''}`); + private readonly schemaText = computed(() => + JSON.stringify(sampleInput(this.tool()?.schema) ?? {}, null, 2), + ); + /** The input to send; starts as a sample of the schema and resets when the tool changes. */ + readonly draft = linkedSignal<{ target: string; sample: string }, string>({ + source: () => ({ target: this.target(), sample: this.schemaText() }), + computation: (source, previous) => + previous && previous.source.target === source.target ? previous.value : source.sample, + }); + readonly armed = linkedSignal({ source: this.target, computation: () => false }); + readonly message = linkedSignal({ source: this.target, computation: () => '' }); + + /** First press arms the button, the second sends the input to the page (try-webmcp). */ + async tryTool() { + const formId = this.formId(); + if (!formId) return; + let value: unknown; + try { + value = JSON.parse(this.draft()); + } catch { + this.message.set('The tool input is not valid JSON.'); + return; + } + if (!value || typeof value !== 'object' || Array.isArray(value)) { + this.message.set('The tool input must be a JSON object.'); + return; + } + if (!this.armed()) { + this.armed.set(true); + this.message.set('Press "Confirm try" to run the tool in the app. It submits the form.'); + return; + } + this.armed.set(false); + const target = this.target(); + const result = await formAction(this.rpc(), { + action: 'try-webmcp', + formId, + value, + confirm: true, + }); + if (this.target() !== target) return; + this.message.set(actionMessage(result)); + } readonly statusText = computed(() => { const tool = this.tool(); diff --git a/apps/docs/src/content/agents/tools.md b/apps/docs/src/content/agents/tools.md index c4d2fb14..b9989d5d 100644 --- a/apps/docs/src/content/agents/tools.md +++ b/apps/docs/src/content/agents/tools.md @@ -796,7 +796,9 @@ Both tools are action tools and need a development build. They don't write secre When a write goes through a native `'))).toBe('email'); + expect(autocompleteHint(input(''))).toBe('given-name'); + expect(autocompleteHint(input(''))).toBe('postal-code'); + expect(autocompleteHint(input(''))).toBe('tel'); + expect(autocompleteHint(input(''))).toBeUndefined(); + expect(autocompleteHint(input(''))).toBeUndefined(); + expect(autocompleteHint(input(''))).toBeUndefined(); + expect(autocompleteHint(input(''))).toBeUndefined(); + expect(domFacts(input(''), {}).autocomplete).toBe('address-level2'); + }); + + it('flags a personal field without autocomplete, unless it is hidden or disabled', () => { + expect( + rules( + formOf([ + leaf('email', { dom: { labelled: true, autocomplete: 'email' } }), + leaf('city', { hidden: true, dom: { labelled: true, autocomplete: 'address-level2' } }), + leaf('zip', { status: 'DISABLED', dom: { labelled: true, autocomplete: 'postal-code' } }), + ]), + ), + ).toEqual(['missing-autocomplete:email']); + const finding = lintForm(formOf([leaf('email', { dom: { autocomplete: 'email' } })]), [], 0)[0]; + expect(finding.fix).toContain('autocomplete="email"'); + }); + + it('flags submit buttons that are all disabled while the form is invalid', () => { + const submitDom = { + tag: 'form', + buttons: 1, + disabledButtons: 1, + novalidate: true, + nativeInvalid: 0, + reasons: [], + }; + const invalid = formOf([leaf('a')], { submitDom }); + invalid.root.status = 'INVALID'; + expect(rules(invalid)).toContain('submit-disabled-while-invalid:'); + expect(rules(formOf([leaf('a')], { submitDom }))).not.toContain( + 'submit-disabled-while-invalid:', + ); + const enabled = formOf([leaf('a')], { submitDom: { ...submitDom, disabledButtons: 0 } }); + enabled.root.status = 'INVALID'; + expect(rules(enabled)).not.toContain('submit-disabled-while-invalid:'); + }); + + it('can be turned off one rule at a time', () => { + const form = formOf([leaf('email', { dom: { labelled: true, autocomplete: 'email' } })]); + expect(lintForm(form, [], 0, { rules: { 'missing-autocomplete': false } })).toEqual([]); + }); +}); diff --git a/packages/devtools/src/forms-dom.ts b/packages/devtools/src/forms-dom.ts index a466e74d..945e7609 100644 --- a/packages/devtools/src/forms-dom.ts +++ b/packages/devtools/src/forms-dom.ts @@ -7,6 +7,11 @@ export interface DomFacts { disabled?: boolean; drift?: string | true; classes?: string[]; + /** + * The `autocomplete` token the field seems to need (WCAG 1.3.5), from its input type or + * name, when it has no `autocomplete` attribute. + */ + autocomplete?: string; } export interface SubmitDom { @@ -132,6 +137,46 @@ function sameValue(dom: string | boolean, model: unknown): boolean { return true; } +const INPUT_TYPES: Record = { email: 'email', tel: 'tel' }; + +/** Name tokens of personal data and the `autocomplete` value each one takes. */ +const PURPOSES: [RegExp, string][] = [ + [/^e-?mail(address)?$/, 'email'], + [/^(phone|tel|telephone|mobile|phonenumber|mobilenumber)$/, 'tel'], + [/^(first-?name|given-?name|fname)$/, 'given-name'], + [/^(last-?name|family-?name|surname|lname)$/, 'family-name'], + [/^(full-?name|your-?name)$/, 'name'], + [/^(user-?name|login)$/, 'username'], + [/^(street|street-?address|address-?line-?1|address1)$/, 'address-line1'], + [/^(zip|zip-?code|postal-?code|post-?code)$/, 'postal-code'], + [/^(city|town)$/, 'address-level2'], + [/^country$/, 'country-name'], + [/^(birthday|birth-?date|dob)$/, 'bday'], + [/^(organization|organisation|company)$/, 'organization'], +]; + +const TEXT_TYPES = new Set(['', 'text', 'email', 'tel', 'search', 'url', 'date']); + +/** The `autocomplete` token a field without one seems to need, or undefined. */ +export function autocompleteHint(el: Element): string | undefined { + if (!(el instanceof HTMLInputElement) || el.hasAttribute('autocomplete')) return undefined; + const type = (el.getAttribute('type') ?? '').toLowerCase(); + if (!TEXT_TYPES.has(type)) return undefined; + if (INPUT_TYPES[type]) return INPUT_TYPES[type]; + const names = [el.getAttribute('name'), el.getAttribute('formcontrolname'), el.id].map((name) => + (name ?? '') + .split(/[.[\]]/) + .pop()! + .replace(/_/g, '-') + .toLowerCase(), + ); + for (const name of names) { + const purpose = PURPOSES.find(([pattern]) => pattern.test(name)); + if (purpose) return purpose[1]; + } + return undefined; +} + export function domFacts( el: Element, model: { value?: unknown; disabled?: boolean; secret?: boolean; hasErrors?: boolean }, @@ -164,6 +209,8 @@ export function domFacts( } const classes = Array.from(el.classList).filter((c) => STATUS_CLASS.test(c)); if (classes.length) facts.classes = classes; + const autocomplete = autocompleteHint(el); + if (autocomplete) facts.autocomplete = autocomplete; return facts; } diff --git a/packages/devtools/src/rpc/forms-lint.ts b/packages/devtools/src/rpc/forms-lint.ts index b16f5311..fe100712 100644 --- a/packages/devtools/src/rpc/forms-lint.ts +++ b/packages/devtools/src/rpc/forms-lint.ts @@ -59,6 +59,21 @@ export function lintForm( 'Add a type="submit" button inside the

, or link it with form="id".', ); } + const dom = form.submitDom; + if ( + dom && + dom.buttons > 0 && + dom.disabledButtons === dom.buttons && + form.root.status === 'INVALID' + ) { + add( + 'submit-disabled-while-invalid', + 'info', + undefined, + 'Every submit button is disabled while the form is invalid. A disabled button gives no reason, keyboard users cannot focus it, and the errors stay hidden until each field is touched.', + 'Keep submit enabled. On an invalid submit, mark the fields touched, show the errors and focus the first invalid field.', + ); + } if (form.kind === 'signal' && form.submitDom && form.submit && !form.submit.hasAction) { add( 'formroot-no-submission', @@ -146,6 +161,15 @@ export function lintForm( 'Add a