diff --git a/packages/domi-ui/CHANGELOG.md b/packages/domi-ui/CHANGELOG.md index 8a352f2..870fb39 100644 --- a/packages/domi-ui/CHANGELOG.md +++ b/packages/domi-ui/CHANGELOG.md @@ -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 + ``/``, 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 ` @@ -233,12 +303,47 @@ data-empty={empty ? '' : undefined} data-disabled={disabled ? '' : undefined} > - - {label}{#if optional}{" (optional)"}{/if} - + {#if editable} + + + + {label}{#if optional}{" (optional)"}{/if} + + {:else} + + {label}{#if optional}{" (optional)"}{/if} + + {/if} - {#if multiline} + {#if editable} + + {#if name}{/if} + {:else if multiline} /, 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)); diff --git a/packages/domi-ui/src/index.ts b/packages/domi-ui/src/index.ts index 309ff20..83285dd 100644 --- a/packages/domi-ui/src/index.ts +++ b/packages/domi-ui/src/index.ts @@ -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'; diff --git a/packages/domi-ui/src/lib/editable.ts b/packages/domi-ui/src/lib/editable.ts new file mode 100644 index 0000000..04fdbfc --- /dev/null +++ b/packages/domi-ui/src/lib/editable.ts @@ -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 /. + * Why: on Android the WebView asks Google's Autofill service (a network request) as soon as a text or + * 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 = { + email: 'email', + url: 'url', + tel: 'tel', + number: 'decimal', + search: 'search', + }; + return map[type] ?? 'text'; +} diff --git a/packages/domi-ui/src/tokens/generated.ts b/packages/domi-ui/src/tokens/generated.ts index f87a74b..718db0e 100644 --- a/packages/domi-ui/src/tokens/generated.ts +++ b/packages/domi-ui/src/tokens/generated.ts @@ -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": {