@mistriwork/kit 1.0.0-rc.69 → 1.0.0-rc.70

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.
@@ -66,6 +66,9 @@ export function Editable({ table, row, column, recordKey, onSaved, app = false,
66
66
  : value === null || value === undefined
67
67
  ? null
68
68
  : String(value);
69
+ /* Chosen from the value the edit started from, never the live draft: a newline typed or pasted must not remount the
70
+ element and take the focus and caret with it. */
71
+ const multiline = original?.includes('\n') ?? false;
69
72
  const pending = sameRow(table.id, recordKey) ? stagedValue(column.name) : undefined;
70
73
  const shown = pending !== undefined ? pending : original;
71
74
  const dirty = pending !== undefined;
@@ -110,6 +113,9 @@ export function Editable({ table, row, column, recordKey, onSaved, app = false,
110
113
  invalidInput: Boolean(control && (control.validity.badInput || control.validity.customError)),
111
114
  };
112
115
  };
116
+ const readStateRef = useRef(readState);
117
+ readStateRef.current = readState;
118
+ const keyText = JSON.stringify(recordKey);
113
119
  const interaction = useEditInteraction({
114
120
  enabled: app &&
115
121
  shell().saveMode() === 'blur' &&
@@ -135,11 +141,10 @@ export function Editable({ table, row, column, recordKey, onSaved, app = false,
135
141
  : undefined);
136
142
  // Composite controls keep their own ARIA attributes; this field owns one
137
143
  // description token, on the actual focusable control, for both renderers.
144
+ const isField = (node) => node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement || node instanceof HTMLSelectElement;
138
145
  useLayoutEffect(() => {
139
146
  const node = input.current;
140
- const control = node instanceof HTMLInputElement || node instanceof HTMLSelectElement
141
- ? node
142
- : node?.querySelector('input, [data-slot="select-trigger"]');
147
+ const control = isField(node) ? node : node?.querySelector('input, textarea, [data-slot="select-trigger"]');
143
148
  if (!control || !error)
144
149
  return;
145
150
  const described = control.getAttribute('aria-describedby')?.split(/\s+/).filter(Boolean) ?? [];
@@ -160,25 +165,24 @@ export function Editable({ table, row, column, recordKey, onSaved, app = false,
160
165
  else
161
166
  control.removeAttribute('aria-invalid');
162
167
  };
163
- });
168
+ }, [error, errorId, opened, pickerGeneration]);
164
169
  /* A refused Save leaves the focus for the first field it marked; this
165
170
  editor takes it once it is drawn — a marked field opens to be answered. */
166
171
  useLayoutEffect(() => {
167
172
  const node = input.current;
168
173
  if (!error || !node || !takeFieldFocus(table.id, recordKey, column.name))
169
174
  return;
170
- const control = node instanceof HTMLInputElement || node instanceof HTMLSelectElement
171
- ? node
172
- : node.querySelector('input, [data-slot="select-trigger"]');
175
+ const control = isField(node) ? node : node.querySelector('input, textarea, [data-slot="select-trigger"]');
173
176
  control?.focus();
174
- });
177
+ // eslint-disable-next-line react-hooks/exhaustive-deps
178
+ }, [error, table.id, keyText, column.name, opened]);
175
179
  useLayoutEffect(() => {
176
180
  const control = input.current instanceof HTMLDivElement ? input.current.querySelector('input') : null;
177
181
  // Read-only keeps a newly focused field in place while another field saves.
178
182
  // The picker API stays unchanged; its search and buttons share this boundary.
179
183
  if (control)
180
184
  control.readOnly = pendingWrite;
181
- });
185
+ }, [pendingWrite, opened, pickerGeneration]);
182
186
  /* Kept by the store so a successful write can confirm in place — the saved
183
187
  value, in green, on the field you just edited — rather than re-render.
184
188
  An unopened field registers its launcher: the store needs to know it is
@@ -192,8 +196,9 @@ export function Editable({ table, row, column, recordKey, onSaved, app = false,
192
196
  const label = column.references ? input.current?.querySelector('input')?.value : undefined;
193
197
  setCommitted({ source: row, value: next === null || next === undefined ? null : String(next), label });
194
198
  setSaved(true);
195
- }, readState);
196
- });
199
+ }, () => readStateRef.current());
200
+ // eslint-disable-next-line react-hooks/exhaustive-deps
201
+ }, [table, keyText, column.name, opened, row, pickerGeneration, multiline]);
197
202
  useEffect(() => {
198
203
  if (!saved)
199
204
  return;
@@ -208,10 +213,10 @@ export function Editable({ table, row, column, recordKey, onSaved, app = false,
208
213
  }
209
214
  wasOpened.current = true;
210
215
  const node = input.current;
211
- if (node instanceof HTMLInputElement || node instanceof HTMLSelectElement)
216
+ if (isField(node))
212
217
  node.focus();
213
218
  /* A rich text field is its text, not its toolbar's first button. */ else
214
- (node?.querySelector('[contenteditable="true"]') ?? node?.querySelector('input, button'))?.focus();
219
+ (node?.querySelector('[contenteditable="true"]') ?? node?.querySelector('input, textarea, button'))?.focus();
215
220
  }, [opened]);
