@openartifactsai/editor-kit 0.0.0-stage → 0.23.0-rc.0

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 (120) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +143 -2
  4. package/package.json +67 -4
  5. package/src/Announcer.d.ts +2 -0
  6. package/src/Announcer.js +8 -0
  7. package/src/FindBar.d.ts +31 -0
  8. package/src/FindBar.js +37 -0
  9. package/src/FoldToolbar.d.ts +58 -0
  10. package/src/FoldToolbar.js +438 -0
  11. package/src/PanelEdge.d.ts +20 -0
  12. package/src/PanelEdge.js +74 -0
  13. package/src/VideoShrinkNotice.d.ts +10 -0
  14. package/src/VideoShrinkNotice.js +81 -0
  15. package/src/WheelZoomItem.d.ts +12 -0
  16. package/src/WheelZoomItem.js +18 -0
  17. package/src/agent.d.ts +68 -0
  18. package/src/agent.js +113 -0
  19. package/src/announce.d.ts +21 -0
  20. package/src/announce.js +31 -0
  21. package/src/chrome.d.ts +208 -0
  22. package/src/chrome.js +148 -0
  23. package/src/clipboard.d.ts +19 -0
  24. package/src/clipboard.js +48 -0
  25. package/src/collab/CommentList.d.ts +32 -0
  26. package/src/collab/CommentList.js +165 -0
  27. package/src/collab/CommentViews.d.ts +131 -0
  28. package/src/collab/CommentViews.js +619 -0
  29. package/src/collab/HistoryViews.d.ts +38 -0
  30. package/src/collab/HistoryViews.js +103 -0
  31. package/src/collab/PresenceViews.d.ts +53 -0
  32. package/src/collab/PresenceViews.js +48 -0
  33. package/src/collab/cds/cds.d.ts +151 -0
  34. package/src/collab/cds/cds.js +231 -0
  35. package/src/collab/cds/comment-card.d.ts +113 -0
  36. package/src/collab/cds/comment-card.js +230 -0
  37. package/src/collab/cds/comment-composer.d.ts +35 -0
  38. package/src/collab/cds/comment-composer.js +125 -0
  39. package/src/collab/cds/comments-css.d.ts +2 -0
  40. package/src/collab/cds/comments-css.js +3 -0
  41. package/src/collab/cds/comments.css +504 -0
  42. package/src/collab/cds/edge-piles.d.ts +69 -0
  43. package/src/collab/cds/edge-piles.js +178 -0
  44. package/src/collab/cds/layer.d.ts +41 -0
  45. package/src/collab/cds/layer.js +144 -0
  46. package/src/collab/cds/markdown.d.ts +20 -0
  47. package/src/collab/cds/markdown.js +534 -0
  48. package/src/collab/cds/shield.d.ts +28 -0
  49. package/src/collab/cds/shield.js +114 -0
  50. package/src/collab/cds/time.d.ts +2 -0
  51. package/src/collab/cds/time.js +41 -0
  52. package/src/collab/collab.d.ts +102 -0
  53. package/src/collab/collab.js +121 -0
  54. package/src/collab/comments.d.ts +272 -0
  55. package/src/collab/comments.js +596 -0
  56. package/src/collab/history-wiring.d.ts +32 -0
  57. package/src/collab/history-wiring.js +53 -0
  58. package/src/collab/history.d.ts +59 -0
  59. package/src/collab/history.js +96 -0
  60. package/src/collab/mentions/mention-list.d.ts +63 -0
  61. package/src/collab/mentions/mention-list.js +257 -0
  62. package/src/collab/mentions.d.ts +112 -0
  63. package/src/collab/mentions.js +164 -0
  64. package/src/collab/peer-colors.d.ts +123 -0
  65. package/src/collab/peer-colors.js +273 -0
  66. package/src/collab/pins.d.ts +70 -0
  67. package/src/collab/pins.js +44 -0
  68. package/src/collab/presence.d.ts +92 -0
  69. package/src/collab/presence.js +158 -0
  70. package/src/design-systems.d.ts +46 -0
  71. package/src/design-systems.js +61 -0
  72. package/src/downloads.d.ts +31 -0
  73. package/src/downloads.js +46 -0
  74. package/src/file-drop.d.ts +33 -0
  75. package/src/file-drop.js +36 -0
  76. package/src/find.d.ts +64 -0
  77. package/src/find.js +147 -0
  78. package/src/follow.d.ts +141 -0
  79. package/src/follow.js +389 -0
  80. package/src/index.d.ts +32 -0
  81. package/src/index.js +32 -0
  82. package/src/keys.d.ts +18 -0
  83. package/src/keys.js +42 -0
  84. package/src/menu-fit.d.ts +12 -0
  85. package/src/menu-fit.js +9 -0
  86. package/src/merge.d.ts +23 -0
  87. package/src/merge.js +116 -0
  88. package/src/page-link.d.ts +33 -0
  89. package/src/page-link.js +75 -0
  90. package/src/project-sync.d.ts +161 -0
  91. package/src/project-sync.js +319 -0
  92. package/src/react.d.ts +20 -0
  93. package/src/react.js +20 -0
  94. package/src/read-retries.d.ts +55 -0
  95. package/src/read-retries.js +125 -0
  96. package/src/right-drag-pan.d.ts +128 -0
  97. package/src/right-drag-pan.js +253 -0
  98. package/src/roles.d.ts +39 -0
  99. package/src/roles.js +27 -0
  100. package/src/session.d.ts +56 -0
  101. package/src/session.js +57 -0
  102. package/src/shell.d.ts +60 -0
  103. package/src/shell.js +111 -0
  104. package/src/stash.d.ts +26 -0
  105. package/src/stash.js +69 -0
  106. package/src/styles.css +17 -0
  107. package/src/toolbar-fold.d.ts +106 -0
  108. package/src/toolbar-fold.js +130 -0
  109. package/src/video-shrink/index.d.ts +8 -0
  110. package/src/video-shrink/index.js +7 -0
  111. package/src/video-shrink/plan.d.ts +92 -0
  112. package/src/video-shrink/plan.js +133 -0
  113. package/src/video-shrink/protocol.d.ts +29 -0
  114. package/src/video-shrink/protocol.js +2 -0
  115. package/src/video-shrink/queue.d.ts +69 -0
  116. package/src/video-shrink/queue.js +287 -0
  117. package/src/video-shrink/worker.d.ts +8 -0
  118. package/src/video-shrink/worker.js +223 -0
  119. package/src/wheel-zoom.d.ts +14 -0
  120. package/src/wheel-zoom.js +48 -0
@@ -0,0 +1,41 @@
1
+ export function commentTime(iso, now = new Date()) {
2
+ const at = new Date(iso);
3
+ if (Number.isNaN(at.getTime()))
4
+ return '';
5
+ if (now.getTime() - at.getTime() < 60_000)
6
+ return 'now';
7
+ const time = at.toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit' });
8
+ const day = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
9
+ const days = Math.round((day(now) - day(at)) / 86_400_000);
10
+ if (days === 0)
11
+ return time;
12
+ if (days === 1)
13
+ return `Yesterday, ${time}`;
14
+ const date = at.toLocaleDateString('en-US', {
15
+ month: 'short',
16
+ day: 'numeric',
17
+ ...(at.getFullYear() !== now.getFullYear() ? { year: 'numeric' } : {}),
18
+ });
19
+ return `${date}, ${time}`;
20
+ }
21
+ export function commentAgo(iso, now = new Date()) {
22
+ const at = new Date(iso);
23
+ if (Number.isNaN(at.getTime()))
24
+ return '';
25
+ const minutes = Math.floor((now.getTime() - at.getTime()) / 60_000);
26
+ if (minutes < 1)
27
+ return 'now';
28
+ if (minutes < 60)
29
+ return `${minutes}m`;
30
+ const hours = Math.floor(minutes / 60);
31
+ if (hours < 24)
32
+ return `${hours}h`;
33
+ const days = Math.floor(hours / 24);
34
+ if (days < 7)
35
+ return `${days}d`;
36
+ return at.toLocaleDateString('en-US', {
37
+ month: 'short',
38
+ day: 'numeric',
39
+ ...(at.getFullYear() !== now.getFullYear() ? { year: 'numeric' } : {}),
40
+ });
41
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Collaboration glue for any editor: what the Shell draws for comments and
3
+ * history (its Comment and History buttons), the Shell's commands for them,
4
+ * which of the two panels is open on the right, and the keys of comment
5
+ * mode (C toggles it, Esc closes a composer, then a card, then the mode).
6
+ *
7
+ * Editor-agnostic: the editor says
8
+ * whether its comment surface is showing and how to comment on its
9
+ * selection ({@link CollabAdapter}).
10
+ */
11
+ import type { ChromeCommand, ChromeReport, CommentThread } from '@openartifactsai/runtime';
12
+ /** What an editor tells the glue. */
13
+ export interface CollabAdapter {
14
+ /** The surface comment mode works on is showing (the canvas, the slide…). */
15
+ onSurface(): boolean;
16
+ /** Brings that surface up (leaves a focused or outline view). */
17
+ showSurface?(): void;
18
+ /** Starts a thread on what is selected (the Shell's `comment_selection` action). */
19
+ commentOnSelection?(): void;
20
+ /** Route the comment shortcut through the host when it owns the entry point. */
21
+ requestCommentMode?(on: boolean): boolean;
22
+ /** The viewer cannot edit (comment mode then leaves Delete alone). */
23
+ readOnly(): boolean;
24
+ /** The Shell's page button for comments (default `false`: the page draws its own). */
25
+ pageButton?: boolean;
26
+ }
27
+ /** A key press, as the editor's shortcut handler sees it. */
28
+ export interface CollabKey {
29
+ key: string;
30
+ code?: string | undefined;
31
+ meta: boolean;
32
+ shift: boolean;
33
+ alt: boolean;
34
+ }
35
+ export type CollabAsideKind = 'history' | null;
36
+ /** Which collaboration panel is docked on the right. */
37
+ export declare function collabAside(_comments: {
38
+ available: boolean;
39
+ listOpen: boolean;
40
+ }, history: {
41
+ available: boolean;
42
+ open: boolean;
43
+ }): CollabAsideKind;
44
+ /** A zustand store as the glue reads it (a bound store: callable as a hook). */
45
+ export interface CollabStore<S> {
46
+ getState(): S;
47
+ subscribe(listener: (state: S, previous: S) => void): () => void;
48
+ <U>(selector: (state: S) => U): U;
49
+ }
50
+ /**
51
+ * The comments the glue drives: a {@link CommentsController}, or an
52
+ * editor's own comments store of the same shape (`available`, `on`,
53
+ * `listOpen`, `threads`, `active`, `draft`…).
54
+ */
55
+ export interface CollabComments {
56
+ store: CollabStore<{
57
+ available: boolean;
58
+ on: boolean;
59
+ listOpen: boolean;
60
+ threads: CommentThread[];
61
+ active: string | null;
62
+ draft: unknown;
63
+ setOn(on: boolean): void;
64
+ setListOpen(open: boolean): void;
65
+ setActive(id: string | null): void;
66
+ setDraft(draft: null): void;
67
+ }>;
68
+ canComment(): boolean;
69
+ }
70
+ /** The version history the glue drives: a {@link HistoryController}, or an editor's own of the same shape. */
71
+ export interface CollabHistory {
72
+ store: CollabStore<{
73
+ available: boolean;
74
+ open: boolean;
75
+ previewing: number | null;
76
+ }>;
77
+ /** Opens or closes the panel (closing it ends a preview). */
78
+ toggle(open?: boolean): void;
79
+ }
80
+ /** One editor's collaboration glue. */
81
+ export interface CollabController {
82
+ /** What the Shell draws for comments and history. */
83
+ chromeReport(): Pick<ChromeReport, 'comments' | 'history'>;
84
+ /** Calls `report` whenever {@link chromeReport} may have changed. */
85
+ subscribe(report: () => void): () => void;
86
+ /** Runs a Shell command that belongs to comments or history; returns whether it did. */
87
+ handleCommand(command: ChromeCommand): boolean;
88
+ /** Opens or closes the comment list (closing the history panel). */
89
+ toggleCommentList(open?: boolean): void;
90
+ /** Opens or closes the history panel (closing the comment list). */
91
+ toggleHistoryPanel(open?: boolean): void;
92
+ /** The open panel (a React hook). */
93
+ useAside(): CollabAsideKind;
94
+ /** Keys of comment mode and of a history preview, ahead of the editor's shortcuts; returns whether the key was taken. */
95
+ runShortcut(press: CollabKey): boolean;
96
+ }
97
+ /** Creates an editor's collaboration glue. */
98
+ export declare function createCollab({ comments, history, adapter }: {
99
+ comments: CollabComments;
100
+ history: CollabHistory;
101
+ adapter: CollabAdapter;
102
+ }): CollabController;
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Collaboration glue for any editor: what the Shell draws for comments and
3
+ * history (its Comment and History buttons), the Shell's commands for them,
4
+ * which of the two panels is open on the right, and the keys of comment
5
+ * mode (C toggles it, Esc closes a composer, then a card, then the mode).
6
+ *
7
+ * Editor-agnostic: the editor says
8
+ * whether its comment surface is showing and how to comment on its
9
+ * selection ({@link CollabAdapter}).
10
+ */
11
+ import { openMessageCount } from "./comments.js";
12
+ /** Which collaboration panel is docked on the right. */
13
+ export function collabAside(_comments, history) {
14
+ return history.available && history.open ? 'history' : null;
15
+ }
16
+ /** Creates an editor's collaboration glue. */
17
+ export function createCollab({ comments, history, adapter }) {
18
+ const toggleCommentList = (open) => {
19
+ const state = comments.store.getState();
20
+ const next = open ?? !state.listOpen;
21
+ state.setListOpen(next);
22
+ if (next && history.store.getState().open)
23
+ history.toggle(false);
24
+ };
25
+ const toggleHistoryPanel = (open) => {
26
+ const next = open ?? !history.store.getState().open;
27
+ history.toggle(next);
28
+ if (next)
29
+ comments.store.getState().setListOpen(false);
30
+ };
31
+ return {
32
+ chromeReport() {
33
+ const c = comments.store.getState();
34
+ const h = history.store.getState();
35
+ return {
36
+ ...(c.available ? { comments: { available: true, on: c.on, open: c.listOpen, count: openMessageCount(c.threads), pageButton: adapter.pageButton ?? false } } : {}),
37
+ ...(h.available ? { history: true } : {}),
38
+ };
39
+ },
40
+ subscribe(report) {
41
+ const a = comments.store.subscribe(report);
42
+ const b = history.store.subscribe((state, previous) => {
43
+ if (state.available !== previous.available)
44
+ report();
45
+ });
46
+ return () => {
47
+ a();
48
+ b();
49
+ };
50
+ },
51
+ handleCommand(command) {
52
+ switch (command.cmd) {
53
+ case 'comments_mode': {
54
+ const state = comments.store.getState();
55
+ if (!state.available)
56
+ return true;
57
+ const on = command.on ?? !state.on;
58
+ if (on && !adapter.onSurface())
59
+ adapter.showSurface?.();
60
+ state.setOn(on);
61
+ return true;
62
+ }
63
+ case 'comments_list':
64
+ toggleCommentList(command.open);
65
+ return true;
66
+ case 'history':
67
+ toggleHistoryPanel();
68
+ return true;
69
+ case 'action':
70
+ if (command.id === 'comment_selection' && adapter.commentOnSelection) {
71
+ adapter.commentOnSelection();
72
+ return true;
73
+ }
74
+ return false;
75
+ default:
76
+ return false;
77
+ }
78
+ },
79
+ toggleCommentList,
80
+ toggleHistoryPanel,
81
+ useAside() {
82
+ const commentsAvailable = comments.store((s) => s.available);
83
+ const listOpen = comments.store((s) => s.listOpen);
84
+ const historyAvailable = history.store((s) => s.available);
85
+ const historyOpen = history.store((s) => s.open);
86
+ return collabAside({ available: commentsAvailable, listOpen }, { available: historyAvailable, open: historyOpen });
87
+ },
88
+ runShortcut(press) {
89
+ // A past version is on screen: the editor under it takes no keys (Esc is the preview's).
90
+ if (history.store.getState().previewing !== null)
91
+ return true;
92
+ const state = comments.store.getState();
93
+ if (!state.available)
94
+ return false;
95
+ if (press.key === 'Escape') {
96
+ if (state.draft !== null)
97
+ state.setDraft(null);
98
+ else if (state.active)
99
+ state.setActive(null);
100
+ else if (state.on)
101
+ state.setOn(false);
102
+ else
103
+ return false;
104
+ return true;
105
+ }
106
+ const letter = press.code?.startsWith('Key') ? press.code.slice(3).toLowerCase() : press.key.toLowerCase();
107
+ if (letter === 'c' && !press.meta && !press.alt && !press.shift) {
108
+ if (!comments.canComment() || !adapter.onSurface())
109
+ return false;
110
+ if (adapter.requestCommentMode)
111
+ return adapter.requestCommentMode(!state.on);
112
+ state.setOn(!state.on);
113
+ return true;
114
+ }
115
+ // Editing keys do nothing while comment mode is on (the surface is for placing comments).
116
+ if (state.on && !press.meta && !adapter.readOnly() && (press.key === 'Delete' || press.key === 'Backspace'))
117
+ return true;
118
+ return false;
119
+ },
120
+ };
121
+ }
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Comment threads for any editor: the store (threads, comment mode, the
3
+ * open card, the draft, the list), and the thread actions over the
4
+ * `comments` capability.
5
+ *
6
+ * Editor-agnostic: what an anchor is,
7
+ * how it is labelled, where it points the agent and how the editor shows it
8
+ * are the {@link CommentsAdapter}'s. The editor hands the capability to
9
+ * {@link CommentsController.start}.
10
+ */
11
+ import { type CommentAuthor, type CommentSendOptions, type CommentsCapability, type CommentThread, type JsonRecord } from '@openartifactsai/runtime';
12
+ import { type StoreApi, type UseBoundStore } from 'zustand';
13
+ import { type MentionPerson } from './mentions.js';
14
+ import type { AnchorState } from './pins.js';
15
+ /**
16
+ * Longest comment, in UTF-8 bytes of the trimmed text: claude.ai's comment boxes take as much. The boxes also set it
17
+ * as their `maxLength` (UTF-16 units), so typing and pasting stop there, and a longer text in bytes (CJK, emoji) is
18
+ * refused when it is sent, with the draft kept.
19
+ */
20
+ export declare const COMMENT_TEXT_BYTES = 4096;
21
+ /** The stored anchor of a comment on the whole artifact (see {@link CommentsAdapter.wholeArtifact}). */
22
+ export declare const WHOLE_ARTIFACT = "";
23
+ /** What the default check says when a comment is over {@link COMMENT_TEXT_BYTES}. */
24
+ export declare const COMMENT_TOO_LONG = "That comment is too long.";
25
+ /** Longest docs comment, in characters: the docs composer counts toward it. */
26
+ export declare const COMMENT_TEXT_MAX = 4000;
27
+ /** The UTF-8 size of `text`, as {@link COMMENT_TEXT_BYTES} counts it. */
28
+ export declare function commentTextBytes(text: string): number;
29
+ /** What an editor tells the comments controller. `A` is its anchor type. */
30
+ export interface CommentsAdapter<A> {
31
+ /** Shows a short message (a toast); default: nothing. */
32
+ notify?(message: {
33
+ title: string;
34
+ description?: string;
35
+ }): void;
36
+ /** Reads a stored anchor; anything unreadable should come back as a whole-document anchor. */
37
+ parse(text: string): A;
38
+ serialize(anchor: A): string;
39
+ /** A short label of what the anchor names ("Button “Sign up” in Home"). */
40
+ label(anchor: A): string;
41
+ /** Location details stored with the thread for the agent. */
42
+ location?(anchor: A): JsonRecord;
43
+ /** How the anchor resolves now (default `ok`). */
44
+ state?(anchor: A): AnchorState;
45
+ /** What a card says about an anchor that is not where it was made (default: a generic sentence). */
46
+ stateNote?(state: AnchorState): string | null;
47
+ /** Brings a thread's anchor into view (page, camera); the card opens after it. */
48
+ reveal?(anchor: A): void;
49
+ /** The viewer may write comments (commenters and up). */
50
+ canComment(): boolean;
51
+ /** The viewer may hand threads to the agent (usually the owner, with an agent connected). */
52
+ canSendToAgent(): boolean;
53
+ /** The agent's name in toasts. */
54
+ agentName?(): string;
55
+ /** false: the agent is not woken while it idles, so the toast tells the person to message it. */
56
+ agentWakesIdle?(): boolean | undefined;
57
+ /** The viewer's name (the new comment's pin shows their initials; default `You`). */
58
+ viewerName?(): string;
59
+ /** People the editor knows besides those the host lists and the threads name (listed after the host's, before authors). */
60
+ people?(): readonly MentionPerson[];
61
+ /** Comment mode turned on or off (end text editing, pick the select tool…). */
62
+ onModeChange?(on: boolean): void;
63
+ /** What the document is called in messages (default `document`). */
64
+ noun?: string;
65
+ /** Most threads one document keeps (default 500). */
66
+ maxThreads?: number;
67
+ /**
68
+ * Checks a message before it is sent: the text to send, or `undefined` to
69
+ * send nothing (after telling the person why); the draft stays either way
70
+ * until a send succeeds. Default: trimmed, and refused with
71
+ * {@link COMMENT_TOO_LONG} past {@link COMMENT_TEXT_BYTES}.
72
+ */
73
+ checkText?(text: string): string | undefined;
74
+ /** What the agent reads about an anchor, stored with a new thread. */
75
+ detail?(anchor: A): string | undefined;
76
+ /** The viewer may delete threads (default: anyone who may comment). */
77
+ canRemove?(): boolean;
78
+ /**
79
+ * Hands a thread to the agent the editor's way (its own request tracking
80
+ * and messages); resolves whether it was sent. Default: the capability's
81
+ * `sendToAgent` and a "Sent to …" message.
82
+ */
83
+ sendToAgent?(thread: CommentThread, anchor: A): Promise<boolean>;
84
+ /** Told of threads as the host hands them over: the list, every change and every write. */
85
+ heard?(threads: readonly CommentThread[]): void;
86
+ /** A new thread's card opens once it is saved (default: always); `sent`: it went to the agent too. */
87
+ opensCreated?(sent: boolean): boolean;
88
+ /**
89
+ * The anchor of a comment on the whole artifact rather than a spot in it: it has no pin and is written from the
90
+ * "All comments" panel. A thread stored with it, or with the empty string, is on the whole artifact. Without it the
91
+ * panel has no composer.
92
+ */
93
+ wholeArtifact?(): A;
94
+ /**
95
+ * The type's pins show a comment set aside ({@link CommentsState.parked}) and take it up again when pressed. Only
96
+ * then is a comment begun on the page set aside when a card or the panel's composer opens; without it the draft
97
+ * just closes and its text goes on to the next one. Every type with {@link wholeArtifact} sets it.
98
+ */
99
+ parksDrafts?: boolean;
100
+ }
101
+ /** The comments store. */
102
+ export interface CommentsState<A> {
103
+ available: boolean;
104
+ threads: CommentThread[];
105
+ /** Comment mode: presses on the surface start threads. */
106
+ on: boolean;
107
+ /** The thread list is open. */
108
+ listOpen: boolean;
109
+ /** The thread shown in a card. */
110
+ active: string | null;
111
+ /** A thread being written (its anchor chosen, no message yet). */
112
+ draft: A | null;
113
+ /** Show resolved threads (pins and list). */
114
+ showResolved: boolean;
115
+ /** The new-comment composer's "Send to agent" box (starts off; kept while the composer is moved to another spot). */
116
+ sendNew: boolean;
117
+ /** The new-comment composer's text (kept while it is moved to another spot). */
118
+ draftText: string;
119
+ /** Each thread's reply box: text and its "Send to agent" box (kept while the card closes and opens). */
120
+ replies: Record<string, {
121
+ text: string;
122
+ send: boolean;
123
+ }>;
124
+ /**
125
+ * A comment begun on the page and set aside with words in it (a card or the panel's composer opened over it): drawn
126
+ * as a draft pin, and pressing that takes it up again. While it waits, no other spot starts a comment.
127
+ */
128
+ parked: ParkedDraft<A> | null;
129
+ /** The message being edited in a card, and whether its words differ from the saved ones. */
130
+ editing: Editing | null;
131
+ /** Writes on their way to the host, one key each: `new`, `reply:<thread>`, `edit:<message>`, `delete:<thread>`, `send`. */
132
+ writing: string[];
133
+ /** People the host knows on this artifact (who has it, then who is here now), once {@link CommentsController.followPeople} ran. */
134
+ known: MentionPerson[];
135
+ /** The viewer as the host names them (to leave them out of `@`), once known. */
136
+ self: {
137
+ id: string;
138
+ name: string;
139
+ } | null;
140
+ /**
141
+ * A resolve or reopen the host has not answered yet. The thread already shows its new status; until the answer
142
+ * comes, no other thread can be resolved or reopened and the thread menus wait.
143
+ */
144
+ statusChange: StatusChange | null;
145
+ setOn(on: boolean): void;
146
+ setListOpen(open: boolean): void;
147
+ setActive(id: string | null): void;
148
+ setDraft(draft: A | null): void;
149
+ setShowResolved(show: boolean): void;
150
+ setSendNew(send: boolean): void;
151
+ setDraftText(text: string): void;
152
+ setReply(id: string, reply: {
153
+ text: string;
154
+ send: boolean;
155
+ }): void;
156
+ /** Starts or ends editing a message, or says whether its words changed. */
157
+ setEditing(editing: Editing | null): void;
158
+ }
159
+ /** A page comment set aside: where it was, its words and its "Send to agent" box. */
160
+ export interface ParkedDraft<A> {
161
+ anchor: A;
162
+ text: string;
163
+ send: boolean;
164
+ }
165
+ /** A message being edited: its thread, its "Send to agent" box, and whether its words differ from the saved ones. */
166
+ export interface Editing {
167
+ thread: string;
168
+ message: string;
169
+ send: boolean;
170
+ changed: boolean;
171
+ }
172
+ /** Why the panel's composer did not open: a write on its way, a comment being written, or an edit with changes. */
173
+ export type ComposeRefusal = 'posting' | 'writing' | 'editing';
174
+ /** A thread's status, set before the host has confirmed it. */
175
+ export interface StatusChange {
176
+ id: string;
177
+ status: CommentThread['status'];
178
+ }
179
+ /** What a menu says while a status change is on its way. */
180
+ export declare const WAIT_FOR_STATUS_CHANGE = "Wait for the current change to finish.";
181
+ /** The threads as shown: the stored ones, with an unconfirmed status change already applied. */
182
+ export declare function withStatusChange(threads: CommentThread[], change: StatusChange | null): CommentThread[];
183
+ /** One editor's comments. */
184
+ export interface CommentsController<A> {
185
+ readonly store: UseBoundStore<StoreApi<CommentsState<A>>>;
186
+ readonly adapter: CommentsAdapter<A>;
187
+ /** Loads the threads and keeps them current; `open` is a thread id to reveal (`?comment=`). */
188
+ start(capability: CommentsCapability | null, open?: string | null): Promise<void>;
189
+ /** Stops following the capability's changes. */
190
+ stop(): void;
191
+ capability(): CommentsCapability | null;
192
+ canComment(): boolean;
193
+ canSendToAgent(): boolean;
194
+ /** The viewer may delete threads. */
195
+ canRemove(): boolean;
196
+ anchorOf(thread: Pick<CommentThread, 'anchor'>): A;
197
+ /** The anchor of a new comment on the whole artifact, when the type has them (the panel's composer). */
198
+ wholeArtifact(): A | null;
199
+ /** The thread is on the whole artifact: no pin, nothing to bring into view. */
200
+ isWhole(thread: Pick<CommentThread, 'anchor'>): boolean;
201
+ /** The anchor is the whole artifact's. */
202
+ isWholeAnchor(anchor: A): boolean;
203
+ /**
204
+ * Opens the composer for a comment on the whole artifact; resolves `null`, or why it stays shut while a write is on
205
+ * its way or an edit has changes. A comment begun on the page is set aside when it has words in it (see
206
+ * {@link CommentsState.parked}), and dropped when it has none.
207
+ */
208
+ composeWhole(): ComposeRefusal | null;
209
+ /** Why the panel's composer would not open now (the same order the refusal is said in), or `null`. */
210
+ composeRefusal(): ComposeRefusal | null;
211
+ labelOf(anchor: A): string;
212
+ stateOf(anchor: A): AnchorState;
213
+ stateNote(state: AnchorState | undefined): string | null;
214
+ /** Starts a thread (`send`: and hands it to the agent; `to`: whom it names); resolves whether it was saved. */
215
+ create(anchor: A, text: string, options?: MessageOptions): Promise<boolean>;
216
+ /** Replies to a thread (`send`: and hands it to the agent; a resolved thread reopens); resolves whether it was saved. */
217
+ reply(id: string, text: string, options?: MessageOptions): Promise<boolean>;
218
+ /** Changes the text of one of the viewer's own messages (`send`: and hands the thread to the agent); resolves whether it was saved. */
219
+ edit(id: string, messageId: string, text: string, options?: MessageOptions): Promise<boolean>;
220
+ /** The viewer wrote this and may still change it. */
221
+ canEdit(author: CommentAuthor): boolean;
222
+ /** Starts following who the host says has the artifact and who is here (once; the `@` list asks for it when it first opens). */
223
+ followPeople(): void;
224
+ /** Whom `@` can name besides the agent, in the order the list shows them (the viewer included: the list leaves them out). */
225
+ mentionPeople(): MentionPerson[];
226
+ /**
227
+ * Resolves or reopens a thread. It shows the new status at once (a resolved card closes); if the host refuses, it
228
+ * goes back and its card reopens. One at a time: ignored while another change is waiting for the host.
229
+ */
230
+ resolve(id: string, resolved: boolean): Promise<void>;
231
+ remove(id: string, messageId?: string): Promise<void>;
232
+ /**
233
+ * Re-anchors a thread. `checked` (a pin the person dragged): the host refuses the move when someone else moved,
234
+ * resolved or removed the thread first, or when the viewer neither started it nor owns the artifact; the thread is
235
+ * then read again, so its pin goes back to where it is now.
236
+ */
237
+ move(id: string, anchor: A, options?: {
238
+ checked?: boolean;
239
+ }): Promise<void>;
240
+ /**
241
+ * Hands a thread to the agent; resolves whether it was sent. `parts`: the person's words in the newest message and
242
+ * what it is on, for an app to show (the host checks them).
243
+ */
244
+ sendToAgent(id: string, parts?: Pick<CommentSendOptions, 'userText' | 'selectionSnapshot'>): Promise<boolean>;
245
+ sendAllToAgent(): Promise<void>;
246
+ /** Whether a thread has something from a person the agent has not been handed (open, a person's message, not sent or answered since). */
247
+ canSendThread(thread: CommentThread): boolean;
248
+ reveal(thread: CommentThread): void;
249
+ /** Shows a thread where it is: comment mode on, its anchor in view, its card open (the "All comments" panel's rows). */
250
+ show(thread: CommentThread): void;
251
+ /** The viewer's name. */
252
+ viewerName(): string;
253
+ }
254
+ /** How a message is sent: `send` hands its thread to the agent; `to` is whom it names (`agent` for the agent). */
255
+ export interface MessageOptions {
256
+ send?: boolean;
257
+ to?: readonly string[];
258
+ }
259
+ /** Under a thread sent to the agent that has not taken it yet; one that is not woken while it idles needs a message. */
260
+ export declare function queuedNote(agent: {
261
+ name: string;
262
+ wakesIdle?: boolean;
263
+ }): string;
264
+ /** The toast after a thread goes to the agent; one that is not woken while it idles needs a message from the person. */
265
+ export declare function sentNotice(name: string, wakesIdle: boolean | undefined): {
266
+ title: string;
267
+ description?: string;
268
+ };
269
+ export declare function openCount(threads: readonly CommentThread[]): number;
270
+ export declare function openMessageCount(threads: readonly CommentThread[]): number;
271
+ /** Creates an editor's comments controller. */
272
+ export declare function createComments<A>(adapter: CommentsAdapter<A>): CommentsController<A>;