You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte-kit-vice/src/uix/morfo/components/dialog.ts

207 lines
5.3 KiB

morfo: cross-layer contract + 14 new WAI-ARIA components + Dialog wired Morfo (src/uix/morfo/): machine-readable contract of a component's public DOM surface, shared between soma/sema/eidos. Shape v5 consolidated across three independent AI reviews (Gemini, Grok, ChatGPT) plus Sema alignment. Types, sium-based validator with cross-field invariants, dialog.ts as the first canonical morfo with data-last-action for Sema-causal exits, 7 passing unit tests. createAttrs(morfo) and registerContract(morfo) now consume a Morfo — legacy inline signature removed. Dialog provider refactored to derive parts + data contract from dialogMorfo. The other 65 soma components need porting (svelte-check lists them) — tracked work. Tooling: scripts/smoke-check.mjs — Playwright smoke over 65 soma demo routes scripts/morfo-check.ts — validates emitted DOM vs morfo scripts/morfo-vocabulary-check.ts — canonical vocabulary consistency npm run smoke / morfo:check / morfo:vocabulary WAI-ARIA APG components added (100% APG coverage now): Announce, Avatar, Clipboard, DragDrop, Feed, GridList, Meter, Progress, SearchField, TagGroup, TreeGrid + Table.RowDetail/Trigger (detail panel pattern; hierarchical Table rows deprecated — use TreeGrid instead). air: Link, Banner. Sema prep: src/uix/sema/sema_pre.md documents the semantic layer's DOM requirements. Morfo already provides everything Sema needs (data-last-action patterns, transition markers, enumerable state values, cross-component consistency). Sema implementation deferred. COMPONENT_GUIDE updated: items 37-39 (translation namespace grep, DOM topology vs .require() audit, npm run smoke is part of done) + A34 rule with incident log. WAI-ARIA pattern listed as soma membership criterion. Pagination translation bug fixed (soma.pagination.page -> idlangref PAGINATION_LANGS.PAGE). Table demo namespace fix (soma.table.* -> components.table.*). Avatar demo now offline-safe (SVG data URL). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6 months ago
/**
* Dialog morfo — canonical first example.
*
* Authored from the current `dialog-provider.svelte.ts` + `sema_pre.md`
* guidelines (data-last-action for asymmetric exits, transition markers).
*
* When the provider is refactored to consume `createAttrs(dialogMorfo)` +
* `registerContract(dialogMorfo)`, this becomes the single source of
* truth for parts, data-attrs, ARIA contract, keyboard, and focus.
*/
import type { Morfo } from '../types';
import { v } from '../types';
export const dialogMorfo: Morfo = {
name: 'Dialog',
kebab: 'dialog',
scope: ['soma'],
apg: 'https://www.w3.org/WAI/ARIA/apg/patterns/dialog/',
focus: {
initial: 'first-focusable',
trap: true,
return: 'trigger',
restore: true
},
parts: [
{
name: 'Provider',
kebab: 'root',
kind: 'virtual',
defaultElement: 'none',
optional: false,
states: ['open', 'closed'],
data: [
{ attr: 'data-state', values: ['open', 'closed'] },
{ attr: 'data-disabled', severity: 'optional' }
],
aria: []
},
{
name: 'Trigger',
kebab: 'trigger',
kind: 'public',
defaultElement: 'button',
role: 'button',
optional: false,
states: ['open', 'closed'],
data: [{ attr: 'data-state', values: ['open', 'closed'] }],
aria: [
{ attr: 'type', value: v.literal('button') },
{ attr: 'aria-haspopup', value: v.literal('dialog') },
{ attr: 'aria-expanded', value: v.stateRef('open') },
{ attr: 'aria-controls', value: v.partRef('content') }
]
},
{
name: 'Content',
kebab: 'content',
kind: 'public',
defaultElement: 'div',
role: 'dialog',
optional: false,
supportsNesting: true,
states: ['open', 'closed'],
data: [
{ attr: 'data-state', values: ['open', 'closed'] },
{
/**
* Sema alignment (sema_pre.md §9): causal exit reason. Updated
* BEFORE `data-state` flips to `'closed'` so Sema can tint the
* exit animation per-action. Ordering is validated by a
* dedicated MutationObserver test in the smoke suite.
*/
attr: 'data-last-action',
values: ['saved', 'cancelled', 'dismissed', 'dismissed-outside', 'failed'],
severity: 'optional'
},
{
attr: 'data-nested',
severity: 'optional'
},
{
attr: 'data-nested-open',
severity: 'optional'
},
{
attr: 'data-starting-style',
severity: 'optional',
condition: { when: 'state-equals', state: 'open', value: 'starting' }
},
{
attr: 'data-ending-style',
severity: 'optional',
condition: { when: 'state-equals', state: 'closed', value: 'ending' }
}
],
aria: [
{ attr: 'aria-modal', value: v.literal('true'), condition: { when: 'prop-truthy', prop: 'modal' } },
{
attr: 'aria-labelledby',
value: v.partRef('title'),
condition: { when: 'part-present', part: 'title' },
severity: 'recommended'
},
{
/**
* APG advises against `aria-describedby` on Dialog with rich
* content (lists, tables) — AT announces everything as a
* single string. Optional by design.
*/
attr: 'aria-describedby',
value: v.partRef('description'),
condition: { when: 'part-present', part: 'description' },
severity: 'optional'
},
{
attr: 'aria-roledescription',
value: v.translationRef('#?components.dialog.content.roledescription|dialog window'),
severity: 'optional'
}
],
keyboard: [
{ key: 'Escape', action: 'close' },
{ key: 'Tab', action: 'focus-next' },
{ key: 'Shift+Tab', action: 'focus-prev' }
]
},
{
name: 'Overlay',
kebab: 'overlay',
kind: 'public',
defaultElement: 'div',
optional: true,
supportsNesting: true,
states: ['open', 'closed'],
data: [
{ attr: 'data-state', values: ['open', 'closed'] },
{ attr: 'data-nested', severity: 'optional' },
{ attr: 'data-nested-open', severity: 'optional' },
{
attr: 'data-starting-style',
severity: 'optional',
condition: { when: 'state-equals', state: 'open', value: 'starting' }
},
{
attr: 'data-ending-style',
severity: 'optional',
condition: { when: 'state-equals', state: 'closed', value: 'ending' }
}
],
aria: [{ attr: 'aria-hidden', value: v.literal('true') }]
},
{
/**
* Title contributes to the accessible name of Content via
* `aria-labelledby`. Emitted as heading for AT hierarchy, but
* level is consumer-controlled (`propRef('level')`) — not a
* hardcoded '2' — so a dialog can be h1 at top level or h3 in
* a nested context without overriding prose.
*/
name: 'Title',
kebab: 'title',
kind: 'public',
defaultElement: 'div',
role: 'heading',
optional: true,
data: [],
aria: [
{
attr: 'aria-level',
value: v.propRef('level'),
severity: 'recommended'
}
]
},
{
name: 'Description',
kebab: 'description',
kind: 'public',
defaultElement: 'div',
optional: true,
data: [],
aria: []
},
{
name: 'Close',
kebab: 'close',
kind: 'public',
defaultElement: 'button',
role: 'button',
optional: true,
data: [],
aria: [
{ attr: 'type', value: v.literal('button') },
{
attr: 'aria-label',
value: v.propRef('aria-label'),
severity: 'recommended',
condition: { when: 'prop-truthy', prop: 'aria-label' }
}
]
}
]
};

Powered by TurnKey Linux.