@open-artifact/editor-kit 0.0.0-stage → 0.2.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.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +128 -2
- package/package.json +58 -4
- package/src/Announcer.d.ts +2 -0
- package/src/Announcer.js +8 -0
- package/src/FindBar.d.ts +31 -0
- package/src/FindBar.js +34 -0
- package/src/agent.d.ts +22 -0
- package/src/agent.js +46 -0
- package/src/announce.d.ts +18 -0
- package/src/announce.js +21 -0
- package/src/chrome.d.ts +180 -0
- package/src/chrome.js +108 -0
- package/src/collab/CommentList.d.ts +23 -0
- package/src/collab/CommentList.js +117 -0
- package/src/collab/CommentViews.d.ts +118 -0
- package/src/collab/CommentViews.js +531 -0
- package/src/collab/HistoryViews.d.ts +38 -0
- package/src/collab/HistoryViews.js +103 -0
- package/src/collab/PresenceViews.d.ts +52 -0
- package/src/collab/PresenceViews.js +46 -0
- package/src/collab/cds/cds.d.ts +148 -0
- package/src/collab/cds/cds.js +230 -0
- package/src/collab/cds/comment-card.d.ts +93 -0
- package/src/collab/cds/comment-card.js +211 -0
- package/src/collab/cds/comment-composer.d.ts +28 -0
- package/src/collab/cds/comment-composer.js +101 -0
- package/src/collab/cds/comments-css.d.ts +2 -0
- package/src/collab/cds/comments-css.js +3 -0
- package/src/collab/cds/comments.css +497 -0
- package/src/collab/cds/edge-piles.d.ts +69 -0
- package/src/collab/cds/edge-piles.js +178 -0
- package/src/collab/cds/layer.d.ts +41 -0
- package/src/collab/cds/layer.js +143 -0
- package/src/collab/cds/markdown.d.ts +17 -0
- package/src/collab/cds/markdown.js +507 -0
- package/src/collab/cds/shield.d.ts +28 -0
- package/src/collab/cds/shield.js +114 -0
- package/src/collab/cds/time.d.ts +2 -0
- package/src/collab/cds/time.js +41 -0
- package/src/collab/collab.d.ts +100 -0
- package/src/collab/collab.js +119 -0
- package/src/collab/comments.d.ts +159 -0
- package/src/collab/comments.js +297 -0
- package/src/collab/history-wiring.d.ts +32 -0
- package/src/collab/history-wiring.js +53 -0
- package/src/collab/history.d.ts +53 -0
- package/src/collab/history.js +94 -0
- package/src/collab/peer-colors.d.ts +123 -0
- package/src/collab/peer-colors.js +273 -0
- package/src/collab/pins.d.ts +70 -0
- package/src/collab/pins.js +44 -0
- package/src/collab/presence.d.ts +92 -0
- package/src/collab/presence.js +158 -0
- package/src/design-systems.d.ts +46 -0
- package/src/design-systems.js +61 -0
- package/src/downloads.d.ts +24 -0
- package/src/downloads.js +36 -0
- package/src/find.d.ts +64 -0
- package/src/find.js +147 -0
- package/src/index.d.ts +25 -0
- package/src/index.js +25 -0
- package/src/keys.d.ts +13 -0
- package/src/keys.js +20 -0
- package/src/merge.d.ts +23 -0
- package/src/merge.js +116 -0
- package/src/page-link.d.ts +33 -0
- package/src/page-link.js +75 -0
- package/src/project-sync.d.ts +118 -0
- package/src/project-sync.js +174 -0
- package/src/react.d.ts +16 -0
- package/src/react.js +16 -0
- package/src/roles.d.ts +36 -0
- package/src/roles.js +27 -0
- package/src/session.d.ts +42 -0
- package/src/session.js +37 -0
- package/src/shell.d.ts +56 -0
- package/src/shell.js +96 -0
- package/src/stash.d.ts +26 -0
- package/src/stash.js +66 -0
- package/src/styles.css +17 -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,100 @@
|
|
|
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 '@open-artifact/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
|
+
/** The viewer cannot edit (comment mode then leaves Delete alone). */
|
|
21
|
+
readOnly(): boolean;
|
|
22
|
+
/** The Shell's page button for comments (default `false`: the page draws its own). */
|
|
23
|
+
pageButton?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** A key press, as the editor's shortcut handler sees it. */
|
|
26
|
+
export interface CollabKey {
|
|
27
|
+
key: string;
|
|
28
|
+
code?: string | undefined;
|
|
29
|
+
meta: boolean;
|
|
30
|
+
shift: boolean;
|
|
31
|
+
alt: boolean;
|
|
32
|
+
}
|
|
33
|
+
export type CollabAsideKind = 'history' | null;
|
|
34
|
+
/** Which collaboration panel is docked on the right. */
|
|
35
|
+
export declare function collabAside(_comments: {
|
|
36
|
+
available: boolean;
|
|
37
|
+
listOpen: boolean;
|
|
38
|
+
}, history: {
|
|
39
|
+
available: boolean;
|
|
40
|
+
open: boolean;
|
|
41
|
+
}): CollabAsideKind;
|
|
42
|
+
/** A zustand store as the glue reads it (a bound store: callable as a hook). */
|
|
43
|
+
export interface CollabStore<S> {
|
|
44
|
+
getState(): S;
|
|
45
|
+
subscribe(listener: (state: S, previous: S) => void): () => void;
|
|
46
|
+
<U>(selector: (state: S) => U): U;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The comments the glue drives: a {@link CommentsController}, or an
|
|
50
|
+
* editor's own comments store of the same shape (`available`, `on`,
|
|
51
|
+
* `listOpen`, `threads`, `active`, `draft`…).
|
|
52
|
+
*/
|
|
53
|
+
export interface CollabComments {
|
|
54
|
+
store: CollabStore<{
|
|
55
|
+
available: boolean;
|
|
56
|
+
on: boolean;
|
|
57
|
+
listOpen: boolean;
|
|
58
|
+
threads: CommentThread[];
|
|
59
|
+
active: string | null;
|
|
60
|
+
draft: unknown;
|
|
61
|
+
setOn(on: boolean): void;
|
|
62
|
+
setListOpen(open: boolean): void;
|
|
63
|
+
setActive(id: string | null): void;
|
|
64
|
+
setDraft(draft: null): void;
|
|
65
|
+
}>;
|
|
66
|
+
canComment(): boolean;
|
|
67
|
+
}
|
|
68
|
+
/** The version history the glue drives: a {@link HistoryController}, or an editor's own of the same shape. */
|
|
69
|
+
export interface CollabHistory {
|
|
70
|
+
store: CollabStore<{
|
|
71
|
+
available: boolean;
|
|
72
|
+
open: boolean;
|
|
73
|
+
previewing: number | null;
|
|
74
|
+
}>;
|
|
75
|
+
/** Opens or closes the panel (closing it ends a preview). */
|
|
76
|
+
toggle(open?: boolean): void;
|
|
77
|
+
}
|
|
78
|
+
/** One editor's collaboration glue. */
|
|
79
|
+
export interface CollabController {
|
|
80
|
+
/** What the Shell draws for comments and history. */
|
|
81
|
+
chromeReport(): Pick<ChromeReport, 'comments' | 'history'>;
|
|
82
|
+
/** Calls `report` whenever {@link chromeReport} may have changed. */
|
|
83
|
+
subscribe(report: () => void): () => void;
|
|
84
|
+
/** Runs a Shell command that belongs to comments or history; returns whether it did. */
|
|
85
|
+
handleCommand(command: ChromeCommand): boolean;
|
|
86
|
+
/** Opens or closes the comment list (closing the history panel). */
|
|
87
|
+
toggleCommentList(open?: boolean): void;
|
|
88
|
+
/** Opens or closes the history panel (closing the comment list). */
|
|
89
|
+
toggleHistoryPanel(open?: boolean): void;
|
|
90
|
+
/** The open panel (a React hook). */
|
|
91
|
+
useAside(): CollabAsideKind;
|
|
92
|
+
/** Keys of comment mode and of a history preview, ahead of the editor's shortcuts; returns whether the key was taken. */
|
|
93
|
+
runShortcut(press: CollabKey): boolean;
|
|
94
|
+
}
|
|
95
|
+
/** Creates an editor's collaboration glue. */
|
|
96
|
+
export declare function createCollab({ comments, history, adapter }: {
|
|
97
|
+
comments: CollabComments;
|
|
98
|
+
history: CollabHistory;
|
|
99
|
+
adapter: CollabAdapter;
|
|
100
|
+
}): CollabController;
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
state.setOn(!state.on);
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
// Editing keys do nothing while comment mode is on (the surface is for placing comments).
|
|
114
|
+
if (state.on && !press.meta && !adapter.readOnly() && (press.key === 'Delete' || press.key === 'Backspace'))
|
|
115
|
+
return true;
|
|
116
|
+
return false;
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
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 { CommentsCapability, CommentThread, JsonRecord } from '@open-artifact/runtime';
|
|
12
|
+
import { type StoreApi, type UseBoundStore } from 'zustand';
|
|
13
|
+
import type { AnchorState } from './pins.ts';
|
|
14
|
+
/** Longest message. */
|
|
15
|
+
export declare const COMMENT_TEXT_MAX = 4000;
|
|
16
|
+
/** What an editor tells the comments controller. `A` is its anchor type. */
|
|
17
|
+
export interface CommentsAdapter<A> {
|
|
18
|
+
/** Shows a short message (a toast); default: nothing. */
|
|
19
|
+
notify?(message: {
|
|
20
|
+
title: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
}): void;
|
|
23
|
+
/** Reads a stored anchor; anything unreadable should come back as a whole-document anchor. */
|
|
24
|
+
parse(text: string): A;
|
|
25
|
+
serialize(anchor: A): string;
|
|
26
|
+
/** A short label of what the anchor names ("Button “Sign up” in Home"). */
|
|
27
|
+
label(anchor: A): string;
|
|
28
|
+
/** Location details stored with the thread for the agent. */
|
|
29
|
+
location?(anchor: A): JsonRecord;
|
|
30
|
+
/** How the anchor resolves now (default `ok`). */
|
|
31
|
+
state?(anchor: A): AnchorState;
|
|
32
|
+
/** What a card says about an anchor that is not where it was made (default: a generic sentence). */
|
|
33
|
+
stateNote?(state: AnchorState): string | null;
|
|
34
|
+
/** Brings a thread's anchor into view (page, camera); the card opens after it. */
|
|
35
|
+
reveal?(anchor: A): void;
|
|
36
|
+
/** The viewer may write comments (commenters and up). */
|
|
37
|
+
canComment(): boolean;
|
|
38
|
+
/** The viewer may hand threads to the agent (usually the owner, with an agent connected). */
|
|
39
|
+
canSendToAgent(): boolean;
|
|
40
|
+
/** The agent's name in toasts. */
|
|
41
|
+
agentName?(): string;
|
|
42
|
+
/** false: the agent is not woken while it idles, so the toast tells the person to message it. */
|
|
43
|
+
agentWakesIdle?(): boolean | undefined;
|
|
44
|
+
/** The viewer's name (the new comment's pin shows their initials; default `You`). */
|
|
45
|
+
viewerName?(): string;
|
|
46
|
+
/** Comment mode turned on or off (end text editing, pick the select tool…). */
|
|
47
|
+
onModeChange?(on: boolean): void;
|
|
48
|
+
/** What the document is called in messages (default `document`). */
|
|
49
|
+
noun?: string;
|
|
50
|
+
/** Most threads one document keeps (default 500). */
|
|
51
|
+
maxThreads?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Checks a message before it is sent: the text to send, or `undefined` to
|
|
54
|
+
* send nothing (after telling the person why). Default: trimmed and cut
|
|
55
|
+
* to {@link COMMENT_TEXT_MAX} characters.
|
|
56
|
+
*/
|
|
57
|
+
checkText?(text: string): string | undefined;
|
|
58
|
+
/** What the agent reads about an anchor, stored with a new thread. */
|
|
59
|
+
detail?(anchor: A): string | undefined;
|
|
60
|
+
/** The viewer may delete threads (default: anyone who may comment). */
|
|
61
|
+
canRemove?(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Hands a thread to the agent the editor's way (its own request tracking
|
|
64
|
+
* and messages); resolves whether it was sent. Default: the capability's
|
|
65
|
+
* `sendToAgent` and a "Sent to …" message.
|
|
66
|
+
*/
|
|
67
|
+
sendToAgent?(thread: CommentThread, anchor: A): Promise<boolean>;
|
|
68
|
+
/** Told of threads as the host hands them over: the list, every change and every write. */
|
|
69
|
+
heard?(threads: readonly CommentThread[]): void;
|
|
70
|
+
}
|
|
71
|
+
/** The comments store. */
|
|
72
|
+
export interface CommentsState<A> {
|
|
73
|
+
available: boolean;
|
|
74
|
+
threads: CommentThread[];
|
|
75
|
+
/** Comment mode: presses on the surface start threads. */
|
|
76
|
+
on: boolean;
|
|
77
|
+
/** The thread list is open. */
|
|
78
|
+
listOpen: boolean;
|
|
79
|
+
/** The thread shown in a card. */
|
|
80
|
+
active: string | null;
|
|
81
|
+
/** A thread being written (its anchor chosen, no message yet). */
|
|
82
|
+
draft: A | null;
|
|
83
|
+
/** Show resolved threads (pins and list). */
|
|
84
|
+
showResolved: boolean;
|
|
85
|
+
/** The new-comment composer's "Send to agent" box (starts off; kept while the composer is moved to another spot). */
|
|
86
|
+
sendNew: boolean;
|
|
87
|
+
/** The new-comment composer's text (kept while it is moved to another spot). */
|
|
88
|
+
draftText: string;
|
|
89
|
+
/** Each thread's reply box: text and its "Send to agent" box (kept while the card closes and opens). */
|
|
90
|
+
replies: Record<string, {
|
|
91
|
+
text: string;
|
|
92
|
+
send: boolean;
|
|
93
|
+
}>;
|
|
94
|
+
setOn(on: boolean): void;
|
|
95
|
+
setListOpen(open: boolean): void;
|
|
96
|
+
setActive(id: string | null): void;
|
|
97
|
+
setDraft(draft: A | null): void;
|
|
98
|
+
setShowResolved(show: boolean): void;
|
|
99
|
+
setSendNew(send: boolean): void;
|
|
100
|
+
setDraftText(text: string): void;
|
|
101
|
+
setReply(id: string, reply: {
|
|
102
|
+
text: string;
|
|
103
|
+
send: boolean;
|
|
104
|
+
}): void;
|
|
105
|
+
}
|
|
106
|
+
/** One editor's comments. */
|
|
107
|
+
export interface CommentsController<A> {
|
|
108
|
+
readonly store: UseBoundStore<StoreApi<CommentsState<A>>>;
|
|
109
|
+
readonly adapter: CommentsAdapter<A>;
|
|
110
|
+
/** Loads the threads and keeps them current; `open` is a thread id to reveal (`?comment=`). */
|
|
111
|
+
start(capability: CommentsCapability | null, open?: string | null): Promise<void>;
|
|
112
|
+
/** Stops following the capability's changes. */
|
|
113
|
+
stop(): void;
|
|
114
|
+
capability(): CommentsCapability | null;
|
|
115
|
+
canComment(): boolean;
|
|
116
|
+
canSendToAgent(): boolean;
|
|
117
|
+
/** The viewer may delete threads. */
|
|
118
|
+
canRemove(): boolean;
|
|
119
|
+
anchorOf(thread: Pick<CommentThread, 'anchor'>): A;
|
|
120
|
+
labelOf(anchor: A): string;
|
|
121
|
+
stateOf(anchor: A): AnchorState;
|
|
122
|
+
stateNote(state: AnchorState | undefined): string | null;
|
|
123
|
+
/** Starts a thread (`send`: and hands it to the agent); resolves whether it was saved. */
|
|
124
|
+
create(anchor: A, text: string, options?: {
|
|
125
|
+
send?: boolean;
|
|
126
|
+
}): Promise<boolean>;
|
|
127
|
+
/** Replies to a thread (`send`: and hands it to the agent; a resolved thread reopens); resolves whether it was saved. */
|
|
128
|
+
reply(id: string, text: string, options?: {
|
|
129
|
+
send?: boolean;
|
|
130
|
+
}): Promise<boolean>;
|
|
131
|
+
resolve(id: string, resolved: boolean): Promise<void>;
|
|
132
|
+
remove(id: string, messageId?: string): Promise<void>;
|
|
133
|
+
move(id: string, anchor: A): Promise<void>;
|
|
134
|
+
/** Hands a thread to the agent; resolves whether it was sent. */
|
|
135
|
+
sendToAgent(id: string): Promise<boolean>;
|
|
136
|
+
sendAllToAgent(): Promise<void>;
|
|
137
|
+
/** Whether a thread has something from a person the agent has not been handed (open, a person's message, not sent or answered since). */
|
|
138
|
+
canSendThread(thread: CommentThread): boolean;
|
|
139
|
+
reveal(thread: CommentThread): void;
|
|
140
|
+
/** Shows a thread where it is: comment mode on, its anchor in view, its card open (the "All comments" panel's rows). */
|
|
141
|
+
show(thread: CommentThread): void;
|
|
142
|
+
/** The viewer's name. */
|
|
143
|
+
viewerName(): string;
|
|
144
|
+
}
|
|
145
|
+
/** Open (unresolved) thread count. */
|
|
146
|
+
/** Under a thread sent to the agent that has not taken it yet; one that is not woken while it idles needs a message. */
|
|
147
|
+
export declare function queuedNote(agent: {
|
|
148
|
+
name: string;
|
|
149
|
+
wakesIdle?: boolean;
|
|
150
|
+
}): string;
|
|
151
|
+
/** The toast after a thread goes to the agent; one that is not woken while it idles needs a message from the person. */
|
|
152
|
+
export declare function sentNotice(name: string, wakesIdle: boolean | undefined): {
|
|
153
|
+
title: string;
|
|
154
|
+
description?: string;
|
|
155
|
+
};
|
|
156
|
+
export declare function openCount(threads: readonly CommentThread[]): number;
|
|
157
|
+
export declare function openMessageCount(threads: readonly CommentThread[]): number;
|
|
158
|
+
/** Creates an editor's comments controller. */
|
|
159
|
+
export declare function createComments<A>(adapter: CommentsAdapter<A>): CommentsController<A>;
|