[ui] Domi UI: vendor @domi/ui v1.1.0 (TextField editable mode, opt-in; unedited)

This commit is contained in:
2026-11-23 01:00:44 +01:00
parent c9aa55ec99
commit 43230be026
9 changed files with 242 additions and 18 deletions
+10
View File
@@ -1,5 +1,15 @@
# Changelog
## 1.1.0 (2026-11-23)
- **TextField `as="editable" | "auto"`**: the field drawn with a contenteditable `role="textbox"` instead of a native
`<input>`/`<textarea>`, because on Android the WebView sends an Autofill request to Google whenever a native text
field gets focus (found by Amicitia). Same look, seal, keys and states; plain-text paste; label by
`aria-labelledby`; `inputmode` from the type; a hidden input for `name`. `auto` = editable on Android only.
Passwords always stay native. New `editor` binding; `input` keeps its type. `isAndroid()` exported.
- Docs: the credit goes by repo visibility (Mark): apps whose own repo is public, and public repos carrying a copy,
show it; apps built from a private repo show none, paid or free.
## 1.0.4 (2026-11-23)
- Fix: `Strike.svelte` had no `<script>` block, so a consumer whose tsconfig has `allowJs` off (Ludus) got "Could not
+1 -1
View File
@@ -1,4 +1,4 @@
This folder is @domi/ui v1.0.4, copied unchanged from domi-design by tools/vendor.mjs.
This folder is @domi/ui v1.1.0, copied unchanged from domi-design by tools/vendor.mjs.
Licence: Common Public Attribution License 1.0 (LICENSE). Original Code: @domi/ui. Initial Developer: Marek Novák.
Attribution Information (Exhibit B). Any app built with this code shows, prominently in its user interface when
+1 -1
View File
@@ -1 +1 @@
v1.0.4
v1.1.0
+2 -2
View File
@@ -1,7 +1,7 @@
{
"name": "@domi/ui",
"version": "1.0.4",
"description": "The Domi design system: tokens for every Domi app, struck buttons and fields with an integrated send button, Svelte 5 components. Vendored copy of v1.0.4: do not edit here; change domi-design and vendor the next tag.",
"version": "1.1.0",
"description": "The Domi design system: tokens for every Domi app, struck buttons and fields with an integrated send button, Svelte 5 components. Vendored copy of v1.1.0: do not edit here; change domi-design and vendor the next tag.",
"license": "CPAL-1.0",
"type": "module",
"svelte": "./src/index.ts",
+118 -13
View File
@@ -5,6 +5,7 @@
import { strike } from '../lib/strike';
import { canSend, enterAction, failureText, isSoftKeyboard, type FieldState } from '../lib/keys';
import type { IconName } from '../lib/icons';
import { caretToEnd, inputmodeFor, insertPlainText, isAndroid, readText, writeText } from '../lib/editable';
type Action = 'send' | 'search' | 'next' | 'save';
@@ -55,8 +56,16 @@
force?: string;
sendForce?: string;
class?: string;
/** The input element, for focusing it from outside. */
/** The input element, for focusing it from outside (null in editable mode: see editor). */
input?: HTMLInputElement | HTMLTextAreaElement | null;
/**
* input (default): a native <input>/<textarea>. editable: a contenteditable box with role="textbox": on Android
* the WebView sends an Autofill request to Google whenever a native text field gets focus; an editable box does
* not. auto: editable on Android, native elsewhere. Passwords are always native (masking, password managers).
*/
as?: 'input' | 'editable' | 'auto';
/** The editable box in editable mode, for focusing it from outside. */
editor?: HTMLElement | null;
}
let {
@@ -94,12 +103,16 @@
sendForce,
class: cls = '',
input = $bindable(null),
as = 'input',
editor = $bindable(null),
}: Props = $props();
const uid = $props.id();
const fieldId = $derived(id ?? `domi-field-${uid}`);
const hintId = `domi-hint-${uid}`;
const errorId = `domi-error-${uid}`;
const labelId = `domi-label-${uid}`;
const android = isAndroid();
const words: Record<Action, { label: string; icon: IconName; key: 'send' | 'search' | 'next' | 'done'; busy: string; done: string; fail: string }> = {
send: { label: 'Send', icon: 'send', key: 'send', busy: 'Sending', done: 'Sent', fail: 'Could not send. Try again.' },
@@ -124,6 +137,10 @@
const described = $derived([hint && hintId, message && errorId].filter(Boolean).join(' ') || undefined);
const inputType = $derived(type === 'password' && revealed ? 'text' : type);
const clears = $derived(clearOnSend ?? action === 'send');
const editable = $derived(type !== 'password' && (as === 'editable' || (as === 'auto' && android)));
/** The element that takes the text, whichever kind it is. */
const box = $derived<HTMLElement | null>(editable ? editor : input);
const locked = $derived(disabled || readonly || shown === 'sending');
function hold(): number {
const v = getComputedStyle(document.documentElement).getPropertyValue('--domi-dur-hold');
@@ -133,22 +150,22 @@
function nextField(from: HTMLElement) {
const scope = from.closest('form') ?? document;
const all = [...scope.querySelectorAll<HTMLElement>('.domi-field__input, input, textarea, select')].filter(
(el) => !el.hasAttribute('disabled') && el.getAttribute('type') !== 'hidden',
(el) => !el.hasAttribute('disabled') && el.getAttribute('aria-disabled') !== 'true' && el.getAttribute('type') !== 'hidden',
);
const i = all.indexOf(from);
all[i + 1]?.focus();
}
async function submit() {
if (!sendable || !input) return;
const el = input;
if (!sendable || !box) return;
const el = box;
const text = value;
clearTimeout(timer);
failure = '';
if (!onsend) {
// No handler: behave like the form's own submit (or, for next, move on).
if (action === 'next') nextField(el);
else el.form?.requestSubmit();
else el.closest('form')?.requestSubmit();
return;
}
const result = onsend(text);
@@ -168,7 +185,7 @@
}
}
function done(el: HTMLInputElement | HTMLTextAreaElement) {
function done(el: HTMLElement) {
if (clears) value = '';
if (action === 'next') {
auto = 'idle';
@@ -194,6 +211,9 @@
} else if (r === 'ignore' && e.key === 'Enter' && e.altKey && !multiline) {
// Alt+Enter must not submit the form. An Enter that ends an input method's composition is left alone.
e.preventDefault();
} else if (editable && !multiline && e.key === 'Enter' && !e.isComposing && e.keyCode !== 229) {
// A single-line editable box never takes a line break.
e.preventDefault();
}
}
@@ -206,10 +226,55 @@
grow();
}
// Editable mode: the box's text is the value. Typing, paste and drop bring plain text only.
function edited() {
if (!editor) return;
let t = readText(editor);
let rewrite = false;
if (!multiline && /\n/.test(t)) {
t = t.replace(/\r?\n/g, ' ');
rewrite = true;
}
if (maxlength !== undefined && t.length > maxlength) {
t = t.slice(0, maxlength);
rewrite = true;
}
if (t === '' && editor.childNodes.length > 0) rewrite = true; // a stray <br> would hide the placeholder
if (rewrite) {
writeText(editor, t);
if (t) caretToEnd(editor);
}
value = t;
typed();
}
function pasted(e: ClipboardEvent) {
if (!editor) return;
e.preventDefault();
if (locked) return;
let t = e.clipboardData?.getData('text/plain') ?? '';
if (!multiline) t = t.replace(/\r?\n/g, ' ');
insertPlainText(editor, t);
edited();
}
function dropped(e: DragEvent) {
if (!editor) return;
e.preventDefault();
const t = e.dataTransfer?.getData('text/plain') ?? '';
if (!t || locked) return;
editor.focus();
insertPlainText(editor, multiline ? t : t.replace(/\r?\n/g, ' '));
edited();
}
// A value set from outside (bind:value, a field cleared after sending) is written into the box.
$effect(() => {
const v = value;
if (editable && editor && readText(editor) !== v) writeText(editor, v);
});
// field-sizing: content grows the textarea in Chromium (WebView2, Android WebView); elsewhere, grow it here.
const sizesItself = typeof CSS !== 'undefined' && CSS.supports?.('field-sizing', 'content');
function grow() {
if (!multiline || sizesItself || !input) return;
if (!multiline || sizesItself || !(input instanceof HTMLTextAreaElement)) return;
input.style.height = 'auto';
input.style.height = `${input.scrollHeight}px`;
}
@@ -219,11 +284,16 @@
});
$effect(() => () => clearTimeout(timer));
$effect(() => {
if (autofocus) input?.focus();
if (autofocus) box?.focus();
});
function focusBox() {
if (!box) return;
box.focus();
if (editable) caretToEnd(box);
}
function focusInput(e: MouseEvent) {
if (e.target === e.currentTarget) input?.focus();
if (e.target === e.currentTarget) focusBox();
}
</script>
@@ -233,12 +303,47 @@
data-empty={empty ? '' : undefined}
data-disabled={disabled ? '' : undefined}
>
<label class={['domi-field__label', hideLabel && 'domi-sr']} for={fieldId}>
{label}{#if optional}<span class="domi-field__optional">{" (optional)"}</span>{/if}
</label>
{#if editable}
<!-- An editable box is not a labelable element: the label names it through aria-labelledby; a click focuses it. -->
<!-- svelte-ignore a11y_click_events_have_key_events a11y_no_static_element_interactions -->
<span class={['domi-field__label', hideLabel && 'domi-sr']} id={labelId} role="presentation" onclick={focusBox}>
{label}{#if optional}<span class="domi-field__optional">{" (optional)"}</span>{/if}
</span>
{:else}
<label class={['domi-field__label', hideLabel && 'domi-sr']} for={fieldId} id={labelId}>
{label}{#if optional}<span class="domi-field__optional">{" (optional)"}</span>{/if}
</label>
{/if}
<!-- svelte-ignore a11y_click_events_have_key_events a11y_no_static_element_interactions -->
<div class="domi-field__well" role="presentation" data-force={force} onclick={focusInput}>
{#if multiline}
{#if editable}
<div
bind:this={editor}
class={['domi-field__input', 'domi-field__input--editable', multiline && 'domi-field__input--lines']}
id={fieldId}
role="textbox"
tabindex={disabled ? -1 : 0}
contenteditable={locked ? 'false' : 'plaintext-only'}
aria-labelledby={labelId}
aria-multiline={multiline ? 'true' : 'false'}
aria-describedby={described}
aria-invalid={message ? 'true' : undefined}
aria-required={required ? 'true' : undefined}
aria-readonly={readonly || shown === 'sending' ? 'true' : undefined}
aria-disabled={disabled ? 'true' : undefined}
aria-placeholder={placeholder}
data-placeholder={placeholder}
inputmode={inputmode ?? inputmodeFor(type)}
enterkeyhint={multiline ? (w.key === 'done' ? 'done' : 'enter') : w.key === 'done' ? 'done' : w.key}
spellcheck={spellcheck ?? true}
style:--_rows-max={rows}
onkeydown={keydown}
oninput={edited}
onpaste={pasted}
ondrop={dropped}
></div>
{#if name}<input type="hidden" {name} {value} />{/if}
{:else if multiline}
<textarea
bind:this={input}
bind:value
+37
View File
@@ -512,6 +512,43 @@ textarea.domi-field__input {
align-items: flex-end;
}
/*
* Editable mode (as="editable"): a contenteditable box in place of <input>/<textarea>, so an Android WebView sends no
* Autofill request. One line: centred, no wrap, scrolls sideways. Several lines: grows to --_rows-max, then scrolls.
*/
.domi-field__input--editable {
align-self: center;
min-height: var(--domi-leading-md);
overflow-x: auto;
overflow-y: hidden;
white-space: pre;
cursor: text;
scrollbar-width: none;
}
.domi-field__input--editable::-webkit-scrollbar {
display: none;
}
.domi-field__input--lines {
align-self: stretch;
padding-top: 8px;
padding-bottom: 8px;
min-height: calc(var(--domi-leading-md) + 16px);
max-height: calc(var(--domi-leading-md) * var(--_rows-max, 8) + 16px);
overflow-x: hidden;
overflow-y: auto;
white-space: pre-wrap;
overflow-wrap: anywhere;
scrollbar-width: thin;
}
.domi-field__input--editable:empty::before {
content: attr(data-placeholder);
color: var(--domi-muted);
pointer-events: none;
}
.domi-field__input--editable[contenteditable='false'] {
cursor: default;
}
/* The seal: the send button set into the right end of the field. */
.domi-send {
--_s: max(var(--domi-size-send-md), var(--domi-send-target));
+1
View File
@@ -14,6 +14,7 @@ export { default as Icon } from './components/Icon.svelte';
export { default as Strike } from './components/Strike.svelte';
export { default as DomiCredit } from './components/DomiCredit.svelte';
export { DOMI_ATTRIBUTION, DOMI_ATTRIBUTION_TEXT } from './lib/credit';
export { isAndroid } from './lib/editable';
export { strike } from './lib/strike';
export { icons, type IconName } from './lib/icons';
+71
View File
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: CPAL-1.0
/**
* Helpers for TextField's editable mode: a contenteditable box with role="textbox" in place of <input>/<textarea>.
* Why: on Android the WebView asks Google's Autofill service (a network request) as soon as a text <input> or
* <textarea> gets focus, and no attribute stops it (found by Amicitia). A contenteditable box is not an autofill
* target. Plain text only: paste and drop never bring markup.
*/
/** True in an Android WebView or browser, where editable mode avoids the Autofill request. Safe during SSR. */
export function isAndroid(): boolean {
return typeof navigator !== 'undefined' && /Android/i.test(navigator.userAgent);
}
/** The box's text, with line breaks as \n. An emptied box that only holds a stray line break reads as ''. */
export function readText(el: HTMLElement): string {
const raw = typeof el.innerText === 'string' ? el.innerText : (el.textContent ?? '');
return raw === '\n' ? '' : raw;
}
/** Replaces the box's content with plain text (no markup can enter). */
export function writeText(el: HTMLElement, text: string): void {
el.textContent = text;
}
/** Puts the caret after the last character. */
export function caretToEnd(el: HTMLElement): void {
const sel = typeof getSelection === 'function' ? getSelection() : null;
if (!sel || typeof document.createRange !== 'function') return;
const range = document.createRange();
range.selectNodeContents(el);
range.collapse(false);
sel.removeAllRanges();
sel.addRange(range);
}
/**
* Inserts plain text at the caret. Uses the browser's own insertion where it exists, so undo keeps working;
* otherwise inserts a text node at the selection.
*/
export function insertPlainText(el: HTMLElement, text: string): void {
try {
if (typeof document.execCommand === 'function' && document.execCommand('insertText', false, text)) return;
} catch {
// Fall through to the Range insertion.
}
const sel = typeof getSelection === 'function' ? getSelection() : null;
const node = document.createTextNode(text);
if (!sel || sel.rangeCount === 0 || !el.contains(sel.getRangeAt(0).commonAncestorContainer)) {
el.append(node);
return;
}
const range = sel.getRangeAt(0);
range.deleteContents();
range.insertNode(node);
range.setStartAfter(node);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
}
/** The soft keyboard a type asks for, as inputmode (an editable box has no type attribute). */
export function inputmodeFor(type: string): 'text' | 'email' | 'url' | 'tel' | 'decimal' | 'search' {
const map: Record<string, 'email' | 'url' | 'tel' | 'decimal' | 'search'> = {
email: 'email',
url: 'url',
tel: 'tel',
number: 'decimal',
search: 'search',
};
return map[type] ?? 'text';
}
+1 -1
View File
@@ -2,7 +2,7 @@
/* eslint-disable */
export const tokens = {
"name": "@domi/ui",
"version": "1.0.4",
"version": "1.1.0",
"note": "GENERATED by tools/build-tokens.mjs. Colours are sRGB hex. Use roles, never the hex in a component.",
"themes": {
"dark": {