@notis_ai/cli 0.2.27 → 0.2.29

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.
Files changed (53) hide show
  1. package/README.md +2 -2
  2. package/config/notis_app_design_rules.json +5 -123
  3. package/dist/agent-hooks/notis-agent-hook.mjs +453 -109
  4. package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
  5. package/dist/base-skills/notis-spaces/SKILL.md +13 -19
  6. package/dist/base-skills/notis-spaces/references/design.md +11 -45
  7. package/dist/base-skills/notis-spaces/references/sdk.md +94 -68
  8. package/dist/base-skills/notis-spaces/references/views.md +12 -1
  9. package/dist/sdk/src/components/NotisCommentBoundary.tsx +43 -83
  10. package/dist/sdk/src/components/NotisSelectionBoundary.tsx +28 -8
  11. package/dist/sdk/src/components/SelectionActionBar.tsx +383 -0
  12. package/dist/sdk/src/components/selectionId.ts +6 -0
  13. package/dist/sdk/src/hooks/useCollectionInteractions.ts +5 -2
  14. package/dist/sdk/src/runtime.ts +5 -0
  15. package/dist/sdk/src/space.ts +4 -0
  16. package/dist/sdk/src/ui/icons.tsx +11 -2
  17. package/dist/sdk/src/words/actions.ts +9 -1
  18. package/dist/sdk/src/words/keymap.ts +3 -0
  19. package/dist/space-harness/host.js +181 -141
  20. package/dist/space-sdk/dist/{chunk-BWHAORT4.js → chunk-BFGB6XXC.js} +2 -2
  21. package/dist/space-sdk/dist/index.js +2 -2
  22. package/dist/space-sdk/dist/ui.js +14 -11
  23. package/dist/space-sdk/src/components/NotisCommentBoundary.d.ts +0 -10
  24. package/dist/space-sdk/src/components/NotisSelectionBoundary.d.ts +7 -0
  25. package/dist/space-sdk/src/runtime.d.ts +5 -0
  26. package/dist/space-sdk/src/space.ts +4 -0
  27. package/dist/space-sdk/src/tailwind-candidates.d.ts +126 -17
  28. package/dist/space-sdk/src/ui/blocks/DataTable.d.ts +86 -0
  29. package/dist/space-sdk/src/ui/blocks/InfoTip.d.ts +25 -0
  30. package/dist/space-sdk/src/ui/blocks/Meter.d.ts +39 -0
  31. package/dist/space-sdk/src/ui/blocks/blocks.d.ts +1 -1
  32. package/dist/space-sdk/src/ui/blocks/index.d.ts +6 -0
  33. package/dist/space-sdk/src/ui/charts/Chart.d.ts +15 -2
  34. package/dist/space-sdk/src/ui/charts/StatRow.d.ts +4 -3
  35. package/dist/space-sdk/src/ui/charts/chartData.d.ts +6 -0
  36. package/dist/space-sdk/src/ui/comments/useComments.d.ts +19 -1
  37. package/dist/space-sdk/src/ui/icons.d.ts +1 -1
  38. package/dist/space-sdk/src/ui/index.d.ts +2 -2
  39. package/dist/space-sdk/src/ui/list/Row.d.ts +10 -3
  40. package/dist/space-sdk/src/ui/period/dateFormat.d.ts +14 -0
  41. package/dist/space-sdk/src/words/actions.ts +9 -1
  42. package/dist/space-sdk/src/words/keymap.ts +3 -0
  43. package/dist/view-renderer/dist/host.js +253 -213
  44. package/dist/view-renderer/src/renderer.js +38 -2
  45. package/package.json +3 -3
  46. package/src/command-specs/computer.js +3 -3
  47. package/src/command-specs/spaces.js +28 -8
  48. package/src/command-specs/tools.js +1 -1
  49. package/src/runtime/app-platform.js +74 -11
  50. package/src/runtime/space-fixture-broker.js +23 -2
  51. package/src/runtime/space-verification.js +62 -10
  52. package/template/components/ui/button.tsx +1 -1
  53. package/template/components/ui/native-select.tsx +1 -1
@@ -2,6 +2,7 @@ import type { CSSProperties, ClipboardEvent, ReactNode } from 'react';
2
2
  import React, { useCallback } from 'react';
3
3
  import { useNotisRuntime } from '../provider';
4
4
  import type { ContextResource, ContextSelection, NotisRuntime } from '../runtime';
5
+ import { newSelectionId } from './selectionId';
5
6
 
6
7
  export const NOTIS_CONTEXT_CLIPBOARD_TYPE = 'application/x-notis-context+json';
7
8
 
@@ -12,12 +13,6 @@ export interface NotisSelectionBoundaryProps {
12
13
  style?: CSSProperties;
13
14
  }
14
15
 
15
- function selectionId(): string {
16
- return typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function'
17
- ? crypto.randomUUID()
18
- : `selection-${Date.now()}-${Math.random().toString(36).slice(2)}`;
19
- }
20
-
21
16
  /** The selection's markup for other paste targets: hidden parts dropped, links made absolute. */
22
17
  function selectionHtml(selection: Selection): string {
23
18
  if (typeof document === 'undefined') return '';
@@ -61,7 +56,7 @@ export function addCopiedSelectionToClipboard(
61
56
  const text = wrotePlain || selection.toString();
62
57
  if (!text.trim()) return null;
63
58
 
64
- const payload: ContextSelection = { ...context, id: selectionId(), text };
59
+ const payload: ContextSelection = { ...context, id: newSelectionId(), text };
65
60
  if (!editorWrote) {
66
61
  // Keep the copied formatting (links, bold, tables) for every other paste target.
67
62
  const html = selectionHtml(selection);
@@ -109,5 +104,30 @@ export function NotisSelectionBoundary({
109
104
  ...(resource ? { resource: { ...resource, snapshot: undefined } } : {}),
110
105
  }), [resource, runtime]);
111
106
 
112
- return <div className={className} style={style} onCopy={onCopy}>{children}</div>;
107
+ // Cite reads the same resource as copy: the bar looks it up from the selection (`quoteResourceFor`).
108
+ const marker = resource ? JSON.stringify({ ...resource, snapshot: undefined }) : undefined;
109
+ return <div className={className} style={style} onCopy={onCopy} data-notis-quote-resource={marker}>{children}</div>;
110
+ }
111
+
112
+ /** The resource a Space's own boundary names for the text in `range`, as copy would quote it; null outside one. */
113
+ export function quoteResourceFor(range: Range): ContextResource | null {
114
+ const start = range.commonAncestorContainer;
115
+ const element = start.nodeType === Node.ELEMENT_NODE ? start as Element : start.parentElement;
116
+ const marked = element?.closest('[data-notis-quote-resource]')?.getAttribute('data-notis-quote-resource');
117
+ if (!marked) return null;
118
+ try { return JSON.parse(marked) as ContextResource; } catch { return null; }
119
+ }
120
+
121
+ /**
122
+ * Cite for a Space (truth PRT-087): the selected text goes to chat as the quote copy would make, its Space as source
123
+ * and the boundary's resource when one names it. A Site's runtime has no chat, so it cites nothing.
124
+ */
125
+ export function citeSpaceSelection(runtime: Pick<NotisRuntime, 'contextSource' | 'addContext'> | null, range: Range, text: string): Promise<boolean> {
126
+ if (!runtime?.addContext) return Promise.resolve(false);
127
+ const resource = quoteResourceFor(range);
128
+ const source = runtime.contextSource;
129
+ return runtime.addContext({
130
+ id: newSelectionId(), text,
131
+ ...(resource ? { resource } : source ? { title: source.appName } : {}),
132
+ });
113
133
  }
@@ -0,0 +1,383 @@
1
+ 'use client';
2
+ import React, { useCallback, useEffect, useLayoutEffect, useRef, useState, type ReactNode, type RefObject } from 'react';
3
+ import { useToolkitLocale } from '../ui/engine/hooks';
4
+ import type { Words } from '../words/types';
5
+
6
+ /**
7
+ * The floating bar on selected text (truths PRT-087, PRT-090, PRT-094): one dark labelled pill at the end of the
8
+ * selection, with Cite and, where a surface takes comments, Comment. Chat, every Space view, Skills and automations
9
+ * draw the same bar; each surface decides what Cite quotes and where the quote goes.
10
+ */
11
+
12
+ /** Cmd+Shift+C (Ctrl+Shift+C off a Mac) cites the selection: the host dispatches this on the document, and the bar on screen answers. */
13
+ export const CITE_SELECTION_EVENT = 'notis:cite-selection';
14
+
15
+ export const SELECTION_BAR_WORDS = Object.freeze({
16
+ cite: Object.freeze({ en: 'Cite', fr: 'Citer' }),
17
+ citeHint: Object.freeze({ en: 'Cite in chat', fr: 'Citer dans le chat' }),
18
+ comment: Object.freeze({ en: 'Comment', fr: 'Commenter' }),
19
+ }) satisfies Readonly<Record<string, Words>>;
20
+
21
+ export interface SelectionBarAction {
22
+ key: string;
23
+ label: string;
24
+ title?: string;
25
+ icon: ReactNode;
26
+ onSelect(): void;
27
+ }
28
+
29
+ export interface SelectionAnchor {
30
+ top: number;
31
+ left: number;
32
+ /** The selected text, trimmed. */
33
+ text: string;
34
+ /** A copy of the selected range, still valid after the browser collapses the live selection. */
35
+ range: Range;
36
+ }
37
+
38
+ type Rect = Pick<DOMRect, 'left' | 'right' | 'top' | 'bottom'>;
39
+ const GAP = 8;
40
+ const TOUCH_GAP = 14;
41
+
42
+ /**
43
+ * Where the bar goes: after the last selected line when it fits there and no text follows on that line, otherwise
44
+ * just below where the selection ends (above it near the bottom of the viewport). On a touch screen it always goes
45
+ * below, so the system's own Copy menu keeps the space above the selection.
46
+ */
47
+ export function getSelectionBarPosition(
48
+ rects: Rect[],
49
+ viewport: { width: number; height: number },
50
+ bar: { width: number; height: number },
51
+ options: { rightBoundary?: number; trailing?: Rect[]; coarse?: boolean } = {},
52
+ ): { top: number; left: number } {
53
+ const last = rects[rects.length - 1];
54
+ const { width, height } = bar;
55
+ const rightBoundary = options.rightBoundary ?? viewport.width;
56
+ const clampX = (x: number) => Math.max(GAP, Math.min(viewport.width - width - GAP, x));
57
+ const clampY = (y: number) => Math.max(GAP, Math.min(viewport.height - height - GAP, y));
58
+ if (!options.coarse) {
59
+ const beside = { left: last.right + GAP, top: clampY((last.top + last.bottom - height) / 2) };
60
+ const overlapsText = (options.trailing ?? []).some(rect => rect.left < beside.left + width && rect.right > beside.left
61
+ && rect.top < beside.top + height && rect.bottom > beside.top);
62
+ if (beside.left + width <= Math.min(viewport.width, rightBoundary) - GAP && !overlapsText) return beside;
63
+ }
64
+ const gap = options.coarse ? TOUCH_GAP : GAP;
65
+ const below = last.bottom + gap;
66
+ const left = clampX(options.coarse ? (last.left + last.right - width) / 2 : last.right - width);
67
+ return { left, top: clampY(below + height <= viewport.height - GAP ? below : last.top - height - gap) };
68
+ }
69
+
70
+ function isCoarsePointer(view: Window | null): boolean {
71
+ return Boolean(view?.matchMedia?.('(pointer: coarse)').matches);
72
+ }
73
+
74
+ // Where a selection may not start or end: fields, editable text and the bar itself.
75
+ const EDITABLE = 'input,textarea,select,[contenteditable]:not([contenteditable="false"]),[data-notis-selection-ui]';
76
+
77
+ /** The live selection's ends, to tell when it moved away from what the bar shows. */
78
+ type Ends = { startContainer: Node; startOffset: number; endContainer: Node; endOffset: number };
79
+ function endsOf(range: Range): Ends {
80
+ return { startContainer: range.startContainer, startOffset: range.startOffset, endContainer: range.endContainer, endOffset: range.endOffset };
81
+ }
82
+ function sameEnds(a: Ends, b: Ends): boolean {
83
+ return a.startContainer === b.startContainer && a.startOffset === b.startOffset
84
+ && a.endContainer === b.endContainer && a.endOffset === b.endOffset;
85
+ }
86
+
87
+ function elementOf(node: Node): Element | null {
88
+ return node.nodeType === Node.ELEMENT_NODE ? node as Element : node.parentElement;
89
+ }
90
+
91
+ function selectionIn(node: Node): Selection | null {
92
+ const scope = node.getRootNode() as ShadowRoot & { getSelection?: () => Selection | null };
93
+ return scope.getSelection?.() || node.ownerDocument?.defaultView?.getSelection() || null;
94
+ }
95
+
96
+ /**
97
+ * The surface's box. A `display: contents` element draws none: its content's own box stands in when it draws one
98
+ * (a boundary given a className), else the nearest ancestor that does.
99
+ */
100
+ function boundsOf(node: HTMLElement): DOMRect {
101
+ let element: Element = node;
102
+ let box = element.getBoundingClientRect();
103
+ for (let depth = 0; !box.width && element.firstElementChild && depth < 8; depth += 1) {
104
+ const child = element.firstElementChild.getBoundingClientRect();
105
+ if (child.width) return child;
106
+ element = element.firstElementChild;
107
+ }
108
+ element = node;
109
+ while (!box.width && element.parentElement) {
110
+ element = element.parentElement;
111
+ box = element.getBoundingClientRect();
112
+ }
113
+ return box;
114
+ }
115
+
116
+ export interface UseSelectionAnchorOptions {
117
+ /** Off while the surface has nowhere to send a quote (a public Site, a chat that cannot send). */
118
+ enabled?: boolean;
119
+ /** Refuse a selection the surface does not quote (inside a nested surface with its own bar). */
120
+ accept?(range: Range, root: HTMLElement): boolean;
121
+ /** Clip the selection to the surface instead of refusing one that spills over its edge. */
122
+ clip?(range: Range, root: HTMLElement): Range | null;
123
+ /** The bar's size, measured once it shows; used to keep it inside the viewport. */
124
+ barSize?: { width: number; height: number };
125
+ /** More places a selection may not start or end in, on top of inputs and editable text (a CSS selector). */
126
+ exclude?: string;
127
+ }
128
+
129
+ /**
130
+ * Follows the text selected inside `root` and returns where the bar shows, or null. A mouse or keyboard selection
131
+ * shows the bar when it ends (mouse up, Shift+arrow up); a touch selection once it has stopped moving.
132
+ */
133
+ export function useSelectionAnchor(root: RefObject<HTMLElement | null>, options: UseSelectionAnchorOptions = {}) {
134
+ const { enabled = true } = options;
135
+ const [anchor, setAnchor] = useState<SelectionAnchor | null>(null);
136
+ const anchorRef = useRef<SelectionAnchor | null>(null);
137
+ anchorRef.current = anchor;
138
+ const optionsRef = useRef(options);
139
+ optionsRef.current = options;
140
+ const settle = useRef<number | undefined>(undefined);
141
+ const pending = useRef<number | undefined>(undefined);
142
+ // The live selection the shown bar was read from: a different one hides the bar until it is read again.
143
+ const shownEnds = useRef<Ends | null>(null);
144
+
145
+ const read = useCallback((): SelectionAnchor | null => {
146
+ const node = root.current;
147
+ if (!node) return null;
148
+ const view = node.ownerDocument.defaultView;
149
+ const selection = selectionIn(node);
150
+ if (!selection?.rangeCount || selection.isCollapsed || !selection.toString().trim()) return null;
151
+ const live = selection.getRangeAt(0);
152
+ let range: Range | null = live.cloneRange();
153
+ const clipped = !node.contains(range.startContainer) || !node.contains(range.endContainer);
154
+ if (clipped) {
155
+ // A selection in another tree (the page around a Space's shadow root) cannot be compared with this one.
156
+ try { range = optionsRef.current.clip?.(range, node) ?? null; } catch { range = null; }
157
+ if (!range) return null;
158
+ }
159
+ const start = elementOf(range.startContainer);
160
+ const end = elementOf(range.endContainer);
161
+ const excluded = optionsRef.current.exclude ? `${EDITABLE},${optionsRef.current.exclude}` : EDITABLE;
162
+ if (start?.closest(excluded) || end?.closest(excluded)) return null;
163
+ if (optionsRef.current.accept && !optionsRef.current.accept(range, node)) return null;
164
+ // The range's own text: it is what the chat finds again when a quote link highlights the words.
165
+ const text = range.toString().trim();
166
+ if (!text) return null;
167
+ const lines = Array.from(range.getClientRects?.() || []).filter(line => line.width > 0 && line.height > 0);
168
+ const rect = range.getBoundingClientRect();
169
+ const trailing: DOMRect[] = [];
170
+ const endBlock = end?.closest('p,li,h1,h2,h3,h4,h5,h6,td,th,pre,blockquote,div');
171
+ if (endBlock && node.contains(endBlock)) {
172
+ const remainder = range.cloneRange();
173
+ remainder.selectNodeContents(endBlock);
174
+ remainder.setStart(range.endContainer, range.endOffset);
175
+ if (remainder.toString().trim()) trailing.push(...Array.from(remainder.getClientRects?.() || []).filter(line => line.width > 0 && line.height > 0));
176
+ }
177
+ const bounds = boundsOf(node);
178
+ const position = getSelectionBarPosition(lines.length ? lines : [rect],
179
+ { width: view?.innerWidth ?? 1024, height: view?.innerHeight ?? 768 },
180
+ optionsRef.current.barSize ?? { width: 80, height: 32 },
181
+ { rightBoundary: bounds.width ? bounds.right : undefined, trailing, coarse: isCoarsePointer(view) });
182
+ shownEnds.current = endsOf(live);
183
+ return { ...position, text, range };
184
+ }, [root]);
185
+
186
+ const dismiss = useCallback(() => setAnchor(null), []);
187
+
188
+ // The bar measured itself: place it again with its real width, so its edge lines up with the selection.
189
+ const barWidth = options.barSize?.width;
190
+ const barHeight = options.barSize?.height;
191
+ useEffect(() => {
192
+ // Read here, not inside the state updater: React may run an updater lazily or twice.
193
+ if (!anchorRef.current) return;
194
+ const next = read();
195
+ setAnchor(current => current ? next : current);
196
+ }, [barWidth, barHeight, read]);
197
+
198
+ useEffect(() => {
199
+ const node = root.current;
200
+ if (!enabled || !node) { setAnchor(null); return; }
201
+ const document = node.ownerDocument;
202
+ const view = document.defaultView;
203
+ const scope = node.getRootNode() as ShadowRoot | Document;
204
+ // Cheap checks only while the selection moves: no layout until it is read again.
205
+ const liveSelection = () => {
206
+ const selection = selectionIn(node);
207
+ const inside = (point: Node | null | undefined) => Boolean(point && node.contains(point));
208
+ if (!selection?.rangeCount || selection.isCollapsed || !(inside(selection.anchorNode) || inside(selection.focusNode))) return null;
209
+ return selection;
210
+ };
211
+ const capture = (event: Event) => {
212
+ if (event.target instanceof Element && event.target.closest('[data-notis-selection-ui]')) return;
213
+ // Let the browser finish the selection (a double click selects the word after mouseup).
214
+ view?.clearTimeout(pending.current);
215
+ pending.current = view?.setTimeout(() => setAnchor(read()), 0);
216
+ };
217
+ // Keys go to the focused element (often the page body), so a keyboard selection is followed on the document.
218
+ const onKeyUp = (event: KeyboardEvent) => {
219
+ if (!(event.shiftKey || event.key === 'Shift' || ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'a'))) return;
220
+ // Only a selection touching this surface (or a bar it shows) is worth reading: typing capitals elsewhere is not.
221
+ if (!liveSelection() && !anchorRef.current) return;
222
+ capture(event);
223
+ };
224
+ const onSelectionChange = () => {
225
+ if (!isCoarsePointer(view)) {
226
+ // A mouse or keyboard selection shows the bar when it ends (mouse up, key up). While it moves, the bar hides
227
+ // as soon as the selection is gone or is no longer the one the bar was read from (a clipped one included).
228
+ const current = selectionIn(node);
229
+ const moved = !current?.rangeCount || current.isCollapsed || !shownEnds.current
230
+ || !sameEnds(endsOf(current.getRangeAt(0)), shownEnds.current);
231
+ if (moved) setAnchor(shown => shown ? null : shown);
232
+ return;
233
+ }
234
+ const selection = liveSelection();
235
+ // A touch selection has no mouse up: show the bar once its handles stop moving.
236
+ view?.clearTimeout(settle.current);
237
+ setAnchor(current => current ? null : current);
238
+ if (!selection) return;
239
+ settle.current = view?.setTimeout(() => setAnchor(read()), 450);
240
+ };
241
+ const onScroll = () => {
242
+ if (!anchorRef.current) return;
243
+ const next = read();
244
+ setAnchor(current => current ? next : current);
245
+ };
246
+ node.addEventListener('mouseup', capture);
247
+ node.addEventListener('dblclick', capture);
248
+ document.addEventListener('keyup', onKeyUp);
249
+ document.addEventListener('selectionchange', onSelectionChange);
250
+ if (scope !== document) scope.addEventListener('selectionchange', onSelectionChange);
251
+ view?.addEventListener('scroll', onScroll, true);
252
+ view?.addEventListener('resize', onScroll);
253
+ return () => {
254
+ view?.clearTimeout(settle.current);
255
+ view?.clearTimeout(pending.current);
256
+ node.removeEventListener('mouseup', capture);
257
+ node.removeEventListener('dblclick', capture);
258
+ document.removeEventListener('keyup', onKeyUp);
259
+ document.removeEventListener('selectionchange', onSelectionChange);
260
+ if (scope !== document) scope.removeEventListener('selectionchange', onSelectionChange);
261
+ view?.removeEventListener('scroll', onScroll, true);
262
+ view?.removeEventListener('resize', onScroll);
263
+ };
264
+ }, [enabled, read, root]);
265
+
266
+ return { anchor, dismiss, refresh: () => setAnchor(read()) };
267
+ }
268
+
269
+ /** Clears the page's selection once its text was cited, so the bar does not linger over it. */
270
+ export function clearSelectionIn(node: Node | null | undefined): void {
271
+ if (node) selectionIn(node)?.removeAllRanges();
272
+ }
273
+
274
+ /**
275
+ * The Cite action of a selection bar: the same words and glyph everywhere; it clears the selection and hides the bar
276
+ * before handing over the cited text.
277
+ */
278
+ export function citeSelectionAction(locale: keyof typeof SELECTION_BAR_WORDS.cite, anchor: SelectionAnchor,
279
+ root: RefObject<HTMLElement | null>, dismiss: () => void, onCite: (range: Range, text: string) => void): SelectionBarAction {
280
+ return {
281
+ key: 'cite', label: SELECTION_BAR_WORDS.cite[locale], title: SELECTION_BAR_WORDS.citeHint[locale], icon: QUOTE_GLYPH,
282
+ onSelect: () => {
283
+ const { range, text } = anchor;
284
+ clearSelectionIn(root.current);
285
+ dismiss();
286
+ onCite(range, text);
287
+ },
288
+ };
289
+ }
290
+
291
+ export interface CiteSelectionBarProps {
292
+ /** The surface whose selected text Cite quotes. */
293
+ root: RefObject<HTMLElement | null>;
294
+ /** Receives the cited text once the bar has cleared the selection. */
295
+ onCite(range: Range, text: string): void;
296
+ enabled?: boolean;
297
+ accept?: UseSelectionAnchorOptions['accept'];
298
+ /**
299
+ * Draws the bar somewhere other than beside the surface. The Portal's own pages hand the bar to a React portal on
300
+ * the page body, out of a container that clips or transforms it. A Space view never gives one: a Notis app stays
301
+ * inside its app surface, so its bar is drawn there, fixed to the viewport.
302
+ */
303
+ portal?(bar: ReactNode): ReactNode;
304
+ }
305
+
306
+ /**
307
+ * The Cite-only bar every quoting surface shows (chat, Space views, Skills and automations; truth PRT-087): it follows
308
+ * the selection in `root`, measures itself, and hands the cited text to `onCite`.
309
+ */
310
+ export function CiteSelectionBar({ root, onCite, enabled = true, accept, portal }: CiteSelectionBarProps) {
311
+ const locale = useToolkitLocale();
312
+ const [barSize, setBarSize] = useState({ width: 72, height: 32 });
313
+ const { anchor, dismiss } = useSelectionAnchor(root, { enabled, accept, barSize });
314
+ if (!anchor) return null;
315
+ const bar = <SelectionActionBar anchor={anchor} onSize={setBarSize} actions={[citeSelectionAction(locale, anchor, root, dismiss, onCite)]} />;
316
+ return portal ? portal(bar) : bar;
317
+ }
318
+
319
+ export const QUOTE_GLYPH = <svg aria-hidden="true" width="14" height="14" viewBox="0 0 256 256" fill="currentColor"><path d="M100,56H40A16,16,0,0,0,24,72v64a16,16,0,0,0,16,16h60v8a32,32,0,0,1-32,32,8,8,0,0,0,0,16,48.05,48.05,0,0,0,48-48V72A16,16,0,0,0,100,56Zm0,80H40V72h60ZM216,56H156a16,16,0,0,0-16,16v64a16,16,0,0,0,16,16h60v8a32,32,0,0,1-32,32,8,8,0,0,0,0,16,48.05,48.05,0,0,0,48-48V72A16,16,0,0,0,216,56Zm0,80H156V72h60Z" /></svg>;
320
+ export const COMMENT_GLYPH = <svg aria-hidden="true" width="14" height="14" viewBox="0 0 256 256" fill="currentColor"><path d="M216,48H40A16,16,0,0,0,24,64V224a15.85,15.85,0,0,0,9.24,14.5A16.13,16.13,0,0,0,40,240a15.89,15.89,0,0,0,10.25-3.78l.09-.07L83,208H216a16,16,0,0,0,16-16V64A16,16,0,0,0,216,48ZM40,224h0ZM216,192H80a8,8,0,0,0-5.23,1.95L40,224V64H216ZM88,112a8,8,0,0,1,8-8h64a8,8,0,0,1,0,16H96A8,8,0,0,1,88,112Zm0,32a8,8,0,0,1,8-8h64a8,8,0,1,1,0,16H96A8,8,0,0,1,88,144Z" /></svg>;
321
+
322
+ const BAR_STYLE: React.CSSProperties = {
323
+ position: 'fixed', zIndex: 60, display: 'inline-flex', alignItems: 'center', gap: 2, padding: 3, borderRadius: 999,
324
+ background: 'hsl(var(--sidebar-background, 0 0% 7.5%))', color: 'hsl(var(--sidebar-foreground, 240 4.8% 95.9%))',
325
+ boxShadow: '0 0 0 1px rgb(255 255 255 / 0.15), 0 6px 18px rgb(0 0 0 / 0.28)', colorScheme: 'dark',
326
+ fontFamily: 'inherit', fontSize: 13, lineHeight: '18px', fontWeight: 500, whiteSpace: 'nowrap',
327
+ };
328
+
329
+ /**
330
+ * The dark labelled pill itself. It never takes focus or moves the selection (mouse down is cancelled), and it
331
+ * answers the Cite key while it shows: the first action is Cite.
332
+ */
333
+ export function SelectionActionBar({ anchor, actions, onSize }: {
334
+ anchor: Pick<SelectionAnchor, 'top' | 'left'>;
335
+ actions: SelectionBarAction[];
336
+ onSize?(size: { width: number; height: number }): void;
337
+ }) {
338
+ const bar = useRef<HTMLDivElement>(null);
339
+ const first = useRef(actions[0]);
340
+ first.current = actions[0];
341
+ const [left, setLeft] = useState(anchor.left);
342
+ // A finger needs a bigger target than the 26 px a pointer gets.
343
+ const coarse = typeof window !== 'undefined' && isCoarsePointer(window);
344
+ useLayoutEffect(() => {
345
+ const node = bar.current;
346
+ const view = node?.ownerDocument.defaultView;
347
+ if (!node || !view) { setLeft(anchor.left); return; }
348
+ const width = node.offsetWidth;
349
+ onSize?.({ width, height: node.offsetHeight });
350
+ setLeft(Math.max(GAP, Math.min(view.innerWidth - width - GAP, anchor.left)));
351
+ }, [anchor.left, anchor.top, onSize, actions.length]);
352
+ useEffect(() => {
353
+ const document = bar.current?.ownerDocument;
354
+ if (!document) return;
355
+ const onCite = (event: Event) => {
356
+ if ((event as CustomEvent<{ handled?: boolean }>).detail?.handled) return;
357
+ const detail = (event as CustomEvent<{ handled?: boolean }>).detail;
358
+ if (detail) detail.handled = true;
359
+ first.current?.onSelect();
360
+ };
361
+ document.addEventListener(CITE_SELECTION_EVENT, onCite);
362
+ return () => document.removeEventListener(CITE_SELECTION_EVENT, onCite);
363
+ }, []);
364
+ return <div ref={bar} data-notis-selection-ui role="toolbar" style={{ ...BAR_STYLE, top: anchor.top, left }}
365
+ onMouseDown={event => event.preventDefault()} onPointerDown={event => event.stopPropagation()}>
366
+ {actions.map((action, index) => <React.Fragment key={action.key}>
367
+ {index > 0 && <span aria-hidden="true" style={{ width: 1, height: 16, background: 'rgb(255 255 255 / 0.14)', margin: '0 1px' }} />}
368
+ <button type="button" title={action.title ?? action.label} onClick={action.onSelect} data-selection-action={action.key}
369
+ className="notis-selection-action"
370
+ style={{ all: 'unset', boxSizing: 'border-box', display: 'inline-flex', alignItems: 'center', gap: 6, height: coarse ? 36 : 26,
371
+ padding: coarse ? '0 14px 0 12px' : '0 11px 0 9px', borderRadius: 999, cursor: 'pointer', background: index === 0 ? 'rgb(255 255 255 / 0.08)' : undefined }}>
372
+ {action.icon}<span>{action.label}</span>
373
+ </button>
374
+ </React.Fragment>)}
375
+ </div>;
376
+ }
377
+
378
+ /** Fires the Cite key: the bar on screen cites its selection. Returns whether one did. */
379
+ export function dispatchCiteSelection(document: Document): boolean {
380
+ const detail = { handled: false };
381
+ document.dispatchEvent(new CustomEvent(CITE_SELECTION_EVENT, { detail }));
382
+ return detail.handled;
383
+ }
@@ -0,0 +1,6 @@
1
+ /** A fresh id for a quote or a comment taken from the selection. */
2
+ export function newSelectionId(): string {
3
+ return typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function'
4
+ ? crypto.randomUUID()
5
+ : `selection-${Date.now()}-${Math.random().toString(36).slice(2)}`;
6
+ }
@@ -285,6 +285,9 @@ export function useCollectionInteractions<T>(
285
285
  );
286
286
  const selectableIdsRef = useRef(selectableIds);
287
287
  selectableIdsRef.current = selectableIds;
288
+ const selectableIdSet = useMemo(() => new Set(selectableIds), [selectableIds]);
289
+ const selectableIdSetRef = useRef(selectableIdSet);
290
+ selectableIdSetRef.current = selectableIdSet;
288
291
  // The list as it was when it last held the active item: J/K from an item that left the list go on from its place.
289
292
  const activePlaceRef = useRef<{ id: string; ids: string[] } | null>(null);
290
293
  const droppedActiveIdRef = useRef<string | null>(null);
@@ -647,7 +650,7 @@ export function useCollectionInteractions<T>(
647
650
  [LEGACY_ROW_ATTRIBUTE]: id,
648
651
  tabIndex: activeIdRef.current === id || (!activeIdRef.current && selectableIdsRef.current[0] === id) ? 0 : -1,
649
652
  'aria-selected': selectedIdsRef.current.has(id),
650
- 'aria-disabled': !selectableIdsRef.current.includes(id),
653
+ 'aria-disabled': !selectableIdSetRef.current.has(id),
651
654
  'data-notis-active': (activeIdRef.current === id ? 'true' : 'false') as 'true' | 'false',
652
655
  onFocus: () => {
653
656
  activateCollectionShortcuts();
@@ -680,7 +683,7 @@ export function useCollectionInteractions<T>(
680
683
 
681
684
  const getCheckboxProps = useCallback((id: string) => ({
682
685
  isSelected: selectedIdsRef.current.has(id),
683
- disabled: !enabled || !selectableIdsRef.current.includes(id),
686
+ disabled: !enabled || !selectableIdSetRef.current.has(id),
684
687
  onClick: onCheckboxClick(id),
685
688
  }), [enabled, onCheckboxClick]);
686
689
 
@@ -205,6 +205,11 @@ export interface NotisRuntimeContext {
205
205
  resourceId?: string | null;
206
206
  /** Loading bones measured from this release at build time; `ViewSkeleton` draws them. Absent until the host has them. */
207
207
  readonly skeleton?: NotisSpaceSkeleton;
208
+ /**
209
+ * The signed-in viewer's first name, for signing what they write (comments). Display only, never an identity
210
+ * or a permission. Absent for visitors of a Site or a link, and on hosts that predate it.
211
+ */
212
+ readonly viewerName?: string | null;
208
213
  }
209
214
 
210
215
  // ---------------------------------------------------------------------------
@@ -537,6 +537,10 @@ export interface SpaceDefinition {
537
537
  * moment, once that person allowed this Space's agents. Agents' own writes never wake anything.
538
538
  */
539
539
  agents?: SpaceAgentDeclaration[];
540
+ /**
541
+ * Lists the database's records as sidebar rows under this Space. Only for a short list people navigate
542
+ * like pages (folders, chapters); a database that keeps growing belongs in the view's `shows` instead.
543
+ */
540
544
  collection?: { database: string; titleProperty: string; parentProperty?: string; allowCreate?: boolean };
541
545
  /** Reproducible source dependencies not discovered by the module graph. */
542
546
  sourceIncludes?: string[];
@@ -74,10 +74,19 @@ export function hasIcon(name: string): boolean {
74
74
  return Object.prototype.hasOwnProperty.call(SHAPES, name);
75
75
  }
76
76
 
77
- /** A built-in icon by name; an unknown name renders nothing. Decorative: the control carries the label. */
77
+ const warned = new Set<string>();
78
+
79
+ /** Names the set lacks, warned once each: an unknown name renders nothing, so a typo would otherwise go unseen. */
80
+ function warnUnknown(name: string): void {
81
+ if (warned.has(name) || typeof console === 'undefined') return;
82
+ warned.add(name);
83
+ console.warn(`[notis/ui] Unknown icon "${name}": it renders nothing. Use a name from the toolkit set (${Object.keys(SHAPES).length} icons, listed in the design system) or pass a Phosphor component.`);
84
+ }
85
+
86
+ /** A built-in icon by name; an unknown name renders nothing and warns once. Decorative: the control carries the label. */
78
87
  export function Icon({ name, className }: { name: string; className?: string }) {
79
88
  const shape = SHAPES[name];
80
- if (!shape) return null;
89
+ if (!shape) { warnUnknown(name); return null; }
81
90
  return (
82
91
  <svg className={className ? `nui-icon ${className}` : 'nui-icon'} viewBox="0 0 16 16" aria-hidden="true" focusable="false">
83
92
  {shape}
@@ -67,7 +67,15 @@ export class ActionError extends Error {
67
67
  /** The reason an ActionError carries, else null. A Space bundles its own copy of the words, so this reads the shape. */
68
68
  export function actionErrorReason(error: unknown): Words | string | null {
69
69
  if (!error || typeof error !== 'object') return null;
70
- const { name, code, reason } = error as { name?: unknown; code?: unknown; reason?: unknown };
70
+ const { name, code, reason, status } = error as { name?: unknown; code?: unknown; reason?: unknown; status?: unknown };
71
+ // A confirmed host refusal can explain how to unblock the action. These words are
72
+ // ours: never display an arbitrary Space/server error's message as a toast reason.
73
+ if (name === 'SpaceActionError' && code === 'document_has_spaces' && status === 'refused') {
74
+ return {
75
+ en: 'This document is used by a Space. Move or trash its linked Spaces first.',
76
+ fr: 'Ce document est utilisé par un Space. Déplace ou mets à la corbeille ses Spaces liés d’abord.',
77
+ };
78
+ }
71
79
  if (name !== 'ActionError' || code !== 'notis_action_error') return null;
72
80
  return typeof reason === 'string' || isWords(reason) ? reason : null;
73
81
  }
@@ -52,6 +52,9 @@ export const DEFAULT_KEYMAP = Object.freeze({
52
52
  'host.search': entry('host.search', ['/'], 'app', 'Search', 'Rechercher', { host: true }),
53
53
  'host.newChat': entry('host.newChat', ['c'], 'app', 'New conversation', 'Nouvelle conversation', { host: true }),
54
54
  'host.call': entry('host.call', ['shift+c'], 'app', 'Open voice call', 'Ouvrir l’appel vocal', { host: true }),
55
+ // Cites the selected text in chat, like the Cite button on the selection (truth PRT-089).
56
+ 'host.cite': entry('host.cite', ['mod+shift+c'], 'app', 'Cite selected text in chat', 'Citer le texte sélectionné dans le chat',
57
+ { host: true }),
55
58
  'host.toggleSidebar': entry('host.toggleSidebar', ['mod+s'], 'app', 'Toggle sidebar',
56
59
  'Afficher ou masquer la barre latérale', { host: true }),
57
60
  'host.voiceMessage': entry('host.voiceMessage', ['mod+d'], 'app', 'Voice message', 'Message vocal', { host: true }),