216
221
  useLayoutEffect(() => {
217
222
  if (pickerFocusRequested.current && (!display || opened))
@@ -357,10 +362,21 @@ export function Editable({ table, row, column, recordKey, onSaved, app = false,
357
362
  if (app && columnKind(column.type) === 'date' && !/time/i.test(column.type)) {
358
363
  return wrap(_jsx("div", { ref: input, inert: locked, "aria-disabled": applying || undefined, className: `cell-edit-control${statusClass}`, children: _jsx(DateField, { id: dateId, value: shown === null ? '' : String(shown), onChange: onEdit, "aria-label": label, disabled: locked, locale: formatLocale(), timezone: formatTimezone(), now: appNow(), popupRef: interaction.popupRef, onOpenChange: interaction.onOpenChange }) }));
359
364
  }
360
- return wrap(_jsx("input", { ref: input, className: `cell-edit${statusClass}`, disabled: locked, readOnly: pendingWrite, "aria-disabled": applying || undefined, "aria-label": label, type: "text", value: shown === null ? '' : String(shown), "data-null": String(shown === null),
365
+ const textValue = shown === null ? '' : String(shown);
366
+ const textProps = {
367
+ className: `cell-edit${statusClass}`,
368
+ disabled: locked,
369
+ readOnly: pendingWrite,
370
+ 'aria-disabled': applying || undefined,
371
+ 'aria-label': label,
372
+ value: textValue,
373
+ 'data-null': String(shown === null),
361
374
  /* Where the database pins the vocabulary, say it — but still a text
362
375
  box: a select would silently rewrite a value the check would refuse. */
363
- title: column.allowed?.length ? say('one', { allowed: column.allowed.join(', ') }) : undefined, onChange: (e) => onEdit(e.target.value) }));
376
+ title: column.allowed?.length ? say('one', { allowed: column.allowed.join(', ') }) : undefined,
377
+ onChange: (e) => onEdit(e.target.value),
378
+ };
379
+ return wrap(multiline ? (_jsx("textarea", { ref: input, rows: Math.min(8, Math.max(2, textValue.split('\n').length)), ...textProps })) : (_jsx("input", { ref: input, type: "text", ...textProps })));
364
380
  }
365
381
  /** Placement changes presentation only; one bar still owns the existing draft. */
366
382
  export function PendingBar({ table, recordKey, onDone, placement, isCurrent }) {
@@ -458,7 +458,7 @@ function PlatformCell({ meta, plan, value, label, display, pin, edge, photo, })
458
458
  if (shellBody().classList.contains('app-mode') && meta?.allowed?.includes(raw))
459
459
  return (_jsx("td", { className: `${classes.join(' ')}${pinClass}`, title: raw, ...pinAttrs, children: vocabularyWord(raw) }));
460
460
  const cell = clampCell(raw);
461
- return (_jsx("td", { className: `${classes.join(' ')}${pinClass}`, title: cell.title, ...pinAttrs, children: cell.text }));
461
+ return (_jsx("td", { className: `${classes.join(' ')}${pinClass}`, title: cell.title, "data-copy": cell.title ? raw : undefined, ...pinAttrs, children: cell.text }));
462
462
  }
463
463
  /* A vocabulary column that says where a row stands, kept when a narrow grid leaves columns out. */
464
464
  const STATUS_NAME = /(^|_)(status|state|stage|phase)$/i;
@@ -1043,7 +1043,7 @@ export function Grid({ table, data, hide, labels, totals, totalsLabel = say('tot
1043
1043
  const top = tableRef.current.offsetTop;
1044
1044
  if (top !== margin)
1045
1045
  setMargin(top);
1046
- });
1046
+ }, [virtual, scroller, rows.length, rowHeight, margin, sizing]);
1047
1047
  useEffect(() => {
1048
1048
  if (virtual)
1049
1049
  virtualizer.measure();
@@ -1052,7 +1052,7 @@ export function Grid({ table, data, hide, labels, totals, totalsLabel = say('tot
1052
1052
  const padTop = virtual && items.length ? items[0].start - margin : 0;
1053
1053
  const padBottom = virtual && items.length ? Math.max(0, rows.length - items[items.length - 1].index - 1) * rowHeight : 0;
1054
1054
  /* ---------- pins and the keyboard ---------- */
1055
- const lefts = usePins(wrap, ordered, pinned, shift, `${shown.join(',')}:${sizing}:${fit.columns.join(',')}`);
1055
+ const lefts = usePins(wrap, ordered, pinned, shift, `${rows.length > 0}:${sizing}:${fit.columns.join(',')}`);
1056
1056
  useStickyHead(wrap, `${ordered.join(',')}:${sizing}:${rows.length > 0}`);
1057
1057
  const lastPinned = pinned.length ? ordered.filter((n) => pinned.includes(n)).pop() : undefined;
1058
1058
  /* Read on every paint, as the cells always read them — an App's display
@@ -1071,9 +1071,13 @@ export function Grid({ table, data, hide, labels, totals, totalsLabel = say('tot
1071
1071
  !columnDisplay(table?.id, name)?.tone);
1072
1072
  return words.reduce((best, name) => (width(name) > width(best) ? name : best), named);
1073
1073
  })();
1074
+ const columnValuesKey = `${ordered.join(',')}\u0000${folded.join(',')}`;
1075
+ const columnValues = useMemo(() => new Map([...ordered, ...folded].map((name) => [name, rows.map((row) => row[name])])),
1076
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1077
+ [rows, columnValuesKey]);
1074
1078
  const cellColumns = useKeptColumns(ordered.map((name) => {
1075
1079
  /* A column of relative dates is said one way down its length (datesAmong). */
1076
- const display = datesAmong(displayOf(name), rows.map((row) => row[name]));
1080
+ const display = datesAmong(displayOf(name), columnValues.get(name) ?? []);
1077
1081
  return {
1078
1082
  name,
1079
1083
  meta: byName.get(name),
@@ -1100,7 +1104,7 @@ export function Grid({ table, data, hide, labels, totals, totalsLabel = say('tot
1100
1104
  head: String(labels?.[other] ?? columnLabel(table?.id, other) ?? other),
1101
1105
  meta: byName.get(other),
1102
1106
  plan: plans.get(other),
1103
- display: datesAmong(columnDisplay(table?.id, other), rows.map((row) => row[other])),
1107
+ display: datesAmong(columnDisplay(table?.id, other), columnValues.get(other) ?? []),
1104
1108
  label: referenceLabels?.[other],
1105
1109
  })),
1106
1110
  }
@@ -19,6 +19,8 @@ export declare function ValueControl(props: {
19
19
  unresolvedReference: boolean;
20
20
  open: boolean;
21
21
  }) => void;
22
+ /** The editor's own popup element (picker list, dropdown listbox, calendar), so blur checks only this control's popup. */
23
+ popupRef?: (node: HTMLElement | null) => void;
22
24
  describedBy?: string;
23
25
  invalid?: boolean;
24
26
  }): import("react").JSX.Element;
@@ -63,12 +63,12 @@ export function ValueControl(props) {
63
63
  return _jsx(PlatformControl, { ...props });
64
64
  return (_jsx(InputSlot, { component: custom, fallback: _jsx(PlatformControl, { ...props }), value: props.value, onChange: (next) => props.onChange(next === null || next === '' ? (props.column.nullable ? null : '') : String(next)), id: props.id ?? inputId, describedBy: props.describedBy, invalid: props.invalid === true, disabled: false, required: props.column.nullable === false, label: props.label, field: { name: props.column.name, resource: props.table.id }, context: "edit" }));
65
65
  }
66
- function PlatformControl({ table, column, value, onChange, label, id, row, onPickerState, describedBy, invalid, valueLabel, }) {
66
+ function PlatformControl({ table, column, value, onChange, label, id, row, onPickerState, popupRef, describedBy, invalid, valueLabel, }) {
67
67
  const dateId = useId();
68
68
  const change = (next) => onChange(next === '' && column.nullable ? null : next);
69
69
  const target = column.references && singleReference(table, column) ? findTable(column.references.table) : undefined;
70
70
  if (target) {
71
- return (_jsx(RecordPicker, { table: target, valueColumn: column.references.column, value: value ?? '', onChange: change, ariaLabel: label, app: true, ...(valueLabel && value ? { known: { value, label: valueLabel } } : {}), editing: { onStateChange: (next) => onPickerState?.(next) } }));
71
+ return (_jsx(RecordPicker, { table: target, valueColumn: column.references.column, value: value ?? '', onChange: change, ariaLabel: label, app: true, ...(valueLabel && value ? { known: { value, label: valueLabel } } : {}), editing: { onStateChange: (next) => onPickerState?.(next), popupRef } }));
72
72
  }
73
73
  const choices = booleanChoices(column, row);
74
74
  if (column.allowed?.length || choices) {
@@ -81,10 +81,10 @@ function PlatformControl({ table, column, value, onChange, label, id, row, onPic
81
81
  ];
82
82
  if (value !== null && !items.some((item) => item.value === value))
83
83
  items.unshift({ value, label: value });
84
- return (_jsx(Dropdown, { ariaLabel: label, id: id, value: value ?? '', ariaInvalid: invalid, ariaDescribedBy: describedBy, items: [...(column.nullable ? [{ value: '', label: say('common.noValue') }] : []), ...items], onChange: change }));
84
+ return (_jsx(Dropdown, { ariaLabel: label, id: id, value: value ?? '', ariaInvalid: invalid, ariaDescribedBy: describedBy, popupRef: popupRef, items: [...(column.nullable ? [{ value: '', label: say('common.noValue') }] : []), ...items], onChange: change }));
85
85
  }
86
86
  if (columnKind(column.type) === 'date' && !/time/i.test(column.type)) {
87
- return (_jsx(DateField, { id: id ?? dateId, value: value ?? '', onChange: change, "aria-label": label, "aria-invalid": invalid || undefined, "aria-describedby": describedBy, locale: formatLocale(), timezone: formatTimezone(), now: appNow() }));
87
+ return (_jsx(DateField, { id: id ?? dateId, value: value ?? '', onChange: change, "aria-label": label, "aria-invalid": invalid || undefined, "aria-describedby": describedBy, locale: formatLocale(), timezone: formatTimezone(), now: appNow(), popupRef: popupRef }));
88
88
  }
89
89
  /* Money kept as minor units is typed as the figure it is ("19.99") and held as what is stored (1999). */
90
90
  const rule = columnDisplay(table.id, column.name);
@@ -116,6 +116,7 @@ export function GridCellEdit({ table, row, column, recordKey, draw, byName = fal
116
116
  const [shown, setShown] = useState(null);
117
117
  const surface = useRef(null);
118
118
  const launcher = useRef(null);
119
+ const popupNode = useRef(null);
119
120
  const unresolved = useRef(false);
120
121
  const pickerOpen = useRef(false);
121
122
  /* Where focus goes once the editor closes: back to the cell, unless Tab sent it on. */
@@ -255,7 +256,8 @@ export function GridCellEdit({ table, row, column, recordKey, draw, byName = fal
255
256
  return;
256
257
  if (active &&
257
258
  (node.contains(active) ||
258
- active.closest('[role="listbox"], [role="dialog"], [data-slot="select-content"], [data-slot="popover-content"][data-kind="calendar"]')))
259
+ popupNode.current?.contains(active) ||
260
+ active.closest('[role="listbox"], [data-slot="select-content"], [data-slot="popover-content"][data-kind="calendar"]')))
259
261
  return;
260
262
  void commit(draft, false, pickedLabel());
261
263
  });
@@ -287,7 +289,9 @@ export function GridCellEdit({ table, row, column, recordKey, draw, byName = fal
287
289
  });
288
290
  }
289
291
  };
290
- return (_jsxs("div", { ref: surface, className: "cell-edit-surface", "data-edit-field": "", onKeyDownCapture: onKey, onBlur: onBlur, onClick: (event) => event.stopPropagation(), onMouseDown: (event) => event.stopPropagation(), children: [_jsx(ValueControl, { table: table, column: column, value: draft, onChange: change, label: label, row: row, valueLabel: shown ? (typeof shown.label === 'string' ? shown.label : undefined) : valueLabel, describedBy: problem ? errorId : undefined, invalid: Boolean(problem), onPickerState: (next) => {
292
+ return (_jsxs("div", { ref: surface, className: "cell-edit-surface", "data-edit-field": "", onKeyDownCapture: onKey, onBlur: onBlur, onClick: (event) => event.stopPropagation(), onMouseDown: (event) => event.stopPropagation(), children: [_jsx(ValueControl, { table: table, column: column, value: draft, onChange: change, label: label, row: row, valueLabel: shown ? (typeof shown.label === 'string' ? shown.label : undefined) : valueLabel, describedBy: problem ? errorId : undefined, invalid: Boolean(problem), popupRef: (node) => {
293
+ popupNode.current = node;
294
+ }, onPickerState: (next) => {
291
295
  unresolved.current = next.unresolvedReference;
292
296
  pickerOpen.current = next.open;
293
297
  } }), problem && (_jsx("span", { id: errorId, className: "edit-field-error", role: "alert", children: problem }))] }));
@@ -59,7 +59,7 @@ export function ListFilterBar(props) {
59
59
  const [folded, setFolded] = useState(0);
60
60
  /* A new width is measured afresh even where nothing was folded: the fold
61
61
  below runs after a render, and unfolding nothing renders nothing. */
62
- const [, remeasure] = useState(0);
62
+ const [measureTick, remeasure] = useState(0);
63
63
  const mark = useRef(null);
64
64
  const width = useRef(0);
65
65
  useLayoutEffect(() => {
@@ -85,7 +85,8 @@ export function ListFilterBar(props) {
85
85
  const end = (node) => (node ? node.offsetLeft + node.offsetWidth : 0);
86
86
  const limit = end(slots.at(-1)) - over;
87
87
  setFolded(folded + 1 + slots.filter((slot) => end(slot.previousSibling) > limit).length);
88
- });
88
+ // eslint-disable-next-line react-hooks/exhaustive-deps
89
+ }, [phone, folded, idle.length, refinement, tabQuery, boxes.length, measureTick]);
89
90
  useEffect(() => {
90
91
  const row = mark.current?.closest('.applist-controls');
91
92
  if (phone || !row || typeof ResizeObserver === 'undefined')
@@ -39,7 +39,8 @@ type FormBodyProps = NewRecordProps & {
39
39
  };
40
40
  /** The fields, the required check and the save, apart from any frame: once its starting words (`today`, `me`) are values. */
41
41
  export declare function NewRecordForm(props: FormBodyProps): import("react").JSX.Element;
42
- export declare function PlatformControl({ column, app, required, assigned, spoken, target, value, onChange, register, explicitNull, errorId, kind, rule, placeholder, as, where, waiting, tree, helpId, }: {
42
+ export declare function PlatformControl({ id, column, app, required, assigned, spoken, target, value, onChange, register, explicitNull, errorId, kind, rule, placeholder, as, where, waiting, tree, helpId, }: {
43
+ id?: string;
43
44
  column: ColumnMeta;
44
45
  app: boolean;
45
46
  /** Said to assistive technology as well as starred: the star is outside the control's name. */
@@ -431,9 +431,15 @@ function NewRecordFormBody({ table, form, app, label: columnLabel, target, inser
431
431
  ? serverError.message
432
432
  : '');
433
433
  const errorId = `${errorPrefix}-${index}-error`;
434
+ const isRadioControl = (app &&
435
+ (own?.as === 'cards' || own?.as === 'buttons') &&
436
+ (Boolean(column.allowed?.length) || isFlagColumn(column))) ||
437
+ (((kind === 'radios' && own?.as !== 'select') || (own?.as === 'radios' && app)) &&
438
+ Boolean(column.allowed?.length));
439
+ const fieldId = isRadioControl ? undefined : `${errorPrefix}-${index}-input`;
434
440
  const help = [own?.help, waitingOn ? say('chooseFirst', { waitingOn }) : ''].filter(Boolean).join(' ') || undefined;
435
441
  const helpId = help ? `${errorPrefix}-${index}-help` : undefined;
436
- return (_jsxs("div", { "data-slot": app ? 'field' : undefined, "data-answer": app && (kind === 'number' || kind === 'money' || kind === 'date' || kind === 'datetime') ? kind : undefined, "data-invalid": app && fieldMessage ? '' : undefined, className: `insert-field${fieldMessage ? ' missing' : ''}`, children: [app ? (_jsxs("div", { "data-slot": "field-head", children: [_jsx("label", { "data-slot": "field-label", children: label(column) }), !required(column) && (_jsxs(_Fragment, { children: [' ', _jsx("span", { "data-slot": "field-optional", children: say('optionalWord') })] }))] })) : (_jsxs("label", { children: [label(column), _jsx("span", { className: "type", children: column.type.toLowerCase() }), column.primaryKey && _jsx("span", { className: "pk", children: say('common.key') }), required(column) && (_jsx("span", { className: "req", title: say('notNullWithNoDefault'), children: say('requiredMark') }))] })), _jsx(Control, { column: column, app: app, input: app ? columnInput(table.id, column.name) : undefined, resource: table.id, required: required(column), assigned: assigned, spoken: label(column), target: target, value: field.state.value, kind: kind, rule: app ? ruleIn(column, { ...defaults, ...values }) : (display?.(column) ?? undefined), placeholder: own?.placeholder, as: own?.as, where: narrowed === undefined ? undefined : narrowed || undefined, waiting: narrowed === undefined, tree: kind === 'reference' ? own?.tree : undefined, helpId: helpId, onChange: (value) => {
442
+ return (_jsxs("div", { "data-slot": app ? 'field' : undefined, "data-answer": app && (kind === 'number' || kind === 'money' || kind === 'date' || kind === 'datetime') ? kind : undefined, "data-invalid": app && fieldMessage ? '' : undefined, className: `insert-field${fieldMessage ? ' missing' : ''}`, children: [app ? (_jsxs("div", { "data-slot": "field-head", children: [_jsx("label", { htmlFor: fieldId, "data-slot": "field-label", children: label(column) }), !required(column) && (_jsxs(_Fragment, { children: [' ', _jsx("span", { "data-slot": "field-optional", children: say('optionalWord') })] }))] })) : (_jsxs("label", { htmlFor: fieldId, children: [label(column), _jsx("span", { className: "type", children: column.type.toLowerCase() }), column.primaryKey && _jsx("span", { className: "pk", children: say('common.key') }), required(column) && (_jsx("span", { className: "req", title: say('notNullWithNoDefault'), children: say('requiredMark') }))] })), _jsx(Control, { id: fieldId, column: column, app: app, input: app ? columnInput(table.id, column.name) : undefined, resource: table.id, required: required(column), assigned: assigned, spoken: label(column), target: target, value: field.state.value, kind: kind, rule: app ? ruleIn(column, { ...defaults, ...values }) : (display?.(column) ?? undefined), placeholder: own?.placeholder, as: own?.as, where: narrowed === undefined ? undefined : narrowed || undefined, waiting: narrowed === undefined, tree: kind === 'reference' ? own?.tree : undefined, helpId: helpId, onChange: (value) => {
437
443
  edited.current.add(column.name);
438
444
  field.handleChange(value);
439
445
  /* A value taken from the record this field names follows the choice, until the person says their own. */
@@ -556,7 +562,7 @@ function Control(props) {
556
562
  if (!input)
557
563
  return _jsx(PlatformControl, { ...rest });
558
564
  /* The App's own input: it hands back text the form keeps, checks and inserts like any control's. */
559
- return (_jsx(InputSlot, { component: input, fallback: _jsx(PlatformControl, { ...rest }), value: rest.value, onChange: (next) => rest.onChange(next === null ? '' : String(next)), id: `new-${id}`, describedBy: rest.errorId, invalid: Boolean(rest.errorId), disabled: false, required: rest.required, label: rest.spoken, field: { name: rest.column.name, resource }, context: "new" }));
565
+ return (_jsx(InputSlot, { component: input, fallback: _jsx(PlatformControl, { ...rest }), value: rest.value, onChange: (next) => rest.onChange(next === null ? '' : String(next)), id: rest.id ?? `new-${id}`, describedBy: rest.errorId, invalid: Boolean(rest.errorId), disabled: false, required: rest.required, label: rest.spoken, field: { name: rest.column.name, resource }, context: "new" }));
560
566
  }
561
567
  let controlsStyled = false;
562
568
  /** Whether the cards-and-buttons rules are here; the first field that wants them fetches the sheet. */
@@ -577,7 +583,7 @@ function useControlsStyle(wanted) {
577
583
  }, [wanted]);
578
584
  return here || controlsStyled;
579
585
  }
580
- export function PlatformControl({ column, app, required, assigned, spoken, target, value, onChange, register, explicitNull, errorId, kind, rule, placeholder, as, where, waiting = false, tree, helpId, }) {
586
+ export function PlatformControl({ id, column, app, required, assigned, spoken, target, value, onChange, register, explicitNull, errorId, kind, rule, placeholder, as, where, waiting = false, tree, helpId, }) {
581
587
  const dateId = useId();
582
588
  const radioName = useId();
583
589
  const styled = useControlsStyle(app && (as === 'cards' || as === 'buttons'));
@@ -603,6 +609,8 @@ export function PlatformControl({ column, app, required, assigned, spoken, targe
603
609
  }
604
610
  validation.current = null;
605
611
  }
612
+ if (node && id && !node.id)
613
+ node.id = id;
606
614
  if (node && (errorId || helpId)) {
607
615
  validation.current = {
608
616
  node,
@@ -670,14 +678,14 @@ export function PlatformControl({ column, app, required, assigned, spoken, targe
670
678
  return (_jsx("div", { className: "command-choices insert-choices", role: "radiogroup", "aria-label": spoken, "aria-required": required || undefined, children: allowed.map((stored, index) => (_jsxs("label", { className: "command-choice", children: [_jsx("input", { type: "radio", name: radioName, value: stored, checked: value === stored, onChange: () => onChange(stored), ref: index === 0 ? setControl : undefined }), word(stored)] }, stored))) }));
671
679
  }
672
680
  if (allowed?.length) {
673
- return (_jsx(Dropdown, { items: [{ value: '', label: unchosen }, ...allowed.map((v) => ({ value: v, label: word(v) }))], value: value, valueClassName: quietWhenEmpty, ariaLabel: `${spoken}${app ? '' : say('one', { allowed: allowed.join(', ') })}`, onChange: onChange, buttonRef: setControl }));
681
+ return (_jsx(Dropdown, { id: id, items: [{ value: '', label: unchosen }, ...allowed.map((v) => ({ value: v, label: word(v) }))], value: value, valueClassName: quietWhenEmpty, ariaLabel: `${spoken}${app ? '' : say('one', { allowed: allowed.join(', ') })}`, onChange: onChange, buttonRef: setControl }));
674
682
  }
675
683
  if (kind === 'switch' && as !== 'select') {
676
684
  /* A flag that is answered either way is a switch: on is yes, off is no — never "leave it to the database". */
677
- return (_jsxs("label", { className: "insert-switch", children: [_jsx("input", { ref: setControl, type: "checkbox", role: "switch", "aria-label": spoken, checked: value === '1', onChange: (e) => onChange(e.target.checked ? '1' : '0') }), _jsx("span", { "aria-hidden": "true", children: value === '1' ? say('common.yes') : say('common.no') })] }));
685
+ return (_jsxs("label", { className: "insert-switch", children: [_jsx("input", { id: id, ref: setControl, type: "checkbox", role: "switch", "aria-label": spoken, checked: value === '1', onChange: (e) => onChange(e.target.checked ? '1' : '0') }), _jsx("span", { "aria-hidden": "true", children: value === '1' ? say('common.yes') : say('common.no') })] }));
678
686
  }
679
687
  if (isFlagColumn(column)) {
680
- return (_jsx(Dropdown, { items: [
688
+ return (_jsx(Dropdown, { id: id, items: [
681
689
  { value: '', label: unchosen },
682
690
  { value: '1', label: app ? say('common.yes') : 'yes' },
683
691
  { value: '0', label: app ? say('common.no') : 'no' },
@@ -695,7 +703,7 @@ export function PlatformControl({ column, app, required, assigned, spoken, targe
695
703
  return (_jsx(RecordPicker, { table: referenced, value: value, onChange: onChange, ariaLabel: spoken, app: app, inputRef: setControl, where: where, disabled: waiting, ...(placeholder ? { placeholder } : {}) }));
696
704
  }
697
705
  if (dateOnly(column) || kind === 'datetime') {
698
- return (_jsx(DateField, { id: dateId, inputRef: setControl, className: "insert-input", value: value, onChange: onChange, withTime: kind === 'datetime', "aria-invalid": errorId ? true : undefined, "aria-label": app ? spoken : `${column.name} (${column.type})`,
706
+ return (_jsx(DateField, { id: id ?? dateId, inputRef: setControl, className: "insert-input", value: value, onChange: onChange, withTime: kind === 'datetime', "aria-invalid": errorId ? true : undefined, "aria-label": app ? spoken : `${column.name} (${column.type})`,
699
707
  /* A day's box, with or without a time, says the locale's pattern, as its hint does and as it reads what is typed
700
708
  (MM/DD/YYYY, and HH:MM after it for a moment, in en-US; ISO is read too): the field's own (DateField.tsx). */
701
709
  placeholder: said || undefined, locale: formatLocale(), timezone: formatTimezone(), now: appNow() }));
@@ -703,12 +711,12 @@ export function PlatformControl({ column, app, required, assigned, spoken, targe
703
711
  /* Formatted text: the editor, fetched when the form first draws one. A new record has no row yet for a
704
712
  picture to be attached to, so it takes pictures once it is saved and edited. */
705
713
  if (kind === 'richText') {
706
- return (_jsx(RichTextField, { label: spoken, value: value, onChange: onChange, ...(said ? { placeholder: said } : {}), ...(rule?.mentions ? { mentions: mentionSearch(rule.mentions, state.activeConnection) } : {}) }));
714
+ return (_jsx(RichTextField, { id: id, label: spoken, value: value, onChange: onChange, ...(said ? { placeholder: said } : {}), ...(rule?.mentions ? { mentions: mentionSearch(rule.mentions, state.activeConnection) } : {}) }));
707
715
  }
708
716
  if (kind === 'textarea') {
709
- return (_jsx("textarea", { ref: setControl, className: "insert-input", rows: 4, placeholder: said, "aria-label": spoken, value: value, onChange: (e) => onChange(e.target.value) }));
717
+ return (_jsx("textarea", { id: id, ref: setControl, className: "insert-input", rows: 4, placeholder: said, "aria-label": spoken, value: value, onChange: (e) => onChange(e.target.value) }));
710
718
  }
711
- const box = (style, shown = value, change = onChange) => (_jsx("input", { ref: setControl, style: style, type: "text", className: "insert-input", placeholder: app && column.name === assigned ? '' : said, "aria-label": app ? spoken : `${column.name} (${column.type})`, autoComplete: "off", spellCheck: false, ...(kind === 'number' || kind === 'money' ? { inputMode: 'decimal' } : {}), value: shown, onChange: (e) => change(e.target.value) }));
719
+ const box = (style, shown = value, change = onChange) => (_jsx("input", { id: id, ref: setControl, style: style, type: "text", className: "insert-input", placeholder: app && column.name === assigned ? '' : said, "aria-label": app ? spoken : `${column.name} (${column.type})`, autoComplete: "off", spellCheck: false, ...(kind === 'number' || kind === 'money' ? { inputMode: 'decimal' } : {}), value: shown, onChange: (e) => change(e.target.value) }));
712
720
  if (kind !== 'money')
713
721
  return box();
714
722
  /* Money says its currency in the box, before the figure, as the figure will read once stored. */
@@ -237,26 +237,29 @@ export function Palette({ prefill = '', onClose }) {
237
237
  onClose();
238
238
  item.run();
239
239
  };
240
+ const keyLatest = useRef({ current, choose, onClose });
241
+ keyLatest.current = { current, choose, onClose };
240
242
  useEffect(() => {
241
243
  const onKey = (e) => {
244
+ const latest = keyLatest.current;
242
245
  switch (e.key) {
243
246
  case 'Escape':
244
247
  /* Stopped as well as prevented: a modal takes the key it handles. */
245
248
  e.preventDefault();
246
249
  e.stopPropagation();
247
- onClose();
250
+ latest.onClose();
248
251
  return;
249
252
  case 'ArrowDown':
250
253
  e.preventDefault();
251
- setActive(current + 1);
254
+ setActive(latest.current + 1);
252
255
  return;
253
256
  case 'ArrowUp':
254
257
  e.preventDefault();
255
- setActive(current - 1);
258
+ setActive(latest.current - 1);
256
259
  return;
257
260
  case 'Enter':
258
261
  e.preventDefault();
259
- choose(current);
262
+ latest.choose(latest.current);
260
263
  return;
261
264
  /* The results are reached with the arrows, so the box is the only
262
265
  stop: Tab used to leave it for the page under the scrim, a focus
@@ -269,7 +272,7 @@ export function Palette({ prefill = '', onClose }) {
269
272
  };
270
273
  addHostListener(document, 'keydown', onKey, true);
271
274
  return () => removeHostListener(document, 'keydown', onKey, true);
272
- });
275
+ }, []);
273
276
  useEffect(() => {
274
277
  const row = list.current?.querySelector(`#palette-o${current}`);
275
278
  /* The first row of a group brings its heading with it, so a list scrolled up by the arrows does not leave the
@@ -280,11 +283,11 @@ export function Palette({ prefill = '', onClose }) {
280
283
  return (_jsx("div", { className: "palette-backdrop", onPointerDown: (e) => {
281
284
  if (e.target === e.currentTarget)
282
285
  onClose();
283
- }, children: _jsxs("div", { className: `palette${inApp ? ' palette-grouped' : ''}`, role: "dialog", "aria-modal": "true", "aria-label": say('navigation.search'), children: [_jsx("span", { className: "palette-glyph", "aria-hidden": "true", children: _jsx(Icon, { name: "magnifying-glass", size: 16 }) }), _jsx("input", { ref: input, type: "text", className: "palette-input", placeholder: shell().inApp() ? say('searchRecordsPagesAndCommands') : say('goToATable'), "aria-label": say('navigation.search'), autoComplete: "off", spellCheck: false, role: "combobox", "aria-autocomplete": "list", "aria-expanded": "true", "aria-controls": "palette-list", "aria-activedescendant": shown.length ? `palette-o${current}` : undefined, value: query, onChange: (e) => {
286
+ }, children: _jsxs("div", { className: `palette${inApp ? ' palette-grouped' : ''}`, role: "dialog", "aria-modal": "true", "aria-label": say('navigation.search'), children: [_jsx("span", { className: "palette-glyph", "aria-hidden": "true", children: _jsx(Icon, { name: "magnifying-glass", size: 16 }) }), _jsx("input", { ref: input, type: "text", className: "palette-input", placeholder: shell().inApp() ? say('searchRecordsPagesAndCommands') : say('goToATable'), "aria-label": say('navigation.search'), autoComplete: "off", spellCheck: false, role: "combobox", "aria-autocomplete": "list", "aria-expanded": shown.length > 0, "aria-controls": shown.length ? 'palette-list' : undefined, "aria-activedescendant": shown.length ? `palette-o${current}` : undefined, value: query, onChange: (e) => {
284
287
  setQuery(e.currentTarget.value);
285
288
  setActive(0);
286
- } }), _jsx("div", { ref: list, className: "palette-list", id: "palette-list", role: "listbox", "aria-label": say('navigation.search'), children: !shown.length
287
- ? settled && _jsx("p", { className: "palette-empty", children: term ? say('nothingMatches', { term }) : say('nothingToGo') })
289
+ } }), _jsx("div", { ref: list, className: "palette-list", id: "palette-list", role: shown.length ? 'listbox' : undefined, "aria-label": shown.length ? say('navigation.search') : undefined, children: !shown.length
290
+ ? settled && (_jsx("p", { className: "palette-empty", role: "status", children: term ? say('nothingMatches', { term }) : say('nothingToGo') }))
288
291
  : inApp
289
292
  ? grouped.map(({ group, items, from: first }) => {
290
293
  return (_jsxs("div", { className: "palette-group", role: "group", "aria-labelledby": `palette-g-${group}`, children: [_jsx("div", { className: "palette-group-head", id: `palette-g-${group}`, children: groupWord(group) }), items.map((item, at) => {
@@ -70,6 +70,7 @@ export function RichTextEditor({ id, value, onChange, label, describedBy, invali
70
70
  const latest = useLatest({ onChange, mentions, pictures, onKey, onProblem, suggesting });
71
71
  /* The last query whose people came back, and how many: a space is let into the query only while it still names someone. */
72
72
  const answered = useRef({ query: '', count: 1 });
73
+ const root = useRef(null);
73
74
  const fileInput = useRef(null);
74
75
  /* The editor, for the paste and drop handlers it is configured with before it exists. */
75
76
  const editorRef = useRef(null);
@@ -300,7 +301,7 @@ export function RichTextEditor({ id, value, onChange, label, describedBy, invali
300
301
  setLinkProblem(false);
301
302
  setLinking(editor.getAttributes('link').href ?? '');
302
303
  };
303
- return (_jsxs("div", { className: `rich-editor${disabled ? ' is-disabled' : ''}`, "data-invalid": invalid ? '' : undefined, children: [_jsxs("div", { className: "rich-toolbar", role: "toolbar", "aria-label": say('formatting', { label }), children: [_jsx(ToolButton, { label: say('bold'), active: editor.isActive('bold'), disabled: disabled, onClick: run((c) => c.toggleBold()), children: _jsx("strong", { children: say('boldMark') }) }), _jsx(ToolButton, { label: say('italic'), active: editor.isActive('italic'), disabled: disabled, onClick: run((c) => c.toggleItalic()), children: _jsx("em", { children: say('italicMark') }) }), _jsx(ToolButton, { label: say('strike'), active: editor.isActive('strike'), disabled: disabled, onClick: run((c) => c.toggleStrike()), children: _jsx("s", { children: say('strikeMark') }) }), _jsx("span", { className: "rich-tool-gap", "aria-hidden": "true" }), _jsxs(DropMenu, { className: "rich-tool-menu", triggerClassName: "rich-tool rich-tool-wide", triggerTitle: say('textStyle'), triggerLabel: `${say('textStyle')}: ${style}`, label: _jsxs(_Fragment, { children: [style, _jsx("span", { className: "rich-tool-caret", "aria-hidden": "true", children: "\u25BE" })] }), popupClassName: "page-actions-popup rich-menu", align: "start", children: [_jsx(DropItem, { className: "page-actions-item", onClick: run((c) => c.setParagraph()), children: say('paragraph') }), [2, 3, 4].map((level) => (_jsx(DropItem, { className: `page-actions-item rich-menu-h${level}`, onClick: run((c) => c.setHeading({ level })), children: say('heading', { level }) }, level))), _jsx(DropItem, { className: "page-actions-item", onClick: run((c) => c.toggleBlockquote()), children: say('quote') }), _jsx(DropItem, { className: "page-actions-item", onClick: run((c) => c.toggleCodeBlock()), children: say('codeBlock') })] }), _jsx("span", { className: "rich-tool-gap", "aria-hidden": "true" }), _jsx(ToolButton, { label: say('bulletList'), active: editor.isActive('bulletList'), disabled: disabled, onClick: run((c) => c.toggleBulletList()), children: "\u2022\u2261" }), _jsx(ToolButton, { label: say('orderedList'), active: editor.isActive('orderedList'), disabled: disabled, onClick: run((c) => c.toggleOrderedList()), children: "1\u2261" }), _jsx(ToolButton, { label: say('taskList'), active: editor.isActive('taskList'), disabled: disabled, onClick: run((c) => c.toggleTaskList()), children: "\u2611" }), _jsx("span", { className: "rich-tool-gap", "aria-hidden": "true" }), _jsx(ToolButton, { label: say('link'), active: editor.isActive('link'), disabled: disabled, onClick: openLink, children: "\u2197" }), _jsx(ToolButton, { label: say('inlineCode'), active: editor.isActive('code'), disabled: disabled, onClick: run((c) => c.toggleCode()), children: '</>' }), _jsxs(DropMenu, { className: "rich-tool-menu", triggerClassName: "rich-tool", triggerTitle: say('table'), triggerLabel: say('table'), label: "\u229E", popupClassName: "page-actions-popup rich-menu", align: "start", children: [_jsx(DropItem, { className: "page-actions-item", disabled: inTable, onClick: run((c) => c.insertTable({ rows: 3, cols: 3, withHeaderRow: true })), children: say('tableInsert') }), _jsx(DropItem, { className: "page-actions-item", disabled: !inTable, onClick: run((c) => c.addRowAfter()), children: say('tableRowAfter') }), _jsx(DropItem, { className: "page-actions-item", disabled: !inTable, onClick: run((c) => c.addColumnAfter()), children: say('tableColumnAfter') }), _jsx(DropItem, { className: "page-actions-item", disabled: !inTable, onClick: run((c) => c.deleteRow()), children: say('tableRowDelete') }), _jsx(DropItem, { className: "page-actions-item", disabled: !inTable, onClick: run((c) => c.deleteColumn()), children: say('tableColumnDelete') }), _jsx(DropItem, { className: "page-actions-item", disabled: !inTable, onClick: run((c) => c.deleteTable()), children: say('tableDelete') })] }), pictures && (_jsxs(_Fragment, { children: [_jsx(ToolButton, { label: adding ? say('pictureAdding') : say('picture'), disabled: disabled, onClick: () => fileInput.current?.click(), children: "\u25A3" }), _jsx("input", { ref: fileInput, type: "file", accept: "image/*", hidden: true, onChange: (event) => {
304
+ return (_jsxs("div", { ref: root, className: `rich-editor${disabled ? ' is-disabled' : ''}`, "data-invalid": invalid ? '' : undefined, children: [_jsxs("div", { className: "rich-toolbar", role: "toolbar", "aria-label": say('formatting', { label }), children: [_jsx(ToolButton, { label: say('bold'), active: editor.isActive('bold'), disabled: disabled, onClick: run((c) => c.toggleBold()), children: _jsx("strong", { children: say('boldMark') }) }), _jsx(ToolButton, { label: say('italic'), active: editor.isActive('italic'), disabled: disabled, onClick: run((c) => c.toggleItalic()), children: _jsx("em", { children: say('italicMark') }) }), _jsx(ToolButton, { label: say('strike'), active: editor.isActive('strike'), disabled: disabled, onClick: run((c) => c.toggleStrike()), children: _jsx("s", { children: say('strikeMark') }) }), _jsx("span", { className: "rich-tool-gap", "aria-hidden": "true" }), _jsxs(DropMenu, { className: "rich-tool-menu", triggerClassName: "rich-tool rich-tool-wide", triggerTitle: say('textStyle'), triggerLabel: `${say('textStyle')}: ${style}`, disabled: disabled, label: _jsxs(_Fragment, { children: [style, _jsx("span", { className: "rich-tool-caret", "aria-hidden": "true", children: "\u25BE" })] }), popupClassName: "page-actions-popup rich-menu", align: "start", children: [_jsx(DropItem, { className: "page-actions-item", onClick: run((c) => c.setParagraph()), children: say('paragraph') }), [2, 3, 4].map((level) => (_jsx(DropItem, { className: `page-actions-item rich-menu-h${level}`, onClick: run((c) => c.setHeading({ level })), children: say('heading', { level }) }, level))), _jsx(DropItem, { className: "page-actions-item", onClick: run((c) => c.toggleBlockquote()), children: say('quote') }), _jsx(DropItem, { className: "page-actions-item", onClick: run((c) => c.toggleCodeBlock()), children: say('codeBlock') })] }), _jsx("span", { className: "rich-tool-gap", "aria-hidden": "true" }), _jsx(ToolButton, { label: say('bulletList'), active: editor.isActive('bulletList'), disabled: disabled, onClick: run((c) => c.toggleBulletList()), children: "\u2022\u2261" }), _jsx(ToolButton, { label: say('orderedList'), active: editor.isActive('orderedList'), disabled: disabled, onClick: run((c) => c.toggleOrderedList()), children: "1\u2261" }), _jsx(ToolButton, { label: say('taskList'), active: editor.isActive('taskList'), disabled: disabled, onClick: run((c) => c.toggleTaskList()), children: "\u2611" }), _jsx("span", { className: "rich-tool-gap", "aria-hidden": "true" }), _jsx(ToolButton, { label: say('link'), active: editor.isActive('link'), disabled: disabled, onClick: openLink, children: "\u2197" }), _jsx(ToolButton, { label: say('inlineCode'), active: editor.isActive('code'), disabled: disabled, onClick: run((c) => c.toggleCode()), children: '</>' }), _jsxs(DropMenu, { className: "rich-tool-menu", triggerClassName: "rich-tool", triggerTitle: say('table'), triggerLabel: say('table'), disabled: disabled, label: "\u229E", popupClassName: "page-actions-popup rich-menu", align: "start", children: [_jsx(DropItem, { className: "page-actions-item", disabled: inTable, onClick: run((c) => c.insertTable({ rows: 3, cols: 3, withHeaderRow: true })), children: say('tableInsert') }), _jsx(DropItem, { className: "page-actions-item", disabled: !inTable, onClick: run((c) => c.addRowAfter()), children: say('tableRowAfter') }), _jsx(DropItem, { className: "page-actions-item", disabled: !inTable, onClick: run((c) => c.addColumnAfter()), children: say('tableColumnAfter') }), _jsx(DropItem, { className: "page-actions-item", disabled: !inTable, onClick: run((c) => c.deleteRow()), children: say('tableRowDelete') }), _jsx(DropItem, { className: "page-actions-item", disabled: !inTable, onClick: run((c) => c.deleteColumn()), children: say('tableColumnDelete') }), _jsx(DropItem, { className: "page-actions-item", disabled: !inTable, onClick: run((c) => c.deleteTable()), children: say('tableDelete') })] }), pictures && (_jsxs(_Fragment, { children: [_jsx(ToolButton, { label: adding ? say('pictureAdding') : say('picture'), disabled: disabled, onClick: () => fileInput.current?.click(), children: "\u25A3" }), _jsx("input", { ref: fileInput, type: "file", accept: "image/*", hidden: true, onChange: (event) => {
304
305
  const files = [...(event.target.files ?? [])];
305
306
  event.target.value = '';
306
307
  addPictures(editor, files);
@@ -327,10 +328,10 @@ export function RichTextEditor({ id, value, onChange, label, describedBy, invali
327
328
  event.preventDefault();
328
329
  openLink();
329
330
  }
330
- } }), suggesting && _jsx(MentionList, { suggesting: suggesting, onPick: (person) => suggesting.pick(person) })] }));
331
+ } }), suggesting && (_jsx(MentionList, { suggesting: suggesting, container: root.current?.closest('dialog, [role="dialog"]') ?? popupContainer() ?? null, onPick: (person) => suggesting.pick(person) }))] }));
331
332
  }
332
333
  /* The people an @ may name, under the @: a listbox the editor drives by key (the focus stays in the text). */
333
- function MentionList({ suggesting, onPick }) {
334
+ function MentionList({ suggesting, container, onPick, }) {
334
335
  /* Where the @ stands, as the window measures it. UI SDK places the list in the same measure and works out the
335
336
  density zoom for itself from the list's own box, so nothing is divided out here. */
336
337
  const anchor = { getBoundingClientRect: () => suggesting.box() ?? new DOMRect() };
@@ -340,7 +341,7 @@ function MentionList({ suggesting, onPick }) {
340
341
  , {
341
342
  /* A popover's panel says it is a dialog named by its trigger. This one has no trigger and takes no focus:
342
343
  it holds the listbox the editor drives, and the panel itself is nothing to a reader. */
343
- render: (part) => _jsx("div", { ...part, role: "presentation", "aria-labelledby": undefined }), className: "rich-mentions", anchor: anchor, side: "bottom", align: "start", sideOffset: 4, collisionPadding: 8, container: popupContainer(), initialFocus: "none", finalFocus: "none", children: _jsx("div", { role: "listbox", "aria-label": say('people'), children: suggesting.items.length ? (suggesting.items.map((person, index) => (_jsxs("div", { role: "option", "aria-selected": index === suggesting.index, className: `rich-mention-option${index === suggesting.index ? ' is-active' : ''}`, onMouseDown: (event) => {
344
+ render: (part) => _jsx("div", { ...part, role: "presentation", "aria-labelledby": undefined }), className: "rich-mentions", anchor: anchor, side: "bottom", align: "start", sideOffset: 4, collisionPadding: 8, container: container, initialFocus: "none", finalFocus: "none", children: _jsx("div", { role: "listbox", "aria-label": say('people'), children: suggesting.items.length ? (suggesting.items.map((person, index) => (_jsxs("div", { role: "option", "aria-selected": index === suggesting.index, className: `rich-mention-option${index === suggesting.index ? ' is-active' : ''}`, onMouseDown: (event) => {
344
345
  event.preventDefault();
345
346
  onPick(person);
346
347
  }, children: [_jsx("span", { children: person.label }), person.kind === 'group' ? (_jsx("span", { className: "rich-mention-kind", children: say('group') })) : (person.handle && _jsxs("span", { className: "rich-mention-handle", children: ["@", person.handle] }))] }, `${person.kind ?? 'person'}:${person.id}`)))) : (_jsx("div", { className: "rich-mention-none", children: say('noPeople') })) }) }) }));
@@ -38,8 +38,11 @@ export function textMeasure(font) {
38
38
  const cache = new Map();
39
39
  const measure = (text) => {
40
40
  const seen = cache.get(text);
41
- if (seen !== undefined)
41
+ if (seen !== undefined) {
42
+ cache.delete(text);
43
+ cache.set(text, seen);
42
44
  return seen;
45
+ }
43
46
  context.font = font;
44
47
  /* Cells set their figures tabular (themeFamilies.css), and a canvas cannot: measured proportional,
45
48
  "$105,828" came out a few pixels short and its cell cut it to "$105,8…". Every figure is measured as a
@@ -55,6 +58,8 @@ export function textMeasure(font) {
55
58
  for (const mark of text)
56
59
  width += gain.get(mark >= '0' && mark <= '9' ? '0' : mark) ?? 0;
57
60
  }
61
+ if (cache.size >= 5000)
62
+ cache.delete(cache.keys().next().value);
58
63
  cache.set(text, width);
59
64
  return width;
60
65
  };
@@ -228,12 +228,12 @@ export function useGridKeyboard(tableRef, wrapRef, opts) {
228
228
  };
229
229
  }, [tableRef, wrapRef, rowCount, columnCount, offset, onOpen, onPeek, totalRows, firstRow]);
230
230
  }
231
- /** Copy one cell: `title` before `textContent`, because a shortened value
232
- keeps the whole thing in its tooltip. */
231
+ /** Copy one cell: `data-copy` (full unclamped text) before `title` before `textContent`,
232
+ because a shortened value keeps the whole thing off-screen. */
233
233
  async function copyCell(cell) {
234
234
  if (!cell)
235
235
  return;
236
- const text = cell.getAttribute('title') ?? cell.textContent ?? '';
236
+ const text = cell.getAttribute('data-copy') ?? cell.getAttribute('title') ?? cell.textContent ?? '';
237
237
  try {
238
238
  await navigator.clipboard.writeText(text);
239
239
  cell.classList.add('cell-copied');
@@ -23,20 +23,34 @@ export function useStickyHead(wrapRef, repaintKey) {
23
23
  return;
24
24
  const trail = [...scroller.querySelectorAll('.crumbs')].find((el) => getComputedStyle(el).position === 'sticky');
25
25
  const head = table.querySelector('thead');
26
+ const raf = (fn) => {
27
+ let id = 0;
28
+ const run = () => {
29
+ if (!id)
30
+ id = requestAnimationFrame(() => {
31
+ id = 0;
32
+ fn();
33
+ });
34
+ };
35
+ return [run, () => id && cancelAnimationFrame(id)];
36
+ };
26
37
  const fit = () => {
27
38
  /* The table's own width against the wrap's, which holds whichever way the wrap overflows. */
28
39
  const fits = table.scrollWidth <= wrap.clientWidth + 1;
40
+ const top = trail?.offsetHeight ?? 0;
29
41
  wrap.toggleAttribute('data-fits', fits);
30
- wrap.style.setProperty('--head-top', `${trail?.offsetHeight ?? 0}px`);
42
+ wrap.style.setProperty('--head-top', `${top}px`);
31
43
  more();
32
44
  stuck();
33
45
  };
34
46
  const more = () => {
35
47
  const past = wrap.scrollWidth - wrap.clientWidth - wrap.scrollLeft;
36
48
  const sides = [wrap.scrollLeft > 1 ? 'start' : '', past > 1 ? 'end' : ''].filter(Boolean).join(' ');
37
- if (sides)
38
- wrap.dataset.more = sides;
39
- else
49
+ if (sides) {
50
+ if (wrap.dataset.more !== sides)
51
+ wrap.dataset.more = sides;
52
+ }
53
+ else if (wrap.dataset.more !== undefined)
40
54
  delete wrap.dataset.more;
41
55
  };
42
56
  const stuck = () => {
@@ -47,19 +61,23 @@ export function useStickyHead(wrapRef, repaintKey) {
47
61
  const box = table.getBoundingClientRect();
48
62
  wrap.toggleAttribute('data-stuck', box.top < top - 0.5 && box.bottom > top + head.getBoundingClientRect().height);
49
63
  };
64
+ const [onStuck, stopStuck] = raf(stuck);
65
+ const [onMore, stopMore] = raf(more);
50
66
  const size = new ResizeObserver(fit);
51
67
  size.observe(wrap);
52
68
  size.observe(table);
53
69
  if (trail)
54
70
  size.observe(trail);
55
- scroller.addEventListener('scroll', stuck, { passive: true });
56
- wrap.addEventListener('scroll', more, { passive: true });
71
+ scroller.addEventListener('scroll', onStuck, { passive: true });
72
+ wrap.addEventListener('scroll', onMore, { passive: true });
57
73
  fit();
58
74
  return () => {
75
+ stopStuck();
76
+ stopMore();
59
77
  size.disconnect();
60
- wrap.removeEventListener('scroll', more);
78
+ wrap.removeEventListener('scroll', onMore);
61
79
  delete wrap.dataset.more;
62
- scroller.removeEventListener('scroll', stuck);
80
+ scroller.removeEventListener('scroll', onStuck);
63
81
  };
64
82
  }, [wrapRef, repaintKey]);
65
83
  }
@@ -11,7 +11,7 @@ const spoken = new WeakMap();
11
11
  status waited behind whatever was being read. */
12
12
  function announce(box, message, urgent) {
13
13
  const id = urgent ? (box.dataset.alert ?? box.dataset.live) : box.dataset.live;
14
- const live = id ? box.ownerDocument.getElementById(id) : null;
14
+ const live = id ? (box.getRootNode().getElementById?.(id) ?? box.ownerDocument.getElementById(id)) : null;
15
15
  if (!live)
16
16
  return;
17
17
  clearTimeout(spoken.get(live));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mistriwork/kit",
3
- "version": "1.0.0-rc.69",
3
+ "version": "1.0.0-rc.70",
4
4
  "description": "The shared React client both shells are drawn with: the walk and the address, Grid, Value, the record page, lists, filters and charts.",
5
5
  "homepage": "https://mistriwork.dev",
6
6
  "bugs": {
@@ -85,8 +85,8 @@
85
85
  "./package.json": "./package.json"
86
86
  },
87
87
  "dependencies": {
88
- "@mistriwork/engine": "1.0.0-rc.69",
89
- "@mistriwork/ui": "1.0.0-rc.69",
88
+ "@mistriwork/engine": "1.0.0-rc.70",
89
+ "@mistriwork/ui": "1.0.0-rc.70",
90
90
  "intl-messageformat": "12.1.2",
91
91
  "qrcode-generator": "^2.0.4"
92
92
  },