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/web/routes/uix/components/words/+page.svelte

1867 lines
59 KiB

<script lang="ts">
import {
Words,
type WordsColor,
type WordsSize,
type WordsToolbarConfig,
type WordsToolbarCodeLanguagePickerConfig,
type WordsToolbarFamilyConfig,
type WordsToolbarFamilyName,
type WordsToolbarGroupConfig,
type WordsToolbarLeafItemConfig,
type WordsToolbarPreset,
type WordsVariant
} from '$uix/eidos/components/words';
import { Bold, Italic, Underline } from '$uix/eidos/components/icon';
import type {
WordsDocument,
WordsExportFormat,
WordsInline,
WordsImportFormat,
WordsSelection
} from '$soma/components/words';
import {
parseWordsHtml,
parseWordsJson,
parseWordsMarkdown,
parseWordsPlainText,
renderWordsPlainText,
serializeWordsHtml,
serializeWordsJson,
serializeWordsMarkdown
} from '$soma/components/words/engine';
import { compileMorfo } from '$uix/morfo';
import { wordsMorfo } from '@/uix/morfo/components/words';
import { getActiveUix } from '$active-uix';
import type { Intent } from '$uix/intent';
type Tab = 'live' | 'api' | 'morfo' | 'sema' | 'recipe' | 'a11y';
type DocumentPreset = 'sample' | 'empty' | 'long';
type ToolbarChoice = 'none' | WordsToolbarPreset | 'custom';
type TraceEntry = { event: string; family: string; intent?: string; at: number };
type FindReplaceToolbarItem = Extract<
WordsToolbarGroupConfig[number],
'find-replace' | { part: 'find-replace' }
>;
type RawValue = { kind?: string; value?: unknown; prop?: string; part?: string };
type RawPart = {
kebab: string;
name: string;
defaultElement: string;
role?: string;
archetype?: string;
states?: readonly string[];
optional?: boolean;
aria?: ReadonlyArray<{
attr: string;
value: RawValue;
condition?: { when: string; prop?: string; part?: string };
severity?: string;
}>;
keyboard?: ReadonlyArray<{ key: string; action: string }>;
};
type RawEvent = {
name: string;
semantic: {
family: string;
verb?: string;
sequence?: string;
intent?: string | RawValue;
target?: RawValue;
};
prewrite?: unknown;
commit?: unknown;
};
const uix = getActiveUix();
const compiled = compileMorfo(wordsMorfo);
const partsList = $derived([...compiled.parts.byKebab.values()]);
const events = $derived([...compiled.actions.byName.values()]);
const sizes: WordsSize[] = ['sm', 'md', 'lg'];
const variants: WordsVariant[] = ['surface', 'outline', 'ghost'];
const colors: WordsColor[] = [
'primary',
'secondary',
'neutral',
'affirm',
'fulfill',
'risk',
'threat',
'loss'
];
const presets: DocumentPreset[] = ['sample', 'empty', 'long'];
const exportFormats: WordsExportFormat[] = ['json', 'text', 'html', 'markdown'];
const importFormats: WordsImportFormat[] = ['json', 'text', 'html', 'markdown'];
const toolbarChoices: ToolbarChoice[] = ['none', 'minimal', 'formatting', 'full', 'custom'];
const toolbarPresetGroups: Record<WordsToolbarPreset, WordsToolbarGroupConfig[]> = {
minimal: [['text-menu']],
formatting: [['text-menu', 'block-menu', 'align-menu', 'insert-menu', 'table-menu']],
full: [
[
'history-menu',
'text-menu',
'block-menu',
'list-menu',
'align-menu',
'insert-menu',
'table-menu',
'link-menu',
'tools-menu'
],
['find-replace']
]
};
const toolbarCustomGroups: WordsToolbarGroupConfig[] = [
[
'history-menu',
{
part: 'toolbar-family',
family: 'text',
label: 'Inline text',
items: ['bold', 'italic', 'underline', 'strike', 'code']
},
'block-menu',
'list-menu',
'align-menu',
'table-menu',
'link-menu',
'tools-menu'
],
['find-replace']
];
const demoToolbarFamilyItems: Record<
WordsToolbarFamilyName,
readonly WordsToolbarLeafItemConfig[]
> = {
history: ['undo', 'redo'],
text: ['bold', 'italic', 'underline', 'strike', 'code', 'clear-formatting'],
block: [
'paragraph',
{ command: 'heading', level: 1, label: 'Heading 1' },
{ command: 'heading', level: 2, label: 'Heading 2' },
{ command: 'heading', level: 3, label: 'Heading 3' },
'quote',
'code-block',
'code-language-picker'
],
list: ['unordered-list', 'ordered-list', 'check-list', 'increase-indent', 'decrease-indent'],
align: ['align-left', 'align-center', 'align-right', 'align-justify'],
insert: ['insert-table'],
table: [
'insert-table',
'insert-table-row',
'insert-table-column',
'delete-table-row',
'delete-table-column',
'toggle-table-header-row',
'toggle-table-header-column',
'toggle-table-striped',
'toggle-table-compact',
'align-left',
'align-center',
'align-right',
'align-justify',
'table-cell-vertical-top',
'table-cell-vertical-middle',
'table-cell-vertical-bottom',
'table-cell-tone-default',
'table-cell-tone-muted',
'table-cell-tone-accent'
],
link: ['link-editor', 'unlink'],
tools: ['clear-formatting', 'clear-document', 'commit']
};
let tab = $state<Tab>('live');
let preset = $state<DocumentPreset>('sample');
let value = $state<WordsDocument>(sampleDocument());
let selection = $state<WordsSelection | null>(null);
let placeholder = $state('Write the product note...');
let disabled = $state(false);
let readonly = $state(false);
let required = $state(false);
let invalid = $state(false);
let commitOnBlur = $state(true);
let toolbarChoice = $state<ToolbarChoice>('full');
let showLinkEditor = $state(true);
let showFindReplace = $state(true);
let showBubbleMenu = $state(false);
let showSlashMenu = $state(true);
let showStatus = $state(true);
let showDrawer = $state(true);
let toolbarLayout = $state<'grouped' | 'inline'>('grouped');
let size = $state<WordsSize>('md');
let variant = $state<WordsVariant>('surface');
let color = $state<WordsColor>('primary');
let lastCommit = $state('none');
let documentRevision = $state(0);
let exportFormat = $state<WordsExportFormat>('markdown');
let importFormat = $state<WordsImportFormat>('markdown');
let importDraft = $state('# Imported note\n\n- safe markdown\n- zero dependencies');
let importFeedback = $state('ready');
let trace = $state<TraceEntry[]>([]);
let stageRef = $state<HTMLElement | null>(null);
const plainText = $derived(readPlainText(value));
const wordCount = $derived(countWords(plainText));
const selectionState = $derived(selectionLabel(selection));
const documentJson = $derived(JSON.stringify(value, null, 2));
const exportPreview = $derived(exportWordsDocument(value, exportFormat));
const toolbarSnippetGroups = $derived(
resolveDemoToolbarGroups(toolbarChoice, showLinkEditor, showFindReplace)
);
const toolbarConfig = $derived<WordsToolbarConfig>(
toolbarChoice === 'none' ? false : toolbarSnippetGroups
);
const toolbarCommandCount = $derived(countToolbarItems(toolbarSnippetGroups));
const somaUsesCodeLanguagePicker = $derived(
toolbarSnippetGroups.some((group) =>
group.some((item) => expandToolbarItem(item).some(isCodeLanguagePickerItem))
)
);
const toolbarShape = $derived(
toolbarChoice === 'none'
? 'disabled'
: `${toolbarChoice} · ${toolbarSnippetGroups.length} groups · ${toolbarCommandCount} items`
);
const bubbleState = $derived(
showBubbleMenu ? 'selection toolbar enabled' : 'selection toolbar off'
);
const slashState = $derived(showSlashMenu ? 'slash commands enabled' : 'slash commands off');
const somaBodyLines = $derived(
[
...somaToolbarSnippet(toolbarSnippetGroups),
...(somaUsesCodeLanguagePicker ? somaCodeLanguageSnippet() : []),
...(showLinkEditor && toolbarChoice === 'none' ? somaLinkEditorSnippet() : []),
showFindReplace && toolbarChoice === 'none' && ' <Words.FindReplace />',
' <Words.Placeholder />',
' <Words.Content />',
...(showBubbleMenu ? somaBubbleMenuSnippet() : []),
showSlashMenu && ' <Words.SlashMenu />',
' <Words.HiddenInput />',
showStatus && ' <Words.Status />'
].filter((line): line is string => Boolean(line))
);
const somaSnippet = $derived(
[
"<script lang='ts'>",
" import * as Words from '$soma/components/words';",
" import type { WordsDocument } from '$soma/components/words';",
` let value = $state<WordsDocument>(${documentJson});`,
showLinkEditor && " let linkHref = $state('/docs');",
'</' + 'script>',
'',
'<Words.Provider',
' bind:value',
` placeholder={${quote(placeholder)}}`,
' name="body"',
disabled && ' disabled',
readonly && ' readonly',
required && ' required',
invalid && ' invalid',
!commitOnBlur && ' commitOnBlur={false}',
'>',
...(somaUsesCodeLanguagePicker
? [
' {#snippet children({ currentBlock, currentCodeLanguage, setCodeLanguage, isDisabled, isReadonly })}',
...somaBodyLines.map((line) => ` ${line}`),
' {/snippet}'
]
: somaBodyLines),
'</Words.Provider>'
]
.filter(Boolean)
.join('\n')
);
const eidosSnippet = $derived(
[
"<script lang='ts'>",
" import { Words } from '$uix/eidos/components/words';",
" import type { WordsDocument } from '$soma/components/words';",
` let value = $state<WordsDocument>(${documentJson});`,
'</' + 'script>',
'',
'<Words',
' bind:value',
` placeholder={${quote(placeholder)}}`,
size !== 'md' && ` size="${size}"`,
variant !== 'surface' && ` variant="${variant}"`,
color !== 'primary' && ` color="${color}"`,
toolbarChoice !== 'none' && ` toolbar={${JSON.stringify(toolbarSnippetGroups)}}`,
toolbarChoice === 'none' && ' toolbar={false}',
disabled && ' disabled',
readonly && ' readonly',
required && ' required',
invalid && ' invalid',
!commitOnBlur && ' commitOnBlur={false}',
'>',
showLinkEditor && toolbarChoice === 'none' && ' <Words.LinkEditor />',
showFindReplace && toolbarChoice === 'none' && ' <Words.FindReplace toolbarItem={false} />',
' <Words.Placeholder />',
' <Words.Content />',
showBubbleMenu && ' <Words.BubbleMenu>',
showBubbleMenu && ' <Words.CommandButton command="bold" aria-label="Bold" />',
showBubbleMenu && ' <Words.CommandButton command="italic" aria-label="Italic" />',
showBubbleMenu && ' <Words.CommandButton command="underline" aria-label="Underline" />',
showBubbleMenu && showLinkEditor && ' <Words.LinkEditor />',
showBubbleMenu && ' </Words.BubbleMenu>',
showSlashMenu && ' <Words.SlashMenu />',
' <Words.HiddenInput />',
showStatus && ' <Words.Status />',
'</Words>'
]
.filter(Boolean)
.join('\n')
);
const recipeSelectors = [
{
selector: '[data-words]',
source: 'morfo + eidos',
kind: 'eidos',
note: 'root, size, variant, color'
},
{ selector: '[data-words][data-focused]', source: 'morfo', kind: 'soma', note: 'focus ring' },
{ selector: '[data-words][data-invalid]', source: 'morfo', kind: 'soma', note: 'risk border' },
{ selector: '[data-words-toolbar]', source: 'morfo', kind: 'soma', note: 'toolbar shell' },
{
selector: '[data-words-command-button][data-state]',
source: 'morfo',
kind: 'soma',
note: 'active command'
},
{
selector: '[data-words-command-button][data-command]',
source: 'morfo',
kind: 'soma',
note: 'command-specific treatment'
},
{
selector: '[data-words-bubble-menu][data-open]',
source: 'morfo',
kind: 'soma',
note: 'selection anchored toolbar'
},
{
selector: '[data-words-slash-menu][data-open]',
source: 'morfo',
kind: 'soma',
note: 'caret anchored command menu'
},
{
selector: '[data-words-slash-option][data-active]',
source: 'eidos',
kind: 'eidos',
note: 'active slash command option'
},
{
selector: '[data-words-heading-picker]',
source: 'eidos',
kind: 'eidos',
note: 'heading level dropdown'
},
{
selector: '[data-words-code-language-picker]',
source: 'eidos',
kind: 'eidos',
note: 'code block language dropdown'
},
{
selector: '[data-words-code-language-option][data-active]',
source: 'eidos',
kind: 'eidos',
note: 'selected code language'
},
{
selector: '[data-words-content] [data-words-code-token]',
source: 'soma engine',
kind: 'soma',
note: 'runtime syntax highlighting tokens'
},
{
selector: "[data-words-content] [data-words-node='table-cell']",
source: 'soma engine',
kind: 'soma',
note: 'editable table cells'
},
{
selector: '[data-words-link-editor]',
source: 'morfo',
kind: 'soma',
note: 'selection-aware link form'
},
{
selector: '[data-words-link-editor][data-invalid]',
source: 'morfo',
kind: 'soma',
note: 'invalid link feedback'
},
{
selector: '[data-words-find-replace]',
source: 'morfo',
kind: 'soma',
note: 'find and replace panel'
},
{
selector: '[data-words-find-replace][data-invalid]',
source: 'morfo',
kind: 'soma',
note: 'invalid regex query state'
},
{
selector: '[data-words-find-case]',
source: 'eidos',
kind: 'eidos',
note: 'case-sensitive search toggle'
},
{
selector: '[data-words-find-whole]',
source: 'eidos',
kind: 'eidos',
note: 'whole-word search toggle'
},
{
selector: '[data-words-find-regex]',
source: 'eidos',
kind: 'eidos',
note: 'regular-expression search toggle'
},
{
selector: "[data-words-find-input][aria-invalid='true']",
source: 'eidos',
kind: 'eidos',
note: 'invalid regex input affordance'
},
{
selector: '[data-words-content] mark[data-words-find-match]',
source: 'soma engine',
kind: 'soma',
note: 'rendered search matches'
},
{
selector: '[data-words-placeholder][hidden]',
source: 'morfo',
kind: 'soma',
note: 'empty document hint'
},
{
selector: '[data-words-content]',
source: 'morfo',
kind: 'soma',
note: 'contenteditable area'
},
{
selector: '[data-words-content] [data-words-marks]',
source: 'soma engine',
kind: 'soma',
note: 'rendered marks'
},
{
selector: '[data-words-content] [data-words-indent]',
source: 'soma engine',
kind: 'soma',
note: 'list item indent levels'
},
{
selector: '[data-words-status][data-status]',
source: 'morfo',
kind: 'soma',
note: 'idle/error status'
}
];
$effect(() => {
const el = stageRef;
if (!el) return;
const obs = new MutationObserver((mutations) => {
for (const m of mutations) {
if (m.attributeName !== 'data-event') continue;
const target = m.target as Element;
const ev = target.getAttribute('data-event');
if (!ev) continue;
trace = [
{
event: ev,
family: target.getAttribute('data-event-family') ?? '-',
intent: target.getAttribute('data-event-intent') ?? undefined,
at: Date.now()
},
...trace
].slice(0, 6);
}
});
obs.observe(el, { attributes: true, subtree: true, attributeFilter: ['data-event'] });
return () => obs.disconnect();
});
function sampleDocument(): WordsDocument {
return {
version: 1,
children: [
{
type: 'heading',
level: 1,
children: [{ type: 'text', text: 'ActiveUIX Words', marks: ['bold'] }]
},
{
type: 'paragraph',
children: [
{ type: 'text', text: 'A rich text surface with ' },
{ type: 'text', text: 'canonical JSON', marks: ['bold'] },
{ type: 'text', text: ', selection-aware commands and UIX semantic events.' }
]
},
{
type: 'quote',
children: [
{ type: 'text', text: 'The visual recipe reads Morfo data attrs; Soma owns editing.' }
]
},
{
type: 'code',
language: 'ts',
children: [{ type: 'text', text: "const words = createWordsState('ActiveUIX');" }]
},
{
type: 'image',
src: 'https://placecats.com/600/300',
alt: 'Demo cat placeholder showing the image block in action',
caption: 'Image blocks are first-class: alt, optional caption, optional alignment.'
},
{
type: 'table',
striped: true,
children: [
{
type: 'table-row',
children: [
{
type: 'table-cell',
header: true,
children: [{ type: 'text', text: 'Feature' }]
},
{
type: 'table-cell',
header: true,
textAlign: 'center',
children: [{ type: 'text', text: 'Owner' }]
}
]
},
{
type: 'table-row',
children: [
{ type: 'table-cell', children: [{ type: 'text', text: 'Tables' }] },
{
type: 'table-cell',
tone: 'accent',
verticalAlign: 'middle',
children: [{ type: 'text', text: 'Soma + Eidos' }]
}
]
}
]
},
{
type: 'list',
kind: 'unordered',
children: [
{
type: 'list-item',
children: [{ type: 'text', text: 'Toolbar commands update the real document.' }]
},
{
type: 'list-item',
children: [{ type: 'text', text: 'HiddenInput serializes the JSON payload.' }]
},
{
type: 'list-item',
indent: 1,
children: [
{
type: 'text',
text: 'Indented list item: Shift+Tab to decrease, Tab to increase.'
}
]
},
{
type: 'list-item',
children: [
{
type: 'text',
text: 'Sema receives focus, commit, format, history and clear events.'
}
]
}
]
}
]
};
}
function emptyDocument(): WordsDocument {
return {
version: 1,
children: [{ type: 'paragraph', children: [{ type: 'text', text: '' }] }]
};
}
function longDocument(): WordsDocument {
return {
version: 1,
children: [
{
type: 'heading',
level: 2,
children: [{ type: 'text', text: 'Editor surface stress case' }]
},
{
type: 'paragraph',
children: [
{
type: 'text',
text: 'Longer copy keeps the editor stable while the toolbar wraps, the placeholder disappears and the content area keeps its rhythm. '
},
{ type: 'text', text: 'Inline code', marks: ['code'] },
{ type: 'text', text: ' and ' },
{ type: 'text', text: 'emphasis', marks: ['italic'] },
{
type: 'text',
text: ' are rendered from the engine metadata, not hand-written demo markup.'
}
]
},
{
type: 'code',
language: 'js',
children: [
{
type: 'text',
text: 'function commit(note) {\n\treturn note.trim();\n}'
}
]
},
{
type: 'paragraph',
children: [
{
type: 'text',
text: 'This document is intentionally verbose so size, variant and color controls have enough surface to show their actual effect across shell, toolbar, command buttons and text.'
}
]
},
{
type: 'list',
kind: 'ordered',
children: [
{
type: 'list-item',
children: [{ type: 'text', text: 'Inspect the Morfo tab for parts and attributes.' }]
},
{
type: 'list-item',
indent: 2,
children: [{ type: 'text', text: 'Nested view of indent level 2 (max 8).' }]
},
{
type: 'list-item',
children: [{ type: 'text', text: 'Use Sema play buttons against the mounted stage.' }]
},
{
type: 'list-item',
children: [
{ type: 'text', text: 'Compare Soma and Eidos snippets after changing controls.' }
]
}
]
}
]
};
}
function setPreset(next: DocumentPreset) {
preset = next;
value =
next === 'empty' ? emptyDocument() : next === 'long' ? longDocument() : sampleDocument();
selection = null;
lastCommit = `preset:${next}`;
documentRevision += 1;
}
function importDraftDocument() {
try {
value =
importFormat === 'json'
? parseWordsJson(importDraft)
: importFormat === 'html'
? parseWordsHtml(importDraft)
: importFormat === 'markdown'
? parseWordsMarkdown(importDraft)
: parseWordsPlainText(importDraft);
selection = null;
preset = 'sample';
lastCommit = `import:${importFormat}`;
importFeedback = `imported ${importFormat}`;
documentRevision += 1;
} catch {
importFeedback = `invalid ${importFormat}`;
}
}
function exportWordsDocument(document: WordsDocument, format: WordsExportFormat): string {
if (format === 'json') return serializeWordsJson(document);
if (format === 'html') return serializeWordsHtml(document);
if (format === 'markdown') return serializeWordsMarkdown(document);
return renderWordsPlainText(document);
}
// readPlainText handles image (no .children) — POLISH-1a
function readPlainText(document: WordsDocument): string {
return document.children
.map((block) => {
if (block.type === 'list') {
return block.children
.map((item) => item.children.map(readInlineText).join(''))
.join('\n');
}
if (block.type === 'table') {
return block.children
.map((row) =>
row.children.map((cell) => cell.children.map(readInlineText).join('')).join('\t')
)
.join('\n');
}
if (block.type === 'image') {
// Image has no inline children — represent in plain text via alt.
return block.alt ?? '';
}
return block.children.map(readInlineText).join('');
})
.join('\n');
}
function readInlineText(inline: WordsInline): string {
if (inline.type === 'text') return inline.text;
return inline.children.map(readInlineText).join('');
}
function countWords(text: string): number {
const trimmed = text.trim();
return trimmed ? trimmed.split(/\s+/).length : 0;
}
function selectionLabel(current: WordsSelection | null): string {
if (!current) return 'none';
const samePath =
current.anchor.path.length === current.focus.path.length &&
current.anchor.path.every((part, index) => part === current.focus.path[index]);
return samePath && current.anchor.offset === current.focus.offset ? 'collapsed' : 'range';
}
function fmtTime(at: number): string {
const d = new Date(at);
return `${String(d.getSeconds()).padStart(2, '0')}.${String(d.getMilliseconds()).padStart(3, '0')}`;
}
function quote(value: string): string {
return JSON.stringify(value);
}
function somaToolbarSnippet(groups: readonly WordsToolbarGroupConfig[]): string[] {
if (groups.length === 0) return [];
const expandedGroups = groups.map((group) => group.flatMap(expandToolbarItem));
const toolbarGroups = expandedGroups
.map((group) => group.filter((item) => !isFindReplaceItem(item)))
.filter((group) => group.length > 0);
const hasFindReplace = expandedGroups.some((group) => group.some(isFindReplaceItem));
return [
...(toolbarGroups.length
? [
' <Words.Toolbar>',
...toolbarGroups.flatMap((group) => [
' <Words.ToolbarGroup>',
...group.flatMap((command) => somaCommandSnippet(command)),
' </Words.ToolbarGroup>'
]),
' </Words.Toolbar>'
]
: []),
hasFindReplace && ' <Words.FindReplace />'
].filter((line): line is string => Boolean(line));
}
function somaCommandSnippet(item: WordsToolbarGroupConfig[number]): string[] {
if (isToolbarFamilyItem(item)) return expandToolbarItem(item).flatMap(somaCommandSnippet);
if (isFindReplaceItem(item)) return [];
if (isCodeLanguagePickerItem(item)) return [];
if (
item === 'link-editor' ||
(typeof item === 'object' && 'part' in item && item.part === 'link-editor')
) {
return somaLinkEditorSnippet().map((line) => ` ${line.trimStart()}`);
}
if (
item === 'heading-picker' ||
(typeof item === 'object' && 'part' in item && item.part === 'heading-picker')
) {
return [' <Words.HeadingPicker />'];
}
const command = typeof item === 'string' ? item : item.command;
const label =
typeof item === 'string' ? commandLabel(command) : (item.label ?? commandLabel(command));
const level =
command === 'heading' ? ` level={${typeof item === 'string' ? 1 : (item.level ?? 1)}}` : '';
return [` <Words.CommandButton command="${command}"${level} aria-label="${label}" />`];
}
function somaLinkEditorSnippet(): string[] {
return [
' <Words.LinkEditor bind:href={linkHref}>',
' {#snippet children({ error, canUnlink, disabled, readonly, unlink, clearError })}',
' <input name="href" bind:value={linkHref} oninput={clearError} />',
' <button type="submit" disabled={disabled || readonly}>Apply</button>',
' <button type="button" disabled={!canUnlink} onclick={unlink}>Remove</button>',
' {#if error}<span>{error}</span>{/if}',
' {/snippet}',
' </Words.LinkEditor>'
];
}
function somaCodeLanguageSnippet(): string[] {
return [
' <label>',
' Code language',
' <select',
' value={currentCodeLanguage ?? ""}',
' disabled={isDisabled || isReadonly || currentBlock !== "code"}',
' onchange={(event) => setCodeLanguage(event.currentTarget.value || undefined)}',
' >',
' <option value="">Plain text</option>',
' <option value="ts">TypeScript</option>',
' <option value="js">JavaScript</option>',
' <option value="css">CSS</option>',
' <option value="json">JSON</option>',
' </select>',
' </label>'
];
}
function somaBubbleMenuSnippet(): string[] {
return [
' <Words.BubbleMenu>',
' <Words.CommandButton command="bold" aria-label="Bold" />',
' <Words.CommandButton command="italic" aria-label="Italic" />',
' <Words.CommandButton command="underline" aria-label="Underline" />',
...(showLinkEditor ? [' <Words.LinkEditor />'] : []),
' </Words.BubbleMenu>'
];
}
function commandLabel(command: string): string {
return command
.split('-')
.map((part) => part[0]?.toUpperCase() + part.slice(1))
.join(' ');
}
function resolveDemoToolbarGroups(
choice: ToolbarChoice,
includeLinkEditor: boolean,
includeFindReplace: boolean
): WordsToolbarGroupConfig[] {
if (choice === 'none') return [];
const source = choice === 'custom' ? toolbarCustomGroups : toolbarPresetGroups[choice];
const groups = source.map((group) =>
group.filter(
(item) => (includeLinkEditor || !isLinkToolbarItem(item)) && !isFindReplaceItem(item)
)
);
const lastIndex = Math.max(0, groups.length - 1);
if (includeFindReplace) groups[lastIndex] = [...groups[lastIndex], 'find-replace'];
return groups;
}
function isToolbarFamilyItem(
item: WordsToolbarGroupConfig[number]
): item is WordsToolbarFamilyConfig {
return (
(typeof item === 'string' && item.endsWith('-menu')) ||
(typeof item === 'object' && 'part' in item && item.part === 'toolbar-family')
);
}
function toolbarFamilyName(item: WordsToolbarFamilyConfig): WordsToolbarFamilyName {
return typeof item === 'string'
? (item.replace(/-menu$/, '') as WordsToolbarFamilyName)
: item.family;
}
function expandToolbarItem(
item: WordsToolbarGroupConfig[number]
): readonly WordsToolbarLeafItemConfig[] {
if (!isToolbarFamilyItem(item)) return [item as WordsToolbarLeafItemConfig];
if (typeof item !== 'string' && item.items) return item.items;
return demoToolbarFamilyItems[toolbarFamilyName(item)];
}
function isLinkToolbarItem(item: WordsToolbarGroupConfig[number]): boolean {
if (isToolbarFamilyItem(item)) return toolbarFamilyName(item) === 'link';
return (
item === 'link-editor' ||
(typeof item === 'object' && 'part' in item && item.part === 'link-editor')
);
}
function isFindReplaceItem(
item: WordsToolbarGroupConfig[number]
): item is FindReplaceToolbarItem {
return (
item === 'find-replace' ||
(typeof item === 'object' && 'part' in item && item.part === 'find-replace')
);
}
function isCodeLanguagePickerItem(
item: WordsToolbarGroupConfig[number]
): item is WordsToolbarCodeLanguagePickerConfig {
return (
item === 'code-language-picker' ||
(typeof item === 'object' && 'part' in item && item.part === 'code-language-picker')
);
}
function countToolbarItems(groups: readonly WordsToolbarGroupConfig[]): number {
return groups.reduce((total, group) => total + group.length, 0);
}
function describeValue(value: unknown): string {
if (!value || typeof value !== 'object') return '-';
const rec = value as RawValue;
if (rec.kind === 'part-ref') return `part:${String(rec.part ?? '-')}`;
if (rec.kind === 'prop-ref') return `prop:${String(rec.prop ?? '-')}`;
if (rec.kind === 'state-ref') return `state:${String(rec.value ?? rec.prop ?? '-')}`;
if (rec.kind === 'literal') return `literal:${String(rec.value ?? '-')}`;
if (rec.kind === 'translation-ref') return 'translation';
return rec.kind ?? '-';
}
function describeCondition(condition: unknown): string {
if (!condition || typeof condition !== 'object') return '-';
const rec = condition as { when?: string; prop?: string; part?: string };
return [rec.when, rec.prop, rec.part].filter(Boolean).join(':') || '-';
}
function describeTarget(target: unknown): string {
const text = describeValue(target);
return text === '-' ? 'provider' : text;
}
function intentLiteral(value: unknown): Intent | undefined {
return typeof value === 'string' ? (value as Intent) : undefined;
}
function targetForAction(actionTarget: unknown): HTMLElement | null {
const part = String(actionTarget || 'provider');
const selector = part === 'provider' ? '[data-words]' : `[data-words-${part}]`;
return (
(stageRef?.querySelector(selector) as HTMLElement | null) ??
(stageRef?.querySelector('[data-words]') as HTMLElement | null) ??
stageRef
);
}
</script>
<svelte:head>
<meta name="perm-axes" content="disabled,readonly,invalid,required" />
</svelte:head>
<div data-uix-canvas-inner>
<header>
<div data-uix-eyebrow>Editors · Words</div>
<h1 data-uix-page-title>Words</h1>
<p data-uix-page-lede>
Rich-text editor primitive with canonical JSON, contenteditable bridge, command toolbar, slash
commands, editable tables, form serialization, find/replace and semantic events. Morfo
declares the editor parts and semantic events; Soma owns state, selection, input, links,
search and history; Eidos only paints the emitted data contract.
</p>
<div data-uix-page-meta>
<span data-uix-meta-pill
><span data-uix-meta-key>parts</span>{compiled.parts.order.length}</span
>
<span data-uix-meta-pill><span data-uix-meta-key>events</span>{events.length}</span>
<span data-uix-meta-pill><span data-uix-meta-key>sizes</span>{sizes.length}</span>
<span data-uix-meta-pill><span data-uix-meta-key>colors</span>{colors.length}</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>apg</span>
<a href={wordsMorfo.apg} target="_blank" rel="noreferrer">textbox ↗</a>
</span>
</div>
</header>
<div data-uix-stage>
<div
data-uix-stage-area
bind:this={stageRef}
style="display: flex; align-items: stretch; justify-content: center; padding: var(--uix-space-5);"
>
<Words
bind:value
bind:selection
{placeholder}
name="body"
{disabled}
{readonly}
{required}
{invalid}
{commitOnBlur}
{size}
{variant}
{color}
toolbar={toolbarConfig}
{toolbarLayout}
onValueCommit={(_, reason) => (lastCommit = reason)}
>
{#snippet children(snippetProps)}
{@const { selectedLink } = snippetProps}
{#if showLinkEditor && toolbarChoice === 'none'}
<Words.LinkEditor />
{/if}
{#if showFindReplace && toolbarChoice === 'none'}
<Words.FindReplace toolbarItem={false} />
{/if}
<Words.Placeholder>{placeholder}</Words.Placeholder>
<Words.Content
data-perm-step={!disabled && !readonly ? '0' : undefined}
data-perm-label={!disabled && !readonly ? 'edit words content' : undefined}
/>
{#if showBubbleMenu}
<Words.BubbleMenu>
<Words.CommandButton command="bold" aria-label="Bold">
<Bold size="sm" decorative />
</Words.CommandButton>
<Words.CommandButton command="italic" aria-label="Italic">
<Italic size="sm" decorative />
</Words.CommandButton>
<Words.CommandButton command="underline" aria-label="Underline">
<Underline size="sm" decorative />
</Words.CommandButton>
{#if showLinkEditor}
<Words.LinkEditor />
{/if}
</Words.BubbleMenu>
{/if}
{#if showSlashMenu}
<Words.SlashMenu />
{/if}
<Words.HiddenInput />
{#if showDrawer}
<Words.Drawer />
{/if}
<Words.ImageFloatBar snippet={snippetProps} />
<Words.BlockHandle snippet={snippetProps} />
<Words.BlockInserter snippet={snippetProps} />
{#if showStatus}
<Words.Status>
{#if invalid}
Invalid content
{:else}
{required ? 'Required' : 'Optional'}
· {wordCount} words
· {plainText.length} chars
· {selectionState}
{#if selectedLink}
· → {selectedLink.href}
{:else if lastCommit !== 'none'}
· {lastCommit}
{/if}
{/if}
</Words.Status>
{/if}
{/snippet}
</Words>
</div>
<div data-uix-stage-trace>
<span data-uix-stage-trace-key>trace</span>
{#if trace.length === 0}
<span>focus the editor or use toolbar commands to see events</span>
{:else}
{#each trace.slice(0, 3) as entry}
<span>
<span data-uix-stage-trace-event>{entry.event}</span>
· {entry.family}{entry.intent ? ' · ' + entry.intent : ''}
</span>
<span style="color: var(--uix-text-faint)">{fmtTime(entry.at)}</span>
{/each}
{/if}
<span style="margin-inline-start: auto;">
<span data-uix-stage-trace-key>selection</span>
{selectionState}
<span data-uix-stage-trace-key>words</span>
{wordCount}
</span>
</div>
</div>
<div data-uix-tabs role="tablist">
<button data-uix-tab data-active={tab === 'live'} onclick={() => (tab = 'live')}>Live</button>
<button data-uix-tab data-active={tab === 'api'} onclick={() => (tab = 'api')}>
API <span data-uix-tab-count>26</span>
</button>
<button data-uix-tab data-active={tab === 'morfo'} onclick={() => (tab = 'morfo')}>
<span data-uix-layer-badge="morfo">morfo</span>
<span data-uix-tab-count>{partsList.length}p · {events.length}e</span>
</button>
<button data-uix-tab data-active={tab === 'sema'} onclick={() => (tab = 'sema')}>
<span data-uix-layer-badge="sema">sema</span>
<span data-uix-tab-count>{events.length}</span>
</button>
<button data-uix-tab data-active={tab === 'recipe'} onclick={() => (tab = 'recipe')}
>Recipe</button
>
<button data-uix-tab data-active={tab === 'a11y'} onclick={() => (tab = 'a11y')}>A11y</button>
</div>
{#if tab === 'live'}
<section data-uix-section>
<h2 data-uix-section-title>Controls</h2>
<p data-uix-section-desc>
<span data-uix-layer-badge="soma">soma</span> owns document, selection and input.
<span data-uix-layer-badge="eidos">eidos</span> owns size, variant and color.
</p>
<div data-uix-subsection-head>
<span data-uix-layer-badge="soma">soma</span> props · editor state
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>preset</span>
<span data-uix-chips role="radiogroup">
{#each presets as item}
<button data-uix-chip data-active={preset === item} onclick={() => setPreset(item)}>
{item}
</button>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>placeholder</span>
<input bind:value={placeholder} />
</label>
<label data-uix-control>
<span data-uix-control-label>toolbar</span>
<span data-uix-chips role="radiogroup">
{#each toolbarChoices as item}
<button
data-uix-chip
data-active={toolbarChoice === item}
onclick={() => (toolbarChoice = item)}
>
{item}
</button>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>export format</span>
<span data-uix-chips role="radiogroup">
{#each exportFormats as item}
<button
data-uix-chip
data-active={exportFormat === item}
onclick={() => (exportFormat = item)}
>
{item}
</button>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>import format</span>
<span data-uix-chips role="radiogroup">
{#each importFormats as item}
<button
data-uix-chip
data-active={importFormat === item}
onclick={() => (importFormat = item)}
>
{item}
</button>
{/each}
</span>
</label>
{#each ['disabled', 'readonly', 'required', 'invalid', 'commitOnBlur', 'linkEditor', 'findReplace', 'bubbleMenu', 'slashMenu', 'status'] as key}
<label data-uix-control>
<span data-uix-control-label>{key}</span>
<span data-uix-switch>
{#if key === 'disabled'}
<input type="checkbox" bind:checked={disabled} />
<span data-uix-switch-label>{disabled ? 'on' : 'off'}</span>
{:else if key === 'readonly'}
<input type="checkbox" bind:checked={readonly} />
<span data-uix-switch-label>{readonly ? 'on' : 'off'}</span>
{:else if key === 'required'}
<input type="checkbox" bind:checked={required} />
<span data-uix-switch-label>{required ? 'on' : 'off'}</span>
{:else if key === 'invalid'}
<input type="checkbox" bind:checked={invalid} />
<span data-uix-switch-label>{invalid ? 'on' : 'off'}</span>
{:else if key === 'commitOnBlur'}
<input type="checkbox" bind:checked={commitOnBlur} />
<span data-uix-switch-label>{commitOnBlur ? 'on' : 'off'}</span>
{:else if key === 'linkEditor'}
<input type="checkbox" bind:checked={showLinkEditor} />
<span data-uix-switch-label>{showLinkEditor ? 'shown' : 'hidden'}</span>
{:else if key === 'findReplace'}
<input type="checkbox" bind:checked={showFindReplace} />
<span data-uix-switch-label>{showFindReplace ? 'shown' : 'hidden'}</span>
{:else if key === 'bubbleMenu'}
<input type="checkbox" bind:checked={showBubbleMenu} />
<span data-uix-switch-label>{showBubbleMenu ? 'shown' : 'hidden'}</span>
{:else if key === 'slashMenu'}
<input type="checkbox" bind:checked={showSlashMenu} />
<span data-uix-switch-label>{showSlashMenu ? 'shown' : 'hidden'}</span>
{:else}
<input type="checkbox" bind:checked={showStatus} />
<span data-uix-switch-label>{showStatus ? 'shown' : 'hidden'}</span>
{/if}
</span>
</label>
{/each}
</div>
<div data-uix-subsection-head>
<span data-uix-layer-badge="eidos">eidos</span> props · visual treatment
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>size</span>
<span data-uix-chips role="radiogroup">
{#each sizes as item}
<button data-uix-chip data-active={size === item} onclick={() => (size = item)}>
{item}
</button>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>variant</span>
<span data-uix-chips role="radiogroup">
{#each variants as item}
<button data-uix-chip data-active={variant === item} onclick={() => (variant = item)}>
{item}
</button>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>color</span>
<span data-uix-chips role="radiogroup">
{#each colors as item}
<button data-uix-chip data-active={color === item} onclick={() => (color = item)}>
{item}
</button>
{/each}
</span>
</label>
</div>
<div data-uix-subsection-head>Live document</div>
<div data-uix-table-wrap>
<table data-uix-table>
<tbody>
<tr><td class="name">blocks</td><td>{value.children.length}</td></tr>
<tr><td class="name">words</td><td>{wordCount}</td></tr>
<tr><td class="name">selection</td><td>{selectionState}</td></tr>
<tr><td class="name">toolbar</td><td>{toolbarShape}</td></tr>
<tr><td class="name">bubble menu</td><td>{bubbleState}</td></tr>
<tr><td class="name">slash menu</td><td>{slashState}</td></tr>
<tr><td class="name">export</td><td>{exportFormat}</td></tr>
<tr><td class="name">import</td><td>{importFeedback}</td></tr>
<tr><td class="name">link editor</td><td>{showLinkEditor ? 'shown' : 'hidden'}</td></tr>
<tr
><td class="name">find/replace</td><td>{showFindReplace ? 'shown' : 'hidden'}</td></tr
>
<tr><td class="name">last commit</td><td>{lastCommit}</td></tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Document exchange</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>import draft</span>
<textarea bind:value={importDraft} rows="5"></textarea>
</label>
<label data-uix-control>
<span data-uix-control-label>apply import</span>
<button data-uix-chip onclick={importDraftDocument}>import {importFormat}</button>
</label>
</div>
<div data-uix-code style="margin-top: var(--uix-space-3);">
<div data-uix-code-head>
<span data-uix-layer-badge="soma">soma</span>
<span>export · {exportFormat}</span>
<span data-uix-code-lang>{exportFormat}</span>
</div>
<pre><code>{exportPreview}</code></pre>
</div>
<div data-uix-code>
<div data-uix-code-head>
<span data-uix-layer-badge="soma">soma</span>
<span>headless · document and commands</span>
<span data-uix-code-lang>svelte</span>
</div>
<pre><code>{somaSnippet}</code></pre>
</div>
<div data-uix-code style="margin-top: var(--uix-space-3);">
<div data-uix-code-head>
<span data-uix-layer-badge="eidos">eidos</span>
<span>visual · compound editor</span>
<span data-uix-code-lang>svelte</span>
</div>
<pre><code>{eidosSnippet}</code></pre>
</div>
</section>
{/if}
{#if tab === 'api'}
<section data-uix-section>
<h2 data-uix-section-title>API surface</h2>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Prop / part</th><th>Owner</th><th>Default</th><th>Notes</th></tr></thead>
<tbody>
<tr
><td class="name">value</td><td>soma</td><td class="default">empty document</td><td
>Canonical JSON document, bindable.</td
></tr
>
<tr
><td class="name">selection</td><td>soma</td><td class="default">null</td><td
>Document selection, bindable.</td
></tr
>
<tr
><td class="name">placeholder</td><td>soma</td><td class="default empty">-</td><td
>Used by Placeholder while empty.</td
></tr
>
<tr
><td class="name">name</td><td>soma</td><td class="default empty">-</td><td
>Enables HiddenInput JSON serialization.</td
></tr
>
<tr
><td class="name">disabled / readonly</td><td>soma</td><td class="default">false</td
><td>Disables editing or keeps read-only focus semantics.</td></tr
>
<tr
><td class="name">required / invalid</td><td>soma</td><td class="default">false</td
><td>ARIA and recipe state, Field-compatible.</td></tr
>
<tr
><td class="name">commitOnBlur</td><td>soma</td><td class="default">true</td><td
>Fires commit-content on blur.</td
></tr
>
<tr
><td class="name">onValueCommit</td><td>soma</td><td class="default empty">-</td><td
>Receives document and reason.</td
></tr
>
<tr
><td class="name">importContent</td><td>soma</td><td class="default"
>json | text | html | markdown</td
><td>Snippet helper that replaces the document through the normalized engine.</td></tr
>
<tr
><td class="name">exportContent</td><td>soma</td><td class="default"
>json | text | html | markdown</td
><td>Snippet helper for clean export without DOM metadata.</td></tr
>
<tr
><td class="name">Content</td><td>soma</td><td class="default">required</td><td
>contenteditable textbox surface.</td
></tr
>
<tr
><td class="name">toolbar</td><td>eidos</td><td class="default">false</td><td
>Optional property: false, true, minimal, formatting, full or custom command/family
groups.</td
></tr
>
<tr
><td class="name">ToolbarFamilyMenu</td><td>eidos</td><td class="default">preset</td
><td
>Groups toolbar actions into submenus such as text, blocks, lists, alignment,
insert, table, links and tools.</td
></tr
>
<tr
><td class="name">Toolbar / ToolbarGroup</td><td>soma</td><td class="default"
>optional</td
><td>Manual composition stays available for fully custom command layouts.</td></tr
>
<tr
><td class="name">CommandButton</td><td>soma</td><td class="default">optional</td><td
>Runs command names and exposes active state, including block commands like
<code>code-block</code>.</td
></tr
>
<tr
><td class="name">insert-table</td><td>soma</td><td class="default">2 x 2</td><td
>Inserts a canonical editable table block and a trailing paragraph for continued
writing.</td
></tr
>
<tr
><td class="name">table row/column</td><td>soma</td><td class="default"
>cursor cell</td
><td
><code>insert-table-row</code>, <code>insert-table-column</code>,
<code>delete-table-row</code> and <code>delete-table-column</code> edit the current table
structure.</td
></tr
>
<tr
><td class="name">table format</td><td>soma/eidos</td><td class="default"
>cursor cell</td
><td
>Header row/column, cell align, vertical align, cell tone, striped rows and compact
table live in the <code>table</code> toolbar family.</td
></tr
>
<tr
><td class="name">BubbleMenu</td><td>soma/eidos</td><td class="default">optional</td
><td
>Selection-anchored toolbar that appears only for text ranges and reuses command
buttons.</td
></tr
>
<tr
><td class="name">SlashMenu</td><td>soma/eidos</td><td class="default">optional</td
><td
>Caret-anchored block command menu opened by slash queries and committed by
<code>Enter</code> or <code>Tab</code>.</td
></tr
>
<tr
><td class="name">HeadingPicker</td><td>eidos</td><td class="default">optional</td><td
>Heading level dropdown: H1, H2, H3, Paragraph.</td
></tr
>
<tr
><td class="name">CodeLanguagePicker</td><td>eidos</td><td class="default"
>optional</td
><td
>Code block language dropdown backed by
<code>currentCodeLanguage</code> and <code>setCodeLanguage</code>.</td
></tr
>
<tr
><td class="name">LinkEditor</td><td>soma/eidos</td><td class="default">optional</td
><td>Form part that applies or removes links against the current selection.</td></tr
>
<tr
><td class="name">FindReplace</td><td>soma/eidos</td><td class="default">optional</td
><td
>Search panel that marks matches, moves selection, supports match-case, whole-word
and regex search, and replaces all matches.</td
></tr
>
<tr
><td class="name">selectedLink</td><td>soma</td><td class="default">null</td><td
>Snippet state for the link under the current document selection.</td
></tr
>
<tr
><td class="name">currentCodeLanguage / setCodeLanguage</td><td>soma</td><td
class="default">undefined</td
><td
>Snippet state and helper for normalized language metadata on the selected code
block.</td
></tr
>
<tr
><td class="name">insertLink / unlink</td><td>soma</td><td class="default">helpers</td
><td>Selection-aware commands exposed to custom toolbars and link forms.</td></tr
>
<tr
><td class="name">HiddenInput / Status</td><td>soma</td><td class="default"
>optional</td
><td>Form serialization and polite status.</td></tr
>
<tr
><td class="name">size</td><td>eidos</td><td class="default">md</td><td
>{sizes.join(' | ')}</td
></tr
>
<tr
><td class="name">variant</td><td>eidos</td><td class="default">surface</td><td
>{variants.join(' | ')}</td
></tr
>
<tr
><td class="name">color</td><td>eidos</td><td class="default">primary</td><td
>{colors.join(' | ')}</td
></tr
>
<tr
><td class="name">reference row</td><td>audit</td><td class="default">V1</td><td
>React Aria/WAI-ARIA inform textbox + toolbar; Lexical informs editor model;
Edra/Tiptap stays a benchmark, not a dependency.</td
></tr
>
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'morfo'}
<section data-uix-section>
<h2 data-uix-section-title>Morfo contract</h2>
<div data-uix-table-wrap>
<table data-uix-table>
<tbody>
<tr><td class="name">name</td><td>{wordsMorfo.name}</td></tr>
<tr><td class="name">kebab</td><td>{wordsMorfo.kebab}</td></tr>
<tr><td class="name">scope</td><td>{wordsMorfo.scope.join(' + ')}</td></tr>
<tr
><td class="name">apg</td><td
><a href={wordsMorfo.apg} target="_blank" rel="noreferrer">textbox</a></td
></tr
>
<tr><td class="name">parts</td><td>{wordsMorfo.parts.length}</td></tr>
<tr><td class="name">events</td><td>{wordsMorfo.events.length}</td></tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Parts overview</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead
><tr
><th>Part</th><th>Marker</th><th>Element</th><th>Role</th><th>Archetype</th><th
>States</th
><th>Optional</th></tr
></thead
>
<tbody>
{#each partsList as part}
<tr>
<td class="name">{part.kebab}</td>
<td><code data-uix-part-marker>[{part.marker}]</code></td>
<td class="type">&lt;{part.defaultElement}&gt;</td>
<td class="type">{part.role ?? '-'}</td>
<td>{part.archetype ?? '-'}</td>
<td>{part.states?.join(' | ') ?? '-'}</td>
<td class="default">{part.optional ? 'yes' : 'no'}</td>
</tr>
{/each}
</tbody>
</table>
</div>
{#each wordsMorfo.parts as rawPart}
{@const partAny = rawPart as unknown as RawPart}
{@const dataAttrs = compiled.contracts.dataAttrsByPart.get(partAny.kebab) ?? []}
{@const ariaAttrs = partAny.aria ?? []}
{@const keyboard = partAny.keyboard ?? []}
{#if dataAttrs.length || ariaAttrs.length || keyboard.length}
<div data-uix-subsection-head>{partAny.kebab}</div>
{#if dataAttrs.length}
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Data attr</th><th>Values</th><th>Source</th></tr></thead>
<tbody>
{#each dataAttrs as attr}
<tr>
<td class="name">{attr.attr}</td>
<td class="type">{attr.values ? attr.values.join(' | ') : '-'}</td>
<td
>{'value' in attr
? describeValue((attr as { value?: unknown }).value)
: '-'}</td
>
</tr>
{/each}
</tbody>
</table>
</div>
{/if}
{#if ariaAttrs.length}
<div data-uix-table-wrap>
<table data-uix-table>
<thead
><tr><th>ARIA attr</th><th>Source</th><th>Condition</th><th>Severity</th></tr
></thead
>
<tbody>
{#each ariaAttrs as attr}
<tr>
<td class="name">{attr.attr}</td>
<td>{describeValue(attr.value)}</td>
<td>{describeCondition(attr.condition)}</td>
<td>{attr.severity ?? '-'}</td>
</tr>
{/each}
</tbody>
</table>
</div>
{/if}
{#if keyboard.length}
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Key</th><th>Action</th></tr></thead>
<tbody>
{#each keyboard as key}
<tr><td><span data-uix-kbd>{key.key}</span></td><td>{key.action}</td></tr>
{/each}
</tbody>
</table>
</div>
{/if}
{/if}
{/each}
<div data-uix-subsection-head>Events declaration</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead
><tr
><th>Name</th><th>Family</th><th>Verb</th><th>Sequence</th><th>Intent</th><th
>Target</th
><th>Prewrite</th><th>Commit</th></tr
></thead
>
<tbody>
{#each wordsMorfo.events as event}
{@const eventAny = event as unknown as RawEvent}
<tr>
<td class="name">{eventAny.name}</td>
<td class="type">{eventAny.semantic.family}</td>
<td>{eventAny.semantic.verb ?? '-'}</td>
<td>{eventAny.semantic.sequence ?? '-'}</td>
<td
>{typeof eventAny.semantic.intent === 'string'
? eventAny.semantic.intent
: describeValue(eventAny.semantic.intent)}</td
>
<td>{describeTarget(eventAny.semantic.target)}</td>
<td>{eventAny.prewrite ? 'yes' : '-'}</td>
<td>{eventAny.commit ? 'yes' : '-'}</td>
</tr>
{/each}
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'sema'}
<section data-uix-section>
<h2 data-uix-section-title>
<span data-uix-layer-badge="sema">sema</span> · events + playback
</h2>
<p data-uix-section-desc>
Typing stays local until it commits; discrete focus, format, link, history, clear and
invalid input actions emit semantic events.
</p>
<div data-uix-table-wrap>
<table data-uix-table>
<thead
><tr
><th>Name</th><th>Family</th><th>Verb</th><th>Sequence</th><th>Intent</th><th
>Target</th
><th>Play</th></tr
></thead
>
<tbody>
{#each events as action}
<tr>
<td class="name">{action.name}</td>
<td class="type">{action.semantic.family}</td>
<td>{action.semantic.verb ?? '-'}</td>
<td>{action.semantic.sequence ?? '-'}</td>
<td>{action.semantic.intent ?? '-'}</td>
<td>{action.target}</td>
<td>
<button
data-uix-play
onclick={() => {
const target = targetForAction(action.target);
if (!target) return;
void uix.events?.emit({
name: action.name,
family: action.semantic.family,
intent: intentLiteral(action.semantic.intent),
target
});
}}
>
Play
</button>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'recipe'}
<section data-uix-section>
<h2 data-uix-section-title>Eidos recipe</h2>
<p data-uix-section-desc>
Selectors live in <code>src/uix/eidos/components/words/words.css</code>; public tokens are
declared under <code>THEME_BASE_RECIPE_TOKENS.words</code>.
</p>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Selector</th><th>Source</th><th>Role</th></tr></thead>
<tbody>
{#each recipeSelectors as row}
<tr>
<td class="name">{row.selector}</td>
<td><span data-uix-tag data-kind={row.kind}>{row.source}</span></td>
<td>{row.note}</td>
</tr>
{/each}
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'a11y'}
<section data-uix-section>
<h2 data-uix-section-title>Accessibility</h2>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Concern</th><th>Contract</th></tr></thead>
<tbody>
<tr
><td class="name">Content</td><td
><code>role="textbox"</code>, <code>aria-multiline="true"</code> and contenteditable managed
by Soma.</td
></tr
>
<tr
><td class="name">Toolbar</td><td
><code>role="toolbar"</code> with <code>aria-orientation="horizontal"</code>.</td
></tr
>
<tr
><td class="name">Buttons</td><td
>Command buttons are native buttons; toggle commands expose <code>aria-pressed</code
>.</td
></tr
>
<tr
><td class="name">BubbleMenu</td><td
>Contextual selection toolbar uses <code>role="toolbar"</code>, keeps focus from
collapsing the editor selection on pointer down, and hides when no text range is
available.</td
></tr
>
<tr
><td class="name">SlashMenu</td><td
>Slash commands use <code>role="listbox"</code> with native button options, preserve
editor focus on pointer down and commit the active block command with
<code>Enter</code> or <code>Tab</code>.</td
></tr
>
<tr
><td class="name">Link editor</td><td
>Link editing is a native <code>form</code> inside Popover; URL, apply, unlink and close
controls stay keyboard reachable and operate on Soma selection state.</td
></tr
>
<tr
><td class="name">Find/replace</td><td
>Find/replace uses <code>role="search"</code>, native inputs, live match counts and
disabled/readonly/invalid state from Soma. The query field focuses on open;
<code>Enter</code>
moves to the next match and <code>Shift+Enter</code> moves to the previous one.</td
></tr
>
<tr
><td class="name">Pickers</td><td
>Heading and code language popovers use native buttons in a
<code>role="group"</code> panel. Arrow keys cycle options, <code>Home</code> and
<code>End</code> jump to the edges, and <code>Escape</code> closes the panel.</td
></tr
>
<tr
><td class="name">Readonly</td><td
>Readonly keeps content focusable and sets <code>aria-readonly</code>.</td
></tr
>
<tr
><td class="name">Disabled</td><td
>Disabled removes editing and prevents command execution.</td
></tr
>
<tr
><td class="name">Status</td><td
>Status uses <code>role="status"</code> and <code>aria-live="polite"</code>.</td
></tr
>
<tr
><td class="name">Form</td><td
>HiddenInput serializes the full JSON document when <code>name</code> is present.</td
></tr
>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Keyboard</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Key</th><th>Action</th></tr></thead>
<tbody>
{#each (wordsMorfo.parts.find((part) => part.kebab === 'content') as unknown as RawPart | undefined)?.keyboard ?? [] as key}
<tr><td><span data-uix-kbd>{key.key}</span></td><td>{key.action}</td></tr>
{/each}
<tr
><td><span data-uix-kbd>Enter</span></td><td>Find next match from query input</td></tr
>
<tr
><td><span data-uix-kbd>Shift+Enter</span></td><td
>Find previous match from query input</td
></tr
>
<tr
><td><span data-uix-kbd>Enter</span></td><td
>Replace all matches from replacement input</td
></tr
>
<tr
><td><span data-uix-kbd>Arrow keys</span></td><td
>Move through heading and code language picker options</td
></tr
>
<tr
><td><span data-uix-kbd>Home / End</span></td><td
>Jump to the first or last picker option</td
></tr
>
<tr><td><span data-uix-kbd>Escape</span></td><td>Close picker popovers</td></tr>
</tbody>
</table>
</div>
</section>
{/if}
</div>

Powered by TurnKey Linux.