@usableapp/cardds 0.7.148 → 0.7.150

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
- import type { ComponentProps, ReactNode } from 'react';
1
+ import { type ComponentProps, type ReactNode } from 'react';
2
+ import { type MentionPerson } from './mention.js';
2
3
  export interface ComposerProps extends Omit<ComponentProps<'textarea'>, 'className' | 'style' | 'children'> {
3
4
  /** the caption between the two buttons ("Your request is born") */
4
5
  hint?: ReactNode;
@@ -6,6 +7,10 @@ export interface ComposerProps extends Omit<ComponentProps<'textarea'>, 'classNa
6
7
  lead?: ReactNode;
7
8
  /** the right button of the bar (an `IconBtn invert` — send) */
8
9
  send?: ReactNode;
10
+ /** the people the member can name with `@` in the first area: typing `@` lists them under it, a pick writes `@name ` and marks it as one piece. Without it, `@` is a letter */
11
+ people?: MentionPerson[];
12
+ /** a person was picked from the `@` list — the words already hold their name (an `onChange` came first); who to tell is the app's */
13
+ onMention?: (person: MentionPerson) => void;
9
14
  /** more writing areas under the first, each a `ComposerArea` (the reason under the request), above the bar */
10
15
  children?: ReactNode;
11
16
  /** classes for the composer's wrapper, not the textarea */
@@ -13,8 +18,8 @@ export interface ComposerProps extends Omit<ComponentProps<'textarea'>, 'classNa
13
18
  /** inline style for the wrapper, not the textarea */
14
19
  style?: React.CSSProperties;
15
20
  }
16
- /** Composer — a big write-in area (display type) with a bottom bar: icon · hint · send. The write-in step's sheet content. On a sheet, never in a Card: the sheet is the paper the member fills in (Lh 2026-10-18). A second thing to write in the same Composer is a `ComposerArea` child: the same words, behind a dashed rule. Two framed write-ins (the ask sheet's request and its reason) are two `Field rows`, not a Composer with a `ComposerArea` (Lh 2026-10-19): the Composer is bare, the one big write-in. The bar is drawn only when it holds a lead, a hint or a send. */
17
- export declare function Composer({ hint, lead, send, children, className, style, ...textarea }: ComposerProps): import("react").JSX.Element;
21
+ /** Composer — a big write-in area (display type) with a bottom bar: icon · hint · send. The write-in step's sheet content. On a sheet, never in a Card: the sheet is the paper the member fills in (Lh 2026-10-18). A second thing to write in the same Composer is a `ComposerArea` child: the same words, behind a dashed rule. Two framed write-ins (the ask sheet's request and its reason) are two `Field rows`, not a Composer with a `ComposerArea` (Lh 2026-10-19): the Composer is bare, the one big write-in. The bar is drawn only when it holds a lead, a hint or a send. `people` turns on naming with `@` (a post that names a neighbour): the matching names are listed under the words, a pick writes `@name ` and reports it to `onMention`; a written name is marked and a backspace takes it whole. */
22
+ export declare function Composer({ hint, lead, send, people, onMention, children, className, style, ref, onChange, onKeyDown, onSelect, onScroll, onBlur, ...textarea }: ComposerProps): import("react").JSX.Element;
18
23
  export interface ComposerAreaProps extends Omit<ComponentProps<'textarea'>, 'className' | 'children'> {
19
24
  }
20
25
  /** ComposerArea — a further writing area inside a Composer (an optional reason or need under the request): the Composer's own type and look, shorter, with a dashed rule above it that the area draws itself. Controlled like any textarea (value + onChange); give it its own aria-label. */
@@ -1,10 +1,22 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef, useState } from 'react';
2
3
  import { cx } from '../cx.js';
4
+ import { setRefs } from '../state.js';
3
5
  import { useStepCursor } from '../sheets/stepCursor.js';
4
- /** Composer — a big write-in area (display type) with a bottom bar: icon · hint · send. The write-in step's sheet content. On a sheet, never in a Card: the sheet is the paper the member fills in (Lh 2026-10-18). A second thing to write in the same Composer is a `ComposerArea` child: the same words, behind a dashed rule. Two framed write-ins (the ask sheet's request and its reason) are two `Field rows`, not a Composer with a `ComposerArea` (Lh 2026-10-19): the Composer is bare, the one big write-in. The bar is drawn only when it holds a lead, a hint or a send. */
5
- export function Composer({ hint, lead, send, children, className, style, ...textarea }) {
6
+ import { useMention } from './mention.js';
7
+ /** Composer — a big write-in area (display type) with a bottom bar: icon · hint · send. The write-in step's sheet content. On a sheet, never in a Card: the sheet is the paper the member fills in (Lh 2026-10-18). A second thing to write in the same Composer is a `ComposerArea` child: the same words, behind a dashed rule. Two framed write-ins (the ask sheet's request and its reason) are two `Field rows`, not a Composer with a `ComposerArea` (Lh 2026-10-19): the Composer is bare, the one big write-in. The bar is drawn only when it holds a lead, a hint or a send. `people` turns on naming with `@` (a post that names a neighbour): the matching names are listed under the words, a pick writes `@name ` and reports it to `onMention`; a written name is marked and a backspace takes it whole. */
8
+ export function Composer({ hint, lead, send, people, onMention, children, className, style, ref, onChange, onKeyDown, onSelect, onScroll, onBlur, ...textarea }) {
6
9
  const cursor = useStepCursor();
7
- return (_jsxs("div", { className: cx('composer', className), style: style, children: [_jsx("textarea", { className: "composer__input", ...textarea, ...cursor }), children, (lead != null || hint != null || send != null) && (_jsxs("div", { className: "composer__bar", children: [lead, hint != null && _jsx("span", { className: "composer__hint", children: hint }), send] }))] }));
10
+ const box = useRef(null);
11
+ const under = useRef(null);
12
+ // the words the marks are drawn under: the app's value, or what was typed into an uncontrolled box
13
+ const [typed, setTyped] = useState(String(textarea.defaultValue ?? ''));
14
+ const text = textarea.value != null ? String(textarea.value) : typed;
15
+ const mention = useMention(box, text, people, onMention);
16
+ const input = (_jsx("textarea", { ref: setRefs(box, ref), className: "composer__input", ...textarea, ...cursor, onChange: (e) => { setTyped(e.currentTarget.value); onChange?.(e); }, onKeyDown: (e) => { onKeyDown?.(e); if (!e.defaultPrevented)
17
+ mention.onKeyDown(e); }, onSelect: (e) => { onSelect?.(e); mention.look(); }, onBlur: (e) => { onBlur?.(e); mention.leave(); }, onScroll: (e) => { onScroll?.(e); if (under.current)
18
+ under.current.scrollTop = e.currentTarget.scrollTop; } }));
19
+ return (_jsxs("div", { className: cx('composer', className), style: style, children: [mention.under ? (_jsxs("div", { className: "mention-box", children: [_jsx("div", { ref: under, className: "composer__input mention-under", "aria-hidden": "true", children: mention.under }), input] })) : input, mention.list, children, (lead != null || hint != null || send != null) && (_jsxs("div", { className: "composer__bar", children: [lead, hint != null && _jsx("span", { className: "composer__hint", children: hint }), send] }))] }));
8
20
  }
9
21
  /** ComposerArea — a further writing area inside a Composer (an optional reason or need under the request): the Composer's own type and look, shorter, with a dashed rule above it that the area draws itself. Controlled like any textarea (value + onChange); give it its own aria-label. */
10
22
  export function ComposerArea(props) {
@@ -1,4 +1,5 @@
1
- import type { ComponentProps, ReactNode } from 'react';
1
+ import { type ComponentProps, type ReactNode } from 'react';
2
+ import { type MentionPerson } from './mention.js';
2
3
  import type { IconName } from '../type/Icon.js';
3
4
  export interface MessageBarProps extends Omit<ComponentProps<'textarea'>, 'value' | 'defaultValue' | 'onChange' | 'className' | 'style' | 'children'> {
4
5
  /** CONTROLLED: the words in the box — with `onValueChange`; or `defaultValue` */
@@ -15,6 +16,10 @@ export interface MessageBarProps extends Omit<ComponentProps<'textarea'>, 'value
15
16
  sendIcon?: IconName;
16
17
  /** what stands before the box: an extra action (an `IconBtn` — attach, a photo) */
17
18
  lead?: ReactNode;
19
+ /** the people the member can name with `@`: typing `@` lists them above the bar, a pick writes `@name ` and marks it as one piece. Without it, `@` is a letter */
20
+ people?: MentionPerson[];
21
+ /** a person was picked from the `@` list — the words already hold their name; who to tell is the app's */
22
+ onMention?: (person: MentionPerson) => void;
18
23
  /** classes for the bar, not the textarea */
19
24
  className?: string;
20
25
  /** inline style for the bar, not the textarea */
@@ -26,6 +31,8 @@ export interface MessageBarProps extends Omit<ComponentProps<'textarea'>, 'value
26
31
  * (an `IconBtn invert`) is off while the box holds only blanks; pressing it hands the words to `onSend` and asks for an empty box, and
27
32
  * the cursor stays in the box, so the keyboard stays up. The Screen's `bottom` (`<Screen fill bottom={<MessageBar…>}>`): a layer over
28
33
  * the content's foot that rides above the keyboard (`--kb`), the conversation's last words scroll clear of it. Controlled like an
29
- * input: `value` + `onValueChange`, or `defaultValue`.
34
+ * input: `value` + `onValueChange`, or `defaultValue`. `people` turns on naming with `@` (a comment that names a neighbour): the
35
+ * matching names are listed above the box, a pick writes `@name ` and reports it to `onMention`; a written name is marked and a
36
+ * backspace takes it whole.
30
37
  */
31
- export declare function MessageBar({ value, defaultValue, onValueChange, onSend, sendLabel, sendIcon, lead, className, style, rows, ...textarea }: MessageBarProps): import("react").JSX.Element;
38
+ export declare function MessageBar({ value, defaultValue, onValueChange, onSend, sendLabel, sendIcon, lead, people, onMention, className, style, rows, ref, onKeyDown, onSelect, onScroll, onBlur, ...textarea }: MessageBarProps): import("react").JSX.Element;
@@ -1,6 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef } from 'react';
2
3
  import { cx } from '../cx.js';
3
- import { useControlled } from '../state.js';
4
+ import { setRefs, useControlled } from '../state.js';
5
+ import { useMention } from './mention.js';
4
6
  import { IconBtn } from '../actions/IconBtn.js';
5
7
  /**
6
8
  * MessageBar — the box a chat's message is typed in, at the foot of a conversation (a `Thread` of `Bubble`s): lead · the box · send.
@@ -8,10 +10,15 @@ import { IconBtn } from '../actions/IconBtn.js';
8
10
  * (an `IconBtn invert`) is off while the box holds only blanks; pressing it hands the words to `onSend` and asks for an empty box, and
9
11
  * the cursor stays in the box, so the keyboard stays up. The Screen's `bottom` (`<Screen fill bottom={<MessageBar…>}>`): a layer over
10
12
  * the content's foot that rides above the keyboard (`--kb`), the conversation's last words scroll clear of it. Controlled like an
11
- * input: `value` + `onValueChange`, or `defaultValue`.
13
+ * input: `value` + `onValueChange`, or `defaultValue`. `people` turns on naming with `@` (a comment that names a neighbour): the
14
+ * matching names are listed above the box, a pick writes `@name ` and reports it to `onMention`; a written name is marked and a
15
+ * backspace takes it whole.
12
16
  */
13
- export function MessageBar({ value, defaultValue = '', onValueChange, onSend, sendLabel, sendIcon = 'arrow-up', lead, className, style, rows = 1, ...textarea }) {
17
+ export function MessageBar({ value, defaultValue = '', onValueChange, onSend, sendLabel, sendIcon = 'arrow-up', lead, people, onMention, className, style, rows = 1, ref, onKeyDown, onSelect, onScroll, onBlur, ...textarea }) {
14
18
  const [shown, request] = useControlled(value, defaultValue, onValueChange);
19
+ const box = useRef(null);
20
+ const under = useRef(null);
21
+ const mention = useMention(box, shown, people, onMention);
15
22
  const empty = !shown.trim();
16
23
  const send = () => {
17
24
  if (empty)
@@ -19,5 +26,7 @@ export function MessageBar({ value, defaultValue = '', onValueChange, onSend, se
19
26
  onSend?.(shown);
20
27
  request('');
21
28
  };
22
- return (_jsxs("div", { className: cx('message-bar', className), style: style, children: [lead, _jsx("div", { className: "message-bar__box", "data-value": shown, children: _jsx("textarea", { className: "message-bar__input", rows: rows, ...textarea, value: shown, onChange: (e) => request(e.currentTarget.value) }) }), _jsx(IconBtn, { invert: true, icon: sendIcon, label: sendLabel, disabled: empty, onPointerDown: (e) => e.preventDefault(), onClick: send })] }));
29
+ return (_jsxs("div", { className: cx('message-bar', className), style: style, children: [mention.list, lead, _jsxs("div", { className: "message-bar__box", "data-value": shown, children: [mention.under && _jsx("div", { ref: under, className: "message-bar__input mention-under", "aria-hidden": "true", children: mention.under }), _jsx("textarea", { ref: setRefs(box, ref), className: "message-bar__input", rows: rows, ...textarea, value: shown, onChange: (e) => request(e.currentTarget.value), onKeyDown: (e) => { onKeyDown?.(e); if (!e.defaultPrevented)
30
+ mention.onKeyDown(e); }, onSelect: (e) => { onSelect?.(e); mention.look(); }, onBlur: (e) => { onBlur?.(e); mention.leave(); }, onScroll: (e) => { onScroll?.(e); if (under.current)
31
+ under.current.scrollTop = e.currentTarget.scrollTop; } })] }), _jsx(IconBtn, { invert: true, icon: sendIcon, label: sendLabel, disabled: empty, onPointerDown: (e) => e.preventDefault(), onClick: send })] }));
23
32
  }
@@ -0,0 +1,22 @@
1
+ import { type KeyboardEvent, type ReactNode, type RefObject } from 'react';
2
+ /** a person the member can name with `@` in a MessageBar or Composer: the app's own id, the name written in the words, a photo */
3
+ export interface MentionPerson {
4
+ /** the app's own id for the person — `onMention` hands it back */
5
+ id: string;
6
+ /** the name as it goes into the words, after the `@` */
7
+ name: string;
8
+ /** a photo for the suggestion row; without it, the name's first letter */
9
+ src?: string;
10
+ }
11
+ /**
12
+ * The `@` behaviour a MessageBar and a Composer share (`people` + `onMention`): typing `@` and letters right before the caret lists the
13
+ * people whose name holds them; picking one writes `@name ` in their place and tells the app. A written name is one piece: a
14
+ * backspace right after it takes the whole name, and the words under the textarea mark it (`under`, drawn behind the transparent box).
15
+ */
16
+ export declare function useMention(ref: RefObject<HTMLTextAreaElement | null>, text: string, people: MentionPerson[] | undefined, onMention?: (person: MentionPerson) => void): {
17
+ list: false | import("react").JSX.Element;
18
+ under: Iterable<ReactNode> | null;
19
+ onKeyDown: (e: KeyboardEvent<HTMLTextAreaElement>) => void;
20
+ look: () => void;
21
+ leave: () => void;
22
+ };
@@ -0,0 +1,82 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Avatar } from '../people/Avatar.js';
4
+ const AT = /(?:^|\s)@([^\s@]*)$/u;
5
+ /** a value set from outside the keyboard still reaches React's onChange: the native setter, then an input event */
6
+ function setText(el, text, caret) {
7
+ Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value').set.call(el, text);
8
+ el.dispatchEvent(new Event('input', { bubbles: true }));
9
+ el.setSelectionRange(caret, caret);
10
+ }
11
+ /** where each named person stands in the words: longest names first, so "@Noi Dee" wins over "@Noi" */
12
+ function spans(text, people) {
13
+ const names = people.map((p) => `@${p.name}`).sort((a, b) => b.length - a.length);
14
+ const out = [];
15
+ for (let i = 0; i < text.length; i++) {
16
+ if (text[i] !== '@' || (i > 0 && !/\s/u.test(text[i - 1])))
17
+ continue;
18
+ const hit = names.find((n) => text.startsWith(n, i));
19
+ if (hit) {
20
+ out.push([i, i + hit.length]);
21
+ i += hit.length - 1;
22
+ }
23
+ }
24
+ return out;
25
+ }
26
+ /**
27
+ * The `@` behaviour a MessageBar and a Composer share (`people` + `onMention`): typing `@` and letters right before the caret lists the
28
+ * people whose name holds them; picking one writes `@name ` in their place and tells the app. A written name is one piece: a
29
+ * backspace right after it takes the whole name, and the words under the textarea mark it (`under`, drawn behind the transparent box).
30
+ */
31
+ export function useMention(ref, text, people, onMention) {
32
+ const [query, setQuery] = useState(null);
33
+ const on = !!people?.length;
34
+ const look = () => {
35
+ const el = ref.current;
36
+ if (!on || !el)
37
+ return;
38
+ const m = el.selectionStart === el.selectionEnd ? AT.exec(el.value.slice(0, el.selectionStart)) : null;
39
+ setQuery(m ? m[1] : null);
40
+ };
41
+ const pick = (person) => {
42
+ const el = ref.current;
43
+ if (!el || query == null)
44
+ return;
45
+ const end = el.selectionStart;
46
+ const start = end - query.length - 1;
47
+ const add = `@${person.name} `;
48
+ setText(el, el.value.slice(0, start) + add + el.value.slice(end), start + add.length);
49
+ setQuery(null);
50
+ onMention?.(person);
51
+ };
52
+ const onKeyDown = (e) => {
53
+ const el = e.currentTarget;
54
+ if (!on || e.key !== 'Backspace' || el.selectionStart !== el.selectionEnd)
55
+ return;
56
+ const caret = el.selectionStart;
57
+ const hit = spans(el.value, people).find(([, b]) => b === caret);
58
+ if (!hit)
59
+ return;
60
+ e.preventDefault();
61
+ setText(el, el.value.slice(0, hit[0]) + el.value.slice(caret), hit[0]);
62
+ };
63
+ const q = query?.toLocaleLowerCase();
64
+ const matches = on && q != null ? people.filter((p) => p.name.toLocaleLowerCase().includes(q)) : [];
65
+ const list = matches.length > 0 && (_jsx("div", { className: "menu mention-list", role: "listbox", children: matches.map((p) => (
66
+ // a press never takes the cursor out of the box: the keyboard stays up
67
+ _jsxs("button", { type: "button", role: "option", "aria-selected": "false", className: "menu__item", onPointerDown: (e) => e.preventDefault(), onClick: () => pick(p), children: [_jsx(Avatar, { size: "sm", src: p.src, children: p.name.slice(0, 1) }), p.name] }, p.id))) }));
68
+ let under = null;
69
+ if (on) {
70
+ const parts = [];
71
+ let at = 0;
72
+ for (const [a, b] of spans(text, people)) {
73
+ parts.push(text.slice(at, a), _jsx("mark", { className: "mention-under__name", children: text.slice(a, b) }, a));
74
+ at = b;
75
+ }
76
+ parts.push(`${text.slice(at)} `);
77
+ under = parts;
78
+ }
79
+ /** the cursor left the box: the list goes (a pick never takes the cursor out, its press is held) */
80
+ const leave = () => setQuery(null);
81
+ return { list, under, onKeyDown, look, leave };
82
+ }
package/dist/index.d.ts CHANGED
@@ -50,6 +50,7 @@ export * from './forms/AddRow.js';
50
50
  export * from './forms/Pin.js';
51
51
  export * from './forms/Composer.js';
52
52
  export * from './forms/MessageBar.js';
53
+ export type { MentionPerson } from './forms/mention.js';
53
54
  export * from './choice/Check.js';
54
55
  export * from './choice/DayStrip.js';
55
56
  export * from './choice/Calendar.js';
package/docs/reference.md CHANGED
@@ -349,6 +349,11 @@ of `Screen`:
349
349
  `defaultValue`); `onSend(words)` hands them to the app, then the bar asks for an empty box; the cursor stays in the box, so
350
350
  the keyboard stays up. It is a layer like the `ActionBar`: measured into `--bottom-h`, lifted by `--kb`. It is not the
351
351
  `Composer` (the one big write-in on a sheet) and not a sheet's form: a message is sent from where it is read.
352
+ - **Naming a person with `@` is `people` + `onMention`** on a `MessageBar` or a `Composer` (2026-10-26) — `people` is the app's
353
+ list (`MentionPerson`: `id` · `name` · `src`). Typing `@` and letters right before the caret lists the people whose name holds
354
+ them (above a MessageBar's box, under a Composer's words; an inline `.menu`, 48px rows); a pick writes `@name ` in their place
355
+ and hands the person to `onMention`. A written name is one piece: marked under the words (`--mention-bg`) and taken whole by
356
+ one backspace. The words stay plain text with `@name` in them; who to notify is the app's.
352
357
  - **A row pinned under the top is `topRow`** (Lh 2026-10-26) — `<Screen fill top={<TopBar…/>} topRow={<Row>…</Row>}>`: a row
353
358
  of the column, so it never scrolls away and the content starts under it at its real height; it touches the bar, edge to
354
359
  edge, on the screen's ground (`--top-row-bg`). On a scrolling screen it sticks to the top once the bar has gone.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usableapp/cardds",
3
- "version": "0.7.148",
3
+ "version": "0.7.150",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "description": "card-first mobile design system, React-first: the components in src/ are thin wrappers over the CSS contract (css/*.css stays the only truth); gallery/ shows every story live (npm run dev).",