@notis_ai/cli 0.2.28 → 0.2.30
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.
- package/README.md +25 -8
- package/dist/agent-hooks/notis-agent-hook.mjs +1476 -712
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/SKILL.md +11 -0
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/references/release.md +6 -5
- package/dist/base-skills/notis-spaces/references/sdk.md +86 -14
- package/dist/sdk/src/components/NotisCommentBoundary.tsx +29 -96
- package/dist/sdk/src/components/NotisSelectionBoundary.tsx +3 -8
- package/dist/sdk/src/components/SelectionActionBar.tsx +144 -23
- package/dist/sdk/src/components/selectionId.ts +6 -0
- package/dist/sdk/src/hooks/useThreadItem.ts +56 -0
- package/dist/sdk/src/index.ts +6 -1
- package/dist/sdk/src/runtime.ts +13 -1
- package/dist/sdk/src/space.ts +230 -0
- package/dist/skill-sync-worker.mjs +185 -30
- package/dist/space-harness/host.js +260 -114
- package/dist/space-sdk/dist/{chunk-BFGB6XXC.js → chunk-6GJ2BS7B.js} +1 -3
- package/dist/space-sdk/dist/index.js +4 -2
- package/dist/space-sdk/dist/ui.js +19 -14
- package/dist/space-sdk/src/components/NotisCommentBoundary.d.ts +0 -10
- package/dist/space-sdk/src/hooks/useThreadItem.d.ts +28 -0
- package/dist/space-sdk/src/index.d.ts +3 -1
- package/dist/space-sdk/src/runtime.d.ts +13 -1
- package/dist/space-sdk/src/space.ts +230 -0
- package/dist/space-sdk/src/tailwind-candidates.d.ts +505 -22
- package/dist/space-sdk/src/ui/actions/useToast.d.ts +2 -0
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +56 -10
- package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +16 -7
- package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +59 -0
- package/dist/space-sdk/src/ui/comments/commentFiles.d.ts +5 -2
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +103 -8
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +82 -0
- package/dist/space-sdk/src/ui/comments/hostComments.d.ts +37 -0
- package/dist/space-sdk/src/ui/comments/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/comments/paneParts.d.ts +119 -0
- package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +75 -0
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +165 -15
- package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +24 -8
- package/dist/space-sdk/src/ui/index.d.ts +2 -1
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +6 -1
- package/dist/space-sdk/src/ui/overlay/Tooltip.d.ts +8 -2
- package/dist/space-sdk/src/ui/styles.d.ts +27 -5
- package/dist/view-renderer/dist/host.js +330 -184
- package/dist/view-renderer/src/host.tsx +6 -3
- package/dist/view-renderer/src/renderer.js +62 -3
- package/package.json +3 -3
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -1
- package/skills/notis-spaces/cli.md +8 -8
- package/src/cli.js +10 -2
- package/src/command-specs/computer.js +21 -1
- package/src/command-specs/profile.js +12 -5
- package/src/command-specs/spaces.js +57 -23
- package/src/command-specs/tools.js +1 -1
- package/src/runtime/agent-identity.js +187 -0
- package/src/runtime/api-hosts.js +92 -0
- package/src/runtime/app-platform.js +74 -11
- package/src/runtime/channel.js +3 -7
- package/src/runtime/oauth.js +95 -4
- package/src/runtime/profiles.js +200 -41
- package/src/runtime/skill-sync-service.js +4 -5
- package/src/runtime/space-fixture-broker.js +23 -2
- package/src/runtime/space-platform.js +2 -0
- package/src/runtime/space-source.js +66 -1
- package/src/runtime/space-test-server.js +20 -4
- package/src/runtime/space-verification.js +66 -10
- package/src/runtime/telemetry.js +14 -1
- package/src/runtime/transport.js +12 -0
- package/src/runtime/upsell.js +3 -6
- package/src/runtime/view-render.js +3 -1
- package/src/skill-sync-worker.js +13 -2
- package/src/space-harness-host.ts +6 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"schema":1,"stamp":
|
|
1
|
+
{"schema":1,"stamp":1794658649,"commit":"c85c7d62766a6561de18ec338247843d089cadae"}
|
|
@@ -57,6 +57,17 @@ Two rules follow from the dev credential being scoped to that local backend:
|
|
|
57
57
|
- A `dev-*` profile only exists while its `./dev.sh` lease is running. If it is stopped, the CLI fails with `dev_runtime_unavailable` instead of sending the test user's token to the live API.
|
|
58
58
|
- To reach a real account from inside a worktree — including when the local backend is wedged — name a real profile explicitly: `notis --profile <name> ...`. That is the supported escape hatch.
|
|
59
59
|
|
|
60
|
+
## Declare who you are before writing
|
|
61
|
+
|
|
62
|
+
When you are an agent (Claude Code, Codex, a script) and not the person typing, name yourself so what you write is yours, not the person's: a comment then shows your name as its author, never counts as the person's comment and never wakes you up. Pick a fresh lowercase imaginary rock-band name (lowercase letters and digits in at least two words joined by hyphens, 3 to 60 characters, such as `fred-and-the-machine`, shown as "Fred And The Machine") and set it once per session:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
export NOTIS_AGENT_NAME="fred-and-the-machine" # your band name
|
|
66
|
+
export NOTIS_AGENT_THREAD="<Notis thread id>" # optional
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
or pass `--agent-name` and `--agent-thread` on a single command (a flag wins over its variable). The CLI generates one id for each name the first time it is used on the computer and keeps sending it, so you edit or delete only your own comments; set `NOTIS_AGENT_ID` (or `--agent-id`) only to override it. Name a Notis thread only when you work for one of the person's Notis threads: replies to your comments then wake that thread; anything else is kept as a label. Declarations take effect where the person has unified comments on (being rolled out); elsewhere Notis ignores them and writes count as the person's, as before. With unified comments on, every comment written through the CLI needs the name, even one the person types: without it the write is refused (`agent_name_required`), and a name sent without an id is refused too (`agent_id_required`). Other writes with the person's own sign-in and no name are the person's. A name that breaks the rule is sent as written and the server refuses the call (`invalid_agent_identity`) where unified comments are on, reads included; elsewhere it is ignored. A declaration names you; it never gives access to anything more. The Notis assistant itself never writes comments (`orchestrator_comments_refused`): it starts a sub-agent for comment work, signed with that sub-agent's band name.
|
|
70
|
+
|
|
60
71
|
## Critical rule for missing tools
|
|
61
72
|
|
|
62
73
|
If the tool you need is not already available in your current tool surface, do not stop and do not assume the task is blocked.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"schema":1,"stamp":
|
|
1
|
+
{"schema":1,"stamp":1794658649,"commit":"c85c7d62766a6561de18ec338247843d089cadae"}
|
|
@@ -18,9 +18,11 @@ Ordinary data and resource edits apply immediately; only source needs a release.
|
|
|
18
18
|
`.notis/space-lock.json`, resources, source key and current revisions. Never
|
|
19
19
|
silently advance a stale checkout or create a duplicate to avoid a conflict.
|
|
20
20
|
2. **Build.** Edit the selected definition, its view and linked Skill files.
|
|
21
|
-
Run `spaces build <dir
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
Run `spaces build <dir>`; it freezes source and artifact bytes and validates
|
|
22
|
+
the view contract and design. A pulled folder holds one Space; a workspace
|
|
23
|
+
with several needs `--space <key>` on build, verify and deploy.
|
|
24
|
+
3. **Verify.** Run `spaces verify <dir>`. A pulled folder targets the Space it
|
|
25
|
+
was pulled from; anything else needs `--space-id <space-id>`.
|
|
24
26
|
This checks current action authorizations and renders explicit fictional
|
|
25
27
|
fixtures at 390px and 1440px with the shared read-only renderer. Provide exact
|
|
26
28
|
action/list/body/record fixtures. A denied read, write-on-load or failed width
|
|
@@ -28,8 +30,7 @@ Ordinary data and resource edits apply immediately; only source needs a release.
|
|
|
28
30
|
Missing browser tooling blocks release: install `agent-browser` and make it
|
|
29
31
|
available on PATH.
|
|
30
32
|
4. **Publish source.** Deploy the frozen, verified snapshot, not edits made after
|
|
31
|
-
verification: `spaces deploy <dir> --
|
|
32
|
-
--request-id <stable-id>`. Or `spaces preview` seals a candidate, and
|
|
33
|
+
verification: `spaces deploy <dir> --request-id <stable-id>`. Or `spaces preview` seals a candidate, and
|
|
33
34
|
`spaces promote <release-id> <dir>` publishes that exact candidate. Preview
|
|
34
35
|
authoring never silently gains live record-edit authority. Deployment updates
|
|
35
36
|
the selected Space, not siblings or the Store.
|
|
@@ -32,10 +32,13 @@ Text a person writes and reviews:
|
|
|
32
32
|
- Comments on selected words of a text property (a Markdown body, a subject)
|
|
33
33
|
come from `@notis/sdk/ui`: `usePassageComments` with `CommentableText` around
|
|
34
34
|
an input or textarea, `CommentableRichText` around the `MarkdownEditor` or
|
|
35
|
-
rendered Markdown, and
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
rendered Markdown, and `<PassageCommentPane comments={comments} />` mounted
|
|
36
|
+
once anywhere in the view (it draws in the host Comments panel, never in a
|
|
37
|
+
`SidePane`). The Comments database needs Field, Quote, Prefix and Suffix
|
|
38
|
+
columns; a thread whose words are gone reads Passage changed and stays open.
|
|
39
|
+
It lists newest first; pass `order="reading"` to list the text's threads in
|
|
40
|
+
reading order. Do not build your own highlights. Pins on a page use
|
|
41
|
+
`useComments` with `CommentPane` (see [Comments](#comments)).
|
|
39
42
|
|
|
40
43
|
## Toolkit pieces
|
|
41
44
|
|
|
@@ -122,16 +125,8 @@ rather than from a copy.
|
|
|
122
125
|
button, `viewerActions` adds viewer buttons (class `nui-viewer-btn`) and
|
|
123
126
|
`onNotice` hears copy and download results. Use `ImageViewer` alone for a
|
|
124
127
|
picture that opens full screen. Do not build your own lightbox.
|
|
125
|
-
- **Comments**: `useComments` with `CommentPane` and `CommentPins` give
|
|
126
|
-
threads on a Comments database (
|
|
127
|
-
changes). For comments on a whole record with nothing to pin on, pass no
|
|
128
|
-
`anchors` and `columns.anchor: null`: the pane offers New comment itself.
|
|
129
|
-
To let people attach pictures and files to a comment or a reply
|
|
130
|
-
(paste, drop or the paperclip), give the Comments database a files column
|
|
131
|
-
named `Attachments` (or pass `columns.attachments`); there is nothing to add
|
|
132
|
-
in the view. Without the column the pane takes text only. Files open from
|
|
133
|
-
the rows for an hour, for whoever may read the row; an agent downloads one
|
|
134
|
-
from the `url` its query returns, or queries again for a fresh one.
|
|
128
|
+
- **Comments**: `useComments` with `CommentPane` and `CommentPins` give comment
|
|
129
|
+
threads on a Comments database; see [Comments](#comments).
|
|
135
130
|
- **Presenting on a second screen**: `useAudienceScreen({ onAction, onClose,
|
|
136
131
|
title })` works like PowerPoint. `secondScreen` says whether another screen
|
|
137
132
|
is connected; call `open(anchor)` from the Present press itself. It answers
|
|
@@ -183,6 +178,75 @@ A status maps to one of ten groups (`backlog`, `todo`, `active`, `review`,
|
|
|
183
178
|
with its icon, words and the one status palette: pass the Space's own status to
|
|
184
179
|
`Row` or `StatusIcon` (with `label` for its own name).
|
|
185
180
|
|
|
181
|
+
## Comments
|
|
182
|
+
|
|
183
|
+
`useComments` with `CommentPane` and `CommentPins` give comment
|
|
184
|
+
threads on a Comments database (pins, zones, replies, asks, Archive, Delete,
|
|
185
|
+
Edit, Copy changes). The pane draws in the host Comments panel beside the
|
|
186
|
+
chat, not where it is mounted: mount `<CommentPane controller={comments} />`
|
|
187
|
+
once anywhere in the view and never wrap it in `SidePane` (a `SidePane` given
|
|
188
|
+
a comment pane shows its page alone). While comments are off for the viewer,
|
|
189
|
+
or on a Site, a link or a preview, the pane, pins and tool bar render nothing:
|
|
190
|
+
never build a fallback comment list. The host owns archive (Status
|
|
191
|
+
`Resolved`, shown Done), delete with Undo, editing your own comment, the
|
|
192
|
+
Open/Done/All filter, the Goes to line and To chip that name the thread a
|
|
193
|
+
comment goes to, `comment=` links and push; the server checks who may change
|
|
194
|
+
a comment and writes `Author` itself (the person's name, or the agent's on
|
|
195
|
+
an agent's comment, adding the select choice when it is missing), so never
|
|
196
|
+
set `Author` from the view or let people pick it. On someone else's comment
|
|
197
|
+
people only archive, reopen, delete (with edit rights) or answer it: every
|
|
198
|
+
other column is its author's, and agents change only what they wrote. Every
|
|
199
|
+
Comments table is followed for waiting comments and push, with or without
|
|
200
|
+
`agents`, and a person's comments, replies and answers go to the thread they
|
|
201
|
+
name even in a Space that declares no `agents`: an answer, or a reply in a
|
|
202
|
+
thread an agent started, goes back to that agent's own thread and subagent,
|
|
203
|
+
and editing a comment wakes an agent only when it replied after the comment.
|
|
204
|
+
A reply under a deleted comment is refused (`comment_not_found`). Every
|
|
205
|
+
comment written through the Notis CLI needs the writing agent's band name
|
|
206
|
+
(`NOTIS_AGENT_NAME` or `--agent-name`, such as `fred-and-the-machine`; the
|
|
207
|
+
rule and the id the CLI keeps per name are in the notis-cli skill): the
|
|
208
|
+
comment is then that agent's, signed "Fred And The Machine", and never wakes
|
|
209
|
+
it. Without a name it is refused (`agent_name_required`), even for a person
|
|
210
|
+
typing the CLI, and a view never writes comments with a Cloud Computer
|
|
211
|
+
credential. The Notis assistant never writes comments itself
|
|
212
|
+
(`orchestrator_comments_refused`): it starts a sub-agent for comment work,
|
|
213
|
+
which signs with its own band name. On a host without the Comments panel a
|
|
214
|
+
comment is signed with the viewer's first name; when the Comments
|
|
215
|
+
database's Author is a choice list, give it a `Person` option, which signs
|
|
216
|
+
anyone it does not name (without it the comment saves with no author). Pass
|
|
217
|
+
`me` only to sign with a fixed name. For comments on a whole record with
|
|
218
|
+
nothing to pin on, pass no `anchors` and `columns.anchor: null`: the pane
|
|
219
|
+
offers New comment itself.
|
|
220
|
+
|
|
221
|
+
Options:
|
|
222
|
+
- `order` on the pane: `'newest'` (default), `'oldest'`, `'anchor'` or a
|
|
223
|
+
comparator. `groupBy`: a function returning `{ key, label }` per thread,
|
|
224
|
+
or false. A controller with no `scope` (the Space home) groups by page,
|
|
225
|
+
named by `scopeNames` on `useComments`; a scoped one is flat.
|
|
226
|
+
- `modes` on `useComments`: any of `text`, `point`, `box`, `items`, `time`,
|
|
227
|
+
`page` (listed in that order). Default: `point` (plus `box` with zone
|
|
228
|
+
columns) when there are anchors, `items` when you pass `onStartItems`,
|
|
229
|
+
`time` when you pass `currentTime`, and `page`. The pane's New comment
|
|
230
|
+
button lists them; `<CommentToolBar controller={comments} />` puts one
|
|
231
|
+
button per mode on the page, toggled with C (`toggleKey`, or `pinned` to
|
|
232
|
+
keep it shown), and Escape cancels a mode.
|
|
233
|
+
- `onStartItems()`: show your own picker (checkboxes, a selection), then call
|
|
234
|
+
`comments.startItems(anchors)`. `currentTime()`: the recording's moment in
|
|
235
|
+
seconds; name a Time column with `columns: { time: 'Time' }` to store it.
|
|
236
|
+
- `focusKey` defaults to the `comment` view param, so a link with
|
|
237
|
+
`comment=<root key>` opens that thread; null turns it off. Give the table
|
|
238
|
+
an `Edited at` date column so edited comments say edited, and an
|
|
239
|
+
`Answer to` text column so an answer to an agent's question reaches only
|
|
240
|
+
the agent that asked (the server adds it to an existing table on the first
|
|
241
|
+
answer, so there is nothing to do by hand).
|
|
242
|
+
|
|
243
|
+
To let people attach pictures and files to a comment or a reply
|
|
244
|
+
(paste, drop or the paperclip), give the Comments database a files column
|
|
245
|
+
named `Attachments` (or pass `columns.attachments`); there is nothing to add
|
|
246
|
+
in the view. Without the column the pane takes text only. Files open from
|
|
247
|
+
the rows for an hour, for whoever may read the row; an agent downloads one
|
|
248
|
+
from the `url` its query returns, or queries again for a fresh one.
|
|
249
|
+
|
|
186
250
|
## Records and declared reads
|
|
187
251
|
|
|
188
252
|
| API | Use |
|
|
@@ -205,6 +269,10 @@ said in the Space's language, default Loading content. Its shapes are
|
|
|
205
269
|
measured from the view at verify time and drawn from the release; `skeletonKey`
|
|
206
270
|
(default `main`) names the region when a view has several separately loading
|
|
207
271
|
parts, and `variant` only draws the fallback before the first measured release.
|
|
272
|
+
A region that only shows on another tab or page is measured when the
|
|
273
|
+
verification fixtures list that tab's params in `context.skeletonParams`. A Space
|
|
274
|
+
with editor-only parts gets the skeleton of its public view, the one visitors
|
|
275
|
+
see: an editors' page that loads differently keeps a plain loading state of its own.
|
|
208
276
|
|
|
209
277
|
For another explicitly idempotent read use `useActionQuery`, or
|
|
210
278
|
`useQuery(keyArray, readCallback, { readOnly: true })` with every input in the
|
|
@@ -244,6 +312,10 @@ in component props.
|
|
|
244
312
|
once the host has taken the navigation and rejects when the host refuses it:
|
|
245
313
|
`await` it (or `void` it in a click handler). Prefer declared portable navigation
|
|
246
314
|
aliases for sibling destinations; the host resolves them under current access.
|
|
315
|
+
Declare each alias in `navigation`, then bind it once per Space with
|
|
316
|
+
`notis spaces navigation bind <space-id> --alias <name> --target '{"space_id":"<id>"}' --revision <n>`
|
|
317
|
+
before you deploy: a binding takes effect at the next deploy, and an unbound name
|
|
318
|
+
fails verify with `navigation_unavailable`.
|
|
247
319
|
Use declared params for view state, for example `{params: {project: key, period: 'week'}}`.
|
|
248
320
|
The destination drops unknown params and authorizes referenced records. Changing
|
|
249
321
|
a slug cannot change identity. Agents cite current server-returned links.
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { useRef, useState, type CSSProperties, type ReactNode } from 'react';
|
|
3
3
|
import type { ContextResource } from '../runtime';
|
|
4
4
|
import { NotisSelectionBoundary, quoteResourceFor } from './NotisSelectionBoundary';
|
|
5
5
|
import { useAgentContext } from '../hooks/useAgentContext';
|
|
6
6
|
import { useNotisRuntime } from '../provider';
|
|
7
|
-
import { COMMENT_GLYPH,
|
|
7
|
+
import { COMMENT_GLYPH, SELECTION_BAR_WORDS, SelectionActionBar, citeSelectionAction, useSelectionAnchor } from './SelectionActionBar';
|
|
8
|
+
import { newSelectionId } from './selectionId';
|
|
8
9
|
import { useToolkitLocale } from '../ui/engine/hooks';
|
|
9
10
|
|
|
10
11
|
export interface NotisCommentBoxProps {
|
|
@@ -51,20 +52,6 @@ export interface NotisCommentBoundaryProps {
|
|
|
51
52
|
renderComment?: (props: NotisCommentBoxProps) => ReactNode;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
type SelectionRect = Pick<DOMRect, 'left' | 'right' | 'top' | 'bottom'>;
|
|
55
|
-
|
|
56
|
-
/** Place the tile after the final selected line, otherwise below (or above near the viewport bottom). */
|
|
57
|
-
export function getCommentActionPosition(rects: SelectionRect[], viewport: { width: number; height: number }, rightBoundary = viewport.width, trailing: SelectionRect[] = []) {
|
|
58
|
-
const last = rects[rects.length - 1];
|
|
59
|
-
const size = 32, gap = 8;
|
|
60
|
-
const clampX = (x: number) => Math.max(gap, Math.min(viewport.width - size - gap, x));
|
|
61
|
-
const clampY = (y: number) => Math.max(gap, Math.min(viewport.height - size - gap, y));
|
|
62
|
-
const beside = { left: last.right + gap, top: clampY((last.top + last.bottom - size) / 2) };
|
|
63
|
-
const overlapsText = trailing.some(rect => rect.left < beside.left + size && rect.right > beside.left && rect.top < beside.top + size && rect.bottom > beside.top);
|
|
64
|
-
if (beside.left + size <= Math.min(viewport.width, rightBoundary) - gap && !overlapsText) return beside;
|
|
65
|
-
return { left: clampX(last.right - size), top: clampY(last.bottom + gap + size <= viewport.height - gap ? last.bottom + gap : last.top - size - gap) };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
55
|
/** Browser paragraph selection may include an adjacent block's empty starting boundary. */
|
|
69
56
|
export function getOwnedCommentRange(selected: Range, content: Element): Range | null {
|
|
70
57
|
const owned = content.ownerDocument.createRange();
|
|
@@ -94,105 +81,51 @@ export function NotisCommentBoundary({ resource, children, className, commentCla
|
|
|
94
81
|
// A host without a chat (a public Site) offers Comment alone: Cite would have nowhere to go.
|
|
95
82
|
const canCite = Boolean(useNotisRuntime()?.addContext);
|
|
96
83
|
const root = useRef<HTMLDivElement>(null);
|
|
97
|
-
const [selection, setSelection] = useState<{ id: string; text: string; resource?: ContextResource | null; range: Range; top: number; left: number } | null>(null);
|
|
98
84
|
const locale = useToolkitLocale();
|
|
99
85
|
const [barSize, setBarSize] = useState({ width: 176, height: 32 });
|
|
100
|
-
|
|
101
|
-
const
|
|
86
|
+
// The quote being commented on, frozen when the editor opens: typing moves the browser selection into the editor.
|
|
87
|
+
const [editing, setEditing] = useState<{ id: string; text: string; resource: ContextResource | null; top: number; left: number } | null>(null);
|
|
102
88
|
const [comment, setComment] = useState('');
|
|
103
89
|
const [pending, setPending] = useState(false);
|
|
104
90
|
const [error, setError] = useState('');
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// A touch selection has no mouse up: show the bar once its handles stop moving (truth PRT-094).
|
|
119
|
-
if (document.defaultView?.matchMedia?.('(pointer: coarse)').matches) {
|
|
120
|
-
document.defaultView.clearTimeout(touchSettle.current);
|
|
121
|
-
touchSettle.current = document.defaultView.setTimeout(() => captureRef.current(null), 450);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
document.addEventListener('selectionchange', clearInvalidSelection);
|
|
125
|
-
if (scope !== (document as unknown as ShadowRoot)) scope.addEventListener('selectionchange', clearInvalidSelection);
|
|
126
|
-
return () => {
|
|
127
|
-
document.removeEventListener('selectionchange', clearInvalidSelection);
|
|
128
|
-
if (scope !== (document as unknown as ShadowRoot)) scope.removeEventListener('selectionchange', clearInvalidSelection);
|
|
129
|
-
};
|
|
130
|
-
}, []);
|
|
131
|
-
const open = () => { editingRef.current = true; setEditing(true); };
|
|
132
|
-
const touchSettle = useRef<number | undefined>(undefined);
|
|
133
|
-
const captureRef = useRef<(target: EventTarget | null) => void>(() => {});
|
|
134
|
-
const capture = (target: EventTarget | null) => {
|
|
135
|
-
// Clicking the action/editor must not unmount it before its click runs.
|
|
136
|
-
if (editing || (target instanceof Element && target.closest('[data-notis-comment-ui],[data-notis-selection-ui]'))) return;
|
|
137
|
-
const node = root.current;
|
|
138
|
-
const scope = node?.getRootNode() as ShadowRoot & { getSelection?: () => Selection | null };
|
|
139
|
-
const selected = scope?.getSelection?.() || window.getSelection();
|
|
140
|
-
if (!node || !selected?.rangeCount || selected.isCollapsed) { setSelection(null); return; }
|
|
141
|
-
const content = node.firstElementChild;
|
|
142
|
-
const range = content ? getOwnedCommentRange(selected.getRangeAt(0), content) : null;
|
|
143
|
-
if (!range) { setSelection(null); return; }
|
|
144
|
-
const start = range.startContainer.nodeType === Node.ELEMENT_NODE ? range.startContainer as Element : range.startContainer.parentElement;
|
|
145
|
-
const end = range.endContainer.nodeType === Node.ELEMENT_NODE ? range.endContainer as Element : range.endContainer.parentElement;
|
|
146
|
-
if (!node.contains(range.startContainer) || !node.contains(range.endContainer)
|
|
147
|
-
|| start?.closest('input,textarea,button,[contenteditable],[data-notis-comment-ui]')
|
|
148
|
-
|| end?.closest('input,textarea,button,[contenteditable],[data-notis-comment-ui]')) { setSelection(null); return; }
|
|
149
|
-
const rect = range.getBoundingClientRect();
|
|
150
|
-
const lines = Array.from(range.getClientRects?.() || []).filter(line => line.width > 0 && line.height > 0);
|
|
151
|
-
const boundary = node.firstElementChild?.getBoundingClientRect();
|
|
152
|
-
const trailing: DOMRect[] = [];
|
|
153
|
-
const endBlock = end?.closest('p,li,h1,h2,h3,h4,h5,h6,td,th,div');
|
|
154
|
-
if (endBlock && node.contains(endBlock)) {
|
|
155
|
-
const remainder = range.cloneRange();
|
|
156
|
-
remainder.selectNodeContents(endBlock);
|
|
157
|
-
remainder.setStart(range.endContainer, range.endOffset);
|
|
158
|
-
trailing.push(...Array.from(remainder.getClientRects?.() || []).filter(line => line.width > 0 && line.height > 0));
|
|
159
|
-
}
|
|
160
|
-
// The bar (Cite, then Comment) sits where the old Comment tile did: after the last line, or below it.
|
|
161
|
-
const position = getSelectionBarPosition(lines.length ? lines : [rect], { width: window.innerWidth, height: window.innerHeight }, barSize,
|
|
162
|
-
{ rightBoundary: boundary?.width ? boundary.right : window.innerWidth, trailing, coarse: window.matchMedia?.('(pointer: coarse)').matches });
|
|
163
|
-
setSelection({ id: crypto.randomUUID(), text: selected.toString().trim(), resource: resource ? JSON.parse(JSON.stringify(resource)) : null, range: range.cloneRange(), ...position });
|
|
91
|
+
// The same bar placement as every quoting surface; a selection spilling over the boundary only by whitespace is
|
|
92
|
+
// clipped to it, and one that takes a neighbour's words is refused.
|
|
93
|
+
const { anchor, dismiss } = useSelectionAnchor(root, {
|
|
94
|
+
enabled: !editing,
|
|
95
|
+
barSize,
|
|
96
|
+
clip: (range, node) => node.firstElementChild ? getOwnedCommentRange(range, node.firstElementChild) : null,
|
|
97
|
+
// A comment boundary never quotes a selection that starts or ends on a button, as before the shared bar.
|
|
98
|
+
exclude: 'button',
|
|
99
|
+
});
|
|
100
|
+
const ownResource = () => resource ? JSON.parse(JSON.stringify(resource)) as ContextResource : null;
|
|
101
|
+
const open = () => {
|
|
102
|
+
if (!anchor) return;
|
|
103
|
+
setEditing({ id: newSelectionId(), text: anchor.text, resource: ownResource(), top: anchor.top, left: anchor.left });
|
|
164
104
|
};
|
|
165
|
-
|
|
166
|
-
// Once the bar measured itself, place it again with its real width.
|
|
167
|
-
useEffect(() => { if (!editingRef.current) captureRef.current(null); }, [barSize.width, barSize.height]);
|
|
168
|
-
const close = () => { editingRef.current = false; setEditing(false); setSelection(null); setComment(''); setError(''); };
|
|
105
|
+
const close = () => { setEditing(null); dismiss(); setComment(''); setError(''); };
|
|
169
106
|
const submit = async () => {
|
|
170
|
-
if (!
|
|
107
|
+
if (!editing || !comment.trim() || pending) return;
|
|
171
108
|
setPending(true); setError('');
|
|
172
109
|
try {
|
|
173
|
-
const added = await context.add({ id:
|
|
110
|
+
const added = await context.add({ id: editing.id, kind: 'comment', title: editing.resource?.label || 'Comment', icon: 'phosphor:chat-text', text: editing.text, comment, resource: editing.resource });
|
|
174
111
|
if (!added) throw new Error('The comment could not be added to chat.');
|
|
175
112
|
close();
|
|
176
113
|
} catch (reason) { setError(reason instanceof Error ? reason.message : 'Could not add this comment.'); }
|
|
177
114
|
finally { setPending(false); }
|
|
178
115
|
};
|
|
179
|
-
const cite = async () => {
|
|
180
|
-
if (!selection) return;
|
|
181
|
-
const quoted = selection;
|
|
182
|
-
clearSelectionIn(root.current);
|
|
183
|
-
setSelection(null);
|
|
116
|
+
const cite = async (range: Range, text: string) => {
|
|
184
117
|
// The quote copy would make: the innermost boundary's resource, else this boundary's.
|
|
185
|
-
const named = quoteResourceFor(
|
|
186
|
-
try { await context.add({ id:
|
|
118
|
+
const named = quoteResourceFor(range) ?? ownResource();
|
|
119
|
+
try { await context.add({ id: newSelectionId(), text, ...(named ? { resource: named } : {}) }); } catch { /* No chat in this host: copy still quotes. */ }
|
|
187
120
|
};
|
|
188
|
-
const editorProps: NotisCommentBoxProps = { quote:
|
|
189
|
-
return <div ref={root} className="contents" data-notis-comment-boundary
|
|
121
|
+
const editorProps: NotisCommentBoxProps = { quote: editing?.text, value: comment, onChange: setComment, onSubmit: () => void submit(), onCancel: close, pending, error, className: commentClassName };
|
|
122
|
+
return <div ref={root} className="contents" data-notis-comment-boundary>
|
|
190
123
|
<NotisSelectionBoundary resource={resource} className={className} style={className ? undefined : { display: 'contents' }}>{children}</NotisSelectionBoundary>
|
|
191
|
-
{
|
|
192
|
-
...(canCite ? [
|
|
124
|
+
{anchor && !editing && <SelectionActionBar anchor={anchor} onSize={setBarSize} actions={[
|
|
125
|
+
...(canCite ? [citeSelectionAction(locale, anchor, root, dismiss, (range, text) => void cite(range, text))] : []),
|
|
193
126
|
{ key: 'comment', label: SELECTION_BAR_WORDS.comment[locale], icon: COMMENT_GLYPH, onSelect: open },
|
|
194
127
|
]} />}
|
|
195
|
-
{
|
|
128
|
+
{editing && <div data-notis-comment-ui className="fixed z-50 max-h-[calc(100dvh-1rem)]" style={{ overflow: 'auto', top: Math.min(editing.top, Math.max(8, window.innerHeight - 320)), left: `clamp(8px, ${editing.left}px, calc(100vw - min(20rem, calc(100vw - 1rem)) - 8px))`, width: 'min(20rem, calc(100vw - 1rem))' } as CSSProperties}>
|
|
196
129
|
{renderComment ? renderComment(editorProps) : <NotisCommentBox {...editorProps} />}
|
|
197
130
|
</div>}
|
|
198
131
|
</div>;
|
|
@@ -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:
|
|
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);
|
|
@@ -132,7 +127,7 @@ export function citeSpaceSelection(runtime: Pick<NotisRuntime, 'contextSource' |
|
|
|
132
127
|
const resource = quoteResourceFor(range);
|
|
133
128
|
const source = runtime.contextSource;
|
|
134
129
|
return runtime.addContext({
|
|
135
|
-
id:
|
|
130
|
+
id: newSelectionId(), text,
|
|
136
131
|
...(resource ? { resource } : source ? { title: source.appName } : {}),
|
|
137
132
|
});
|
|
138
133
|
}
|