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

1425 lines
45 KiB

<script lang="ts">
import {
Words,
type WordsColor,
type WordsSize,
type WordsToolbarConfig,
type WordsToolbarGroupConfig,
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,
WordsToolbarOrientation
} 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 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 orientations: WordsToolbarOrientation[] = ['horizontal', 'vertical'];
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: [['bold', 'italic', 'underline']],
formatting: [
['bold', 'italic', 'underline', 'strike', 'code'],
['paragraph', { command: 'heading', level: 1, label: 'Heading 1' }, 'quote']
],
full: [
['undo', 'redo'],
['bold', 'italic', 'underline', 'strike', 'code'],
[
'paragraph',
{ command: 'heading', level: 1, label: 'Heading 1' },
'quote',
'unordered-list',
'ordered-list',
'check-list'
],
['link-editor', 'unlink', 'clear-formatting', 'clear-document', 'commit']
]
};
const toolbarCustomGroups: WordsToolbarGroupConfig[] = [
['undo', 'redo'],
[
{ command: 'heading', level: 1, label: 'Title' },
{ command: 'paragraph', label: 'Body' },
'quote'
],
['bold', 'italic', 'code'],
['link-editor', 'unlink', '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 showBubbleMenu = $state(true);
let showStatus = $state(true);
let orientation = $state<WordsToolbarOrientation>('horizontal');
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));
const toolbarConfig = $derived<WordsToolbarConfig>(
toolbarChoice === 'none' ? false : toolbarSnippetGroups
);
const toolbarCommandCount = $derived(countToolbarItems(toolbarSnippetGroups));
const toolbarShape = $derived(
toolbarChoice === 'none'
? 'disabled'
: `${toolbarChoice} · ${toolbarSnippetGroups.length} groups · ${toolbarCommandCount} items`
);
const bubbleState = $derived(showBubbleMenu ? 'selection toolbar enabled' : 'selection toolbar off');
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}',
'>',
...somaToolbarSnippet(toolbarSnippetGroups, orientation),
...(showLinkEditor && toolbarChoice === 'none' ? somaLinkEditorSnippet() : []),
' <Words.Placeholder />',
' <Words.Content />',
...(showBubbleMenu ? somaBubbleMenuSnippet() : []),
' <Words.HiddenInput />',
showStatus && ' <Words.Status />',
'</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}',
orientation !== 'horizontal' && ` toolbarOrientation="${orientation}"`,
disabled && ' disabled',
readonly && ' readonly',
required && ' required',
invalid && ' invalid',
!commitOnBlur && ' commitOnBlur={false}',
'>',
showLinkEditor && toolbarChoice === 'none' && ' <Words.LinkEditor />',
' <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>',
' <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-toolbar][data-orientation]',
source: 'morfo',
kind: 'soma',
note: 'toolbar axis'
},
{
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-tool-popover-trigger]',
source: 'eidos',
kind: 'eidos',
note: 'toolbar tool disclosure'
},
{
selector: '[data-words-tool-popover]',
source: 'eidos',
kind: 'eidos',
note: 'shared floating tool shell'
},
{
selector: '[data-words-tool-popover-close]',
source: 'eidos',
kind: 'eidos',
note: 'shared close affordance'
},
{
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-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-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: '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',
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: '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',
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);
}
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');
}
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[],
toolbarOrientation: WordsToolbarOrientation
): string[] {
if (groups.length === 0) return [];
return [
` <Words.Toolbar orientation="${toolbarOrientation}">`,
...groups.flatMap((group) => [
' <Words.ToolbarGroup>',
...group.flatMap((command) => somaCommandSnippet(command)),
' </Words.ToolbarGroup>'
]),
' </Words.Toolbar>'
];
}
function somaCommandSnippet(item: WordsToolbarGroupConfig[number]): string[] {
if (item === 'link-editor' || (typeof item === 'object' && 'part' in item)) {
return somaLinkEditorSnippet().map((line) => ` ${line.trimStart()}`);
}
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 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
): WordsToolbarGroupConfig[] {
if (choice === 'none') return [];
const source = choice === 'custom' ? toolbarCustomGroups : toolbarPresetGroups[choice];
const groups = source.map((group) =>
group.filter(
(item) => item !== 'link-editor' && !(typeof item === 'object' && 'part' in item)
)
);
if (!includeLinkEditor) return groups;
const lastIndex = Math.max(0, groups.length - 1);
groups[lastIndex] = ['link-editor', ...groups[lastIndex]];
return groups;
}
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, form
serialization and semantic events. Morfo declares the editor parts and semantic events; Soma
owns state, selection, input, links 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);"
>
{#key documentRevision}
<Words
bind:value
bind:selection
{placeholder}
name="body"
{disabled}
{readonly}
{required}
{invalid}
{commitOnBlur}
{size}
{variant}
{color}
toolbar={toolbarConfig}
toolbarOrientation={orientation}
onValueCommit={(_, reason) => (lastCommit = reason)}
>
{#snippet children({ selectedLink })}
{#if showLinkEditor && toolbarChoice === 'none'}
<Words.LinkEditor />
{/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}
<Words.HiddenInput />
{#if showStatus}
<Words.Status>
{invalid
? 'Invalid content'
: `${required ? 'Required editor' : 'Optional editor'} · ${wordCount} words · ${selectedLink ? selectedLink.href : lastCommit}`}
</Words.Status>
{/if}
{/snippet}
</Words>
{/key}
</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>24</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>toolbar orientation</span>
<span data-uix-chips role="radiogroup">
{#each orientations as item}
<button
data-uix-chip
data-active={orientation === item}
onclick={() => (orientation = 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', 'bubbleMenu', '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 === 'bubbleMenu'}
<input type="checkbox" bind:checked={showBubbleMenu} />
<span data-uix-switch-label>{showBubbleMenu ? '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">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">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 groups.</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.</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">ToolPopover</td><td>eidos</td><td class="default">optional</td><td
>Reusable toolbar tool shell: icon trigger, floating panel, close button and dismiss
guard.</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">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">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 orientation propagated to ARIA.</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">Link editor</td><td
>Link editing is a native <code>form</code> inside a reusable tool popover; URL, apply,
unlink and close controls stay keyboard reachable and operate on Soma selection state.</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}
</tbody>
</table>
</div>
</section>
{/if}
</div>

Powered by TurnKey Linux.