@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,48 @@
1
+ /**
2
+ * Writing the system clipboard from an editor. Some browsers keep the
3
+ * clipboard from framed pages whatever the frame's `allow` says; there the
4
+ * Open Artifacts Shell framing the editor writes instead (it may, right after
5
+ * a press in the frame). Pure (no DOM until called).
6
+ */
7
+ /** The browser itself writes clipboard formats (images, HTML) here. */
8
+ const browserWrites = () => typeof ClipboardItem !== 'undefined' && Boolean(globalThis.navigator?.clipboard?.write);
9
+ /** The browser refused the clipboard (rather than failing on the content). */
10
+ export function clipboardRefused(error) {
11
+ return typeof error === 'object' && error !== null && error.name === 'NotAllowedError';
12
+ }
13
+ /** Formats can be copied: by the browser, or by the Shell framing the page. */
14
+ export function canWriteClipboard(shell) {
15
+ return browserWrites() || Boolean(shell?.writesClipboard);
16
+ }
17
+ /**
18
+ * Writes one clipboard item. Call it on the person's press without awaiting
19
+ * anything first (a format may still be a promise, such as an image being
20
+ * drawn). Where the browser refuses this page, the Shell writes it.
21
+ */
22
+ export async function writeClipboard(items, shell) {
23
+ if (browserWrites()) {
24
+ try {
25
+ await navigator.clipboard.write([new ClipboardItem(items)]);
26
+ return;
27
+ }
28
+ catch (error) {
29
+ if (!shell?.writesClipboard || !clipboardRefused(error))
30
+ throw error;
31
+ }
32
+ }
33
+ else if (!shell?.writesClipboard) {
34
+ throw new Error('This browser cannot copy to the clipboard.');
35
+ }
36
+ await shell.writeClipboard(items);
37
+ }
38
+ /** Writes text to the clipboard, through the Shell where the browser refuses this page. */
39
+ export async function writeClipboardText(text, shell) {
40
+ try {
41
+ await navigator.clipboard.writeText(text);
42
+ }
43
+ catch (error) {
44
+ if (!shell?.writesClipboard || !clipboardRefused(error))
45
+ throw error;
46
+ await shell.writeClipboard({ 'text/plain': new Blob([text], { type: 'text/plain' }) });
47
+ }
48
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * fixed under the bar the comments button is in, at the right edge; every thread newest first, open ones unless
3
+ * "Show resolved" is ticked in its filter menu; "Send all to {agent}" for whoever may send; a click on a row shows the
4
+ * thread where it is (comment mode on, its anchor in view, its card open). Each row is a flat comment card whose
5
+ * Resolve and ⋯ menu (Reopen, Delete thread) show while it is hovered or current.
6
+ *
7
+ * A type whose controller has whole-artifact anchors also gets "Add comment" under the header: a composer in the panel
8
+ * for a comment on the artifact as a whole (no pin, no spot), with the `@` list and "Send to {agent}". Such a thread's
9
+ * row says "Whole artifact", and its card opens beside the panel, or at the top right while the panel is closed.
10
+ *
11
+ * What a type supplies is only its threads and anchors (the controller); the panel is the same everywhere.
12
+ */
13
+ import { type ReactNode } from 'react';
14
+ import { type CommentsController } from './comments.js';
15
+ import { type AgentBadge } from './CommentViews.js';
16
+ /** The room the open panel takes at the right edge (pins' edge tabs keep clear of it). */
17
+ export declare const ALL_COMMENTS_RIGHT: number;
18
+ export interface AllCommentsProps<A> {
19
+ comments: CommentsController<A>;
20
+ agent: AgentBadge;
21
+ /** Where the panel starts, px from the window's top (default 12: under a Shell's bar, the frame's top). */
22
+ top?: number;
23
+ /** What the empty panel says to someone who can comment. */
24
+ hint?: string;
25
+ /** Run the window's full height (down to the same gap from the bottom) rather than fit the threads. */
26
+ fill?: boolean;
27
+ }
28
+ /**
29
+ * The "All comments" panel, while the comments store says it is open; and the open card of a thread on the whole
30
+ * artifact, which has no pin to open by.
31
+ */
32
+ export declare function AllComments<A>({ comments, agent, top, hint, fill }: AllCommentsProps<A>): ReactNode;
@@ -0,0 +1,165 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * fixed under the bar the comments button is in, at the right edge; every thread newest first, open ones unless
4
+ * "Show resolved" is ticked in its filter menu; "Send all to {agent}" for whoever may send; a click on a row shows the
5
+ * thread where it is (comment mode on, its anchor in view, its card open). Each row is a flat comment card whose
6
+ * Resolve and ⋯ menu (Reopen, Delete thread) show while it is hovered or current.
7
+ *
8
+ * A type whose controller has whole-artifact anchors also gets "Add comment" under the header: a composer in the panel
9
+ * for a comment on the artifact as a whole (no pin, no spot), with the `@` list and "Send to {agent}". Such a thread's
10
+ * row says "Whole artifact", and its card opens beside the panel, or at the top right while the panel is closed.
11
+ *
12
+ * What a type supplies is only its threads and anchors (the controller); the panel is the same everywhere.
13
+ */
14
+ import { Menu as BaseMenu } from '@base-ui/react/menu';
15
+ import { useEffect, useId, useState } from 'react';
16
+ import { isComposingKey } from '@openartifactsai/ui';
17
+ import { Button, CheckboxMark, cn, Icon, MENU_ITEM, Menu, MenuPopup, panelClass, panelVars, RobotGlyph, Tooltip, useCdsRoot } from "./cds/cds.js";
18
+ import { Actions, Comment, CommentCard, DeleteConfirm, MoreMenu, ResolveAction, useLayerMenu } from "./cds/comment-card.js";
19
+ import { CommentsLayer } from "./cds/layer.js";
20
+ import { commentMarkdown } from "./cds/markdown.js";
21
+ import { sentMentionNames } from "./mentions.js";
22
+ import { commentAgo } from "./cds/time.js";
23
+ import { WAIT_FOR_STATUS_CHANGE } from "./comments.js";
24
+ import { CommentComposer, CommentPopover, ThreadCard } from "./CommentViews.js";
25
+ /** The panel: 300px, 12px from the right edge and from the bar above it. */
26
+ const PANEL_WIDTH = 300;
27
+ const PANEL_GAP = 12;
28
+ /** The room the open panel takes at the right edge (pins' edge tabs keep clear of it). */
29
+ export const ALL_COMMENTS_RIGHT = PANEL_WIDTH + PANEL_GAP * 2;
30
+ /** A whole-artifact thread's card, beside the panel. */
31
+ const WHOLE_CARD_WIDTH = 330;
32
+ /** Why "Add comment" did not open the composer, said under it while the reason holds. */
33
+ const COMPOSE_REFUSED = {
34
+ posting: 'Wait until the comment finishes posting.',
35
+ writing: 'Finish or discard the comment you’re writing first.',
36
+ editing: 'Finish or discard the comment you’re editing first.',
37
+ };
38
+ /** The empty panel's line when it has a composer. */
39
+ const EMPTY_WITH_COMPOSER = 'Add a comment on the whole artifact, or press the comment button to comment on a specific spot.';
40
+ /**
41
+ * The "All comments" panel, while the comments store says it is open; and the open card of a thread on the whole
42
+ * artifact, which has no pin to open by.
43
+ */
44
+ export function AllComments({ comments, agent, top = PANEL_GAP, hint, fill = false }) {
45
+ const available = comments.store((s) => s.available);
46
+ const open = comments.store((s) => s.listOpen);
47
+ const thread = comments.store((s) => (s.active ? s.threads.find((t) => t.id === s.active && t.messages.length > 0 && comments.isWhole(t)) : undefined));
48
+ if (!available || (!open && !thread))
49
+ return null;
50
+ return (_jsxs(CommentsLayer, { mark: "data-comments-panel-layer", children: [open ? _jsx(Panel, { comments: comments, agent: agent, top: top, hint: hint, fill: fill }) : null, thread ? _jsx(WholeCard, { comments: comments, agent: agent, thread: thread, top: top, beside: open }) : null] }));
51
+ }
52
+ const firstAt = (thread) => thread.messages[0]?.at ?? '';
53
+ function Panel({ comments, agent, top, hint, fill }) {
54
+ const { dark } = useCdsRoot();
55
+ const threads = comments.store((s) => s.threads);
56
+ const showResolved = comments.store((s) => s.showResolved);
57
+ const on = comments.store((s) => s.on);
58
+ const active = comments.store((s) => s.active);
59
+ const draft = comments.store((s) => s.draft);
60
+ const [refused, setRefused] = useState(false);
61
+ const refusal = comments.store(() => comments.composeRefusal());
62
+ const close = () => comments.store.getState().setListOpen(false);
63
+ const all = threads.filter((t) => t.messages.length > 0);
64
+ const whole = comments.wholeArtifact();
65
+ const compose = whole !== null && comments.canComment();
66
+ const composing = compose && draft !== null && comments.isWholeAnchor(draft);
67
+ // The reason is said until it no longer holds.
68
+ if (refused && refusal === null)
69
+ setRefused(false);
70
+ const startComposing = () => setRefused(comments.composeWhole() !== null);
71
+ const shown = all.filter((t) => showResolved || t.status === 'open').sort((a, b) => firstAt(b).localeCompare(firstAt(a)));
72
+ const resolved = all.filter((t) => t.status === 'resolved').length;
73
+ return (_jsxs("section", { "aria-label": "All comments", "data-comments-panel": "", className: cn(panelClass(true), 'fixed flex flex-col text-body text-primary'), style: {
74
+ top,
75
+ right: PANEL_GAP,
76
+ width: PANEL_WIDTH,
77
+ maxWidth: `calc(100vw - ${PANEL_GAP * 2}px)`,
78
+ [fill ? 'height' : 'maxHeight']: `calc(100dvh - ${top + PANEL_GAP}px)`,
79
+ zIndex: 40,
80
+ // Over a host that lets the pointer through (a frame's comments layer), the panel still takes it.
81
+ pointerEvents: 'auto',
82
+ ...panelVars(dark),
83
+ }, onKeyDown: (event) => {
84
+ // A menu's Escape (its popup is a portal, so React bubbles its keys here) closes only the menu.
85
+ const inMenu = event.target instanceof Element && event.target.closest('[data-cds=Menu]');
86
+ if (event.key === 'Escape' && !event.defaultPrevented && !inMenu) {
87
+ event.preventDefault();
88
+ close();
89
+ }
90
+ }, children: [_jsxs("div", { className: "flex shrink-0 items-center gap-xs", style: { padding: '10px 10px 6px 16px' }, children: [_jsx("span", { className: "min-w-0 flex-1 truncate font-medium", children: "All comments" }), _jsx(FilterMenu, { showResolved: showResolved, onShowResolved: (next) => comments.store.getState().setShowResolved(next) }), _jsx(Button, { variant: "ghost", iconOnly: true, "aria-label": "Close", icon: _jsx(Icon, { name: "X", size: "sm" }), onClick: close })] }), compose ? (composing ? (_jsx("div", { "data-comments-composer": "", style: { padding: '0 12px 8px' }, onKeyDown: (event) => {
91
+ // Escape closes the composer, not the panel.
92
+ if (event.key !== 'Escape' || event.defaultPrevented || isComposingKey(event.nativeEvent))
93
+ return;
94
+ event.preventDefault();
95
+ comments.store.getState().setDraft(null);
96
+ }, children: _jsx(CommentComposer, { comments: comments, agent: agent, anchor: draft }) })) : (_jsxs("div", { className: "flex shrink-0 flex-col items-start gap-xs", style: { padding: '0 12px 8px' }, children: [_jsx(Button, { "data-comments-compose": "", "data-size": "sm", variant: "secondary", onClick: startComposing, children: "Add comment" }), refused && refusal ? (_jsx("span", { role: "status", "data-comments-compose-refused": "", className: "text-caption text-secondary", children: COMPOSE_REFUSED[refusal] })) : null] }))) : null, _jsx(SendAll, { comments: comments, agent: agent, threads: all }), _jsxs("div", { className: cn('flex min-h-0 flex-col gap-xs overflow-y-auto [--cds-comment-card-bg:var(--cds-surface-2)]', fill && 'flex-1'), style: { padding: '0 12px 12px' }, children: [all.length === 0 ? (_jsxs("div", { "data-comments-empty": "", className: "flex flex-1 flex-col items-center justify-center gap-xs px-lg text-center", style: { paddingBlock: 'var(--cds-pad-xl)' }, children: [_jsx("span", { className: "text-body font-medium text-secondary", children: "No comments yet" }), _jsx("span", { className: "text-caption text-muted", children: compose ? EMPTY_WITH_COMPOSER : comments.canComment() ? (hint ?? 'Press the comment button, then click anywhere on the artifact to add one.') : 'Only people with comment access can add one.' })] })) : shown.length === 0 ? (_jsxs("span", { "data-comments-filtered-empty": "", className: "px-lg text-center text-caption text-muted", style: { paddingBlock: 'var(--cds-pad-xl)' }, children: ["No open comments.", resolved > 0 ? (_jsxs(_Fragment, { children: [' ', _jsx("button", { type: "button", className: "cds-text-link cds-text-link-underline inline text-inherit", onClick: () => comments.store.getState().setShowResolved(true), children: `Show ${resolved} resolved` })] })) : null] })) : null, shown.map((thread) => (
97
+ // The current row is the thread whose card is showing (out of comment mode no card shows, but for one on the whole artifact).
98
+ _jsx(PanelThread, { comments: comments, agent: agent, thread: thread, current: (on || comments.isWhole(thread)) && active === thread.id }, thread.id)))] })] }));
99
+ }
100
+ function useWindowSize() {
101
+ const [size, setSize] = useState(() => ({ width: window.innerWidth, height: window.innerHeight }));
102
+ useEffect(() => {
103
+ const resize = () => setSize({ width: window.innerWidth, height: window.innerHeight });
104
+ window.addEventListener('resize', resize);
105
+ return () => window.removeEventListener('resize', resize);
106
+ }, []);
107
+ return size;
108
+ }
109
+ /** The open card of a thread on the whole artifact: at the top, just left of the open panel, or at the right edge. */
110
+ function WholeCard({ comments, agent, thread, top, beside }) {
111
+ const viewport = useWindowSize();
112
+ const close = () => comments.store.getState().setActive(null);
113
+ return (_jsx("div", { "data-comments-whole-card": "", style: { position: 'fixed', inset: 0, pointerEvents: 'none', zIndex: 40 }, children: _jsx(CommentPopover, { corner: { x: viewport.width - (beside ? ALL_COMMENTS_RIGHT : PANEL_GAP) - WHOLE_CARD_WIDTH, y: top }, width: WHOLE_CARD_WIDTH, viewport: viewport, onEscape: close, children: (maxHeight) => _jsx(ThreadCard, { comments: comments, agent: agent, thread: thread, state: "ok", maxHeight: maxHeight }) }, thread.id) }));
114
+ }
115
+ function FilterGlyph() {
116
+ return (_jsx("svg", { "data-cds": "Icon", "aria-hidden": true, width: "1em", height: "1em", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: 1.2, strokeLinecap: "round", style: { fontSize: 'calc(1rem * var(--cds-rem-scale,1))' }, children: _jsx("path", { d: "M2.5 4.5h11M4.5 8h7M6.5 11.5h3" }) }));
117
+ }
118
+ function FilterMenu({ showResolved, onShowResolved }) {
119
+ const [open, setOpen] = useLayerMenu();
120
+ return (_jsxs(Menu.Root, { open: open, onOpenChange: setOpen, modal: false, children: [_jsx(Tooltip, { content: "Filter", disabled: open, children: _jsx(Menu.Trigger, { render: _jsx(Button, { variant: "ghost", iconOnly: true, tooltip: false, "aria-label": "Filter", icon: _jsx(FilterGlyph, {}) }) }) }), _jsx(MenuPopup, { align: "end", children: _jsxs(BaseMenu.CheckboxItem, { checked: showResolved, onCheckedChange: onShowResolved, closeOnClick: false, className: cn(MENU_ITEM, 'group/cb text-primary data-[highlighted]:bg-fill-ghost-hover'), children: [_jsx(CheckboxMark, {}), _jsx("span", { className: "min-w-0 flex-1 truncate", children: "Show resolved" })] }) })] }));
121
+ }
122
+ /**
123
+ * "Send all to {agent}": every open thread with something from a person the agent hasn't been handed.
124
+ * Shown to whoever may send once an open thread has a person's comment; right after a send, with nothing new since, it
125
+ * says so instead of sending again.
126
+ */
127
+ function SendAll({ comments, agent, threads }) {
128
+ const [sending, setSending] = useState(false);
129
+ const [justSent, setJustSent] = useState(false);
130
+ const open = threads.filter((t) => t.status === 'open' && t.messages.some((m) => m.author.kind === 'person'));
131
+ if (!comments.canSendToAgent() || !agent.available || open.length === 0)
132
+ return null;
133
+ const nothingNew = !open.some((t) => comments.canSendThread(t));
134
+ const reason = nothingNew ? (justSent ? `These comments were just sent to ${agent.name}.` : `${agent.name} has every comment.`) : undefined;
135
+ return (_jsx("div", { className: "flex shrink-0 flex-col items-end gap-sm", style: { padding: '0 12px 8px' }, children: _jsx(Tooltip, { content: reason, side: "bottom", children: _jsx(Button, { "data-comments-send-all": "", "data-size": "sm", variant: "secondary", busy: sending, "aria-disabled": reason !== undefined || sending || undefined, className: "aria-disabled:opacity-disabled", onClick: () => {
136
+ if (reason !== undefined || sending)
137
+ return;
138
+ setSending(true);
139
+ void comments
140
+ .sendAllToAgent()
141
+ .then(() => setJustSent(true))
142
+ .finally(() => setSending(false));
143
+ }, children: `Send all to ${agent.name}` }) }) }));
144
+ }
145
+ /**
146
+ * A thread in the panel: a flat comment card. Its resolve button and ⋯ menu (Reopen, Delete thread) show while the row
147
+ * is hovered or current; the delete confirmation opens in the row. A click elsewhere on it, the replies line included,
148
+ * shows the thread where it is.
149
+ */
150
+ function PanelThread({ comments, agent, thread, current }) {
151
+ const [confirming, setConfirming] = useState(false);
152
+ const deleting = comments.store((s) => s.writing.includes(`delete:${thread.id}`));
153
+ const change = comments.store((s) => s.statusChange);
154
+ const nameId = useId();
155
+ const first = thread.messages[0];
156
+ const replies = thread.messages.length - 1;
157
+ const resolved = thread.status === 'resolved';
158
+ const commenting = comments.canComment();
159
+ const author = first.author.kind === 'agent' ? first.author.name || agent.name : first.author.name || 'Someone';
160
+ const items = [
161
+ ...(resolved && commenting ? [{ label: 'Reopen', icon: 'Comment', onSelect: () => void comments.resolve(thread.id, false) }] : []),
162
+ ...(comments.canRemove() ? [{ label: 'Delete thread', icon: 'Trash', variant: 'danger', onSelect: () => setConfirming(true) }] : []),
163
+ ];
164
+ return (_jsxs(CommentCard, { variant: "flat", expanded: false, active: current, labelledBy: nameId, onExpand: () => comments.show(thread), className: "rounded", children: [_jsx(Comment, { nameId: nameId, authorName: author, agent: first.author.kind === 'agent', timestamp: _jsxs(_Fragment, { children: [commentAgo(first.at), resolved && ' · Resolved', comments.isWhole(thread) ? _jsx("span", { "data-comment-whole-artifact": "", children: " \u00B7 Whole artifact" }) : null, thread.agent ? (_jsx("span", { role: "img", "aria-label": `Sent to ${agent.name}`, className: "inline-flex", style: { width: 18, height: 18, marginInlineStart: 4, verticalAlign: 'middle', color: 'var(--cds-fill-brand)' }, children: _jsx(RobotGlyph, {}) })) : null] }), confirm: confirming ? (_jsx(DeleteConfirm, { busy: deleting, onCancel: () => setConfirming(false), onDelete: () => void comments.remove(thread.id) })) : undefined, actions: _jsxs(Actions, { placement: current ? 'pinned' : undefined, children: [commenting ? (_jsx(ResolveAction, { resolved: resolved, disabled: change !== null, onResolve: () => void comments.resolve(thread.id, true) })) : null, _jsx(MoreMenu, { items: items, disabled: change !== null && change.id !== thread.id, waitReason: change?.id === thread.id ? WAIT_FOR_STATUS_CHANGE : undefined })] }), children: _jsx("span", { className: "line-clamp-3", children: commentMarkdown(first.text, { flat: true, mentions: sentMentionNames(first.to, agent.name) }) }) }), replies > 0 && !confirming ? (_jsx("button", { type: "button", "data-cds-part": "replies-toggle", className: "self-start text-body font-normal text-accent hover:underline", children: replies === 1 ? '1 reply' : `${replies} replies` })) : null] }));
165
+ }
@@ -0,0 +1,131 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { CommentThread } from '@openartifactsai/runtime';
3
+ import { type MentionsSpec } from './mentions/mention-list.js';
4
+ import { type CommentsController } from './comments.js';
5
+ import { type AnchorState, type Box, type Camera, type PinPlace, type Point } from './pins.js';
6
+ export declare const COMMENT_TARGET = "#ae7303";
7
+ export declare const COMMENT_CURSOR: string;
8
+ /** The agent as comment UI shows it. */
9
+ export interface AgentBadge {
10
+ available: boolean;
11
+ name: string;
12
+ /** false: an idle agent is not woken (Cursor); what is sent waits until the person next talks to it. */
13
+ wakesIdle?: boolean;
14
+ }
15
+ /** A short "5m ago" style time. */
16
+ export declare function timeAgo(iso: string, now?: number): string;
17
+ export interface CommentCaptureProps<A> {
18
+ comments: CommentsController<A>;
19
+ /** Comment mode applies here now (the editor's surface is showing). */
20
+ enabled: boolean;
21
+ /** Space is held: the surface underneath pans. */
22
+ panning?: boolean;
23
+ /** The surface's camera at this moment (read on release, so a live camera mid-glide is fine). */
24
+ camera(): Camera;
25
+ /** What lies under a world point. */
26
+ anchorAt(world: Point): A;
27
+ /** The anchor of a dragged area (world corners). */
28
+ areaAnchor(a: Point, b: Point): A;
29
+ /** The world box of an anchor: outlined under the pointer, so it shows what a click comments on. */
30
+ highlight?(anchor: A): Box | null;
31
+ /** What lies under the resting pointer (`null` once it leaves, drags or the camera moves). */
32
+ onHover?(anchor: A | null): void;
33
+ /** Changes when what lies under the pointer may have changed without it moving (e.g. an artboard finished loading). */
34
+ revision?: unknown;
35
+ }
36
+ /** In comment mode: clicks place threads, drags draw areas. */
37
+ export declare function CommentCapture<A>({ comments, enabled, panning, camera, anchorAt, areaAnchor, highlight, onHover, revision }: CommentCaptureProps<A>): ReactNode;
38
+ type Size = {
39
+ width: number;
40
+ height: number;
41
+ };
42
+ /** Where a pin goes for a point (surface px): below it, or above it when the room is there. */
43
+ export interface PinBox {
44
+ left: number;
45
+ top: number;
46
+ /** Above the point. */
47
+ flip: boolean;
48
+ }
49
+ export declare function pinBox(point: Point, viewport: Size): PinBox;
50
+ export interface CommentPopoverProps {
51
+ /** Beside this pin… */
52
+ pin?: PinBox;
53
+ /** …or with its top-left corner here (a page that marks its threads itself). */
54
+ corner?: Point;
55
+ /** The surface it is kept inside (px, from the layer's top-left corner). */
56
+ viewport: Size;
57
+ /** Its width (px; default 330). */
58
+ width?: number;
59
+ onEscape(): void;
60
+ /** A function gets the height the card may take, and the popover keeps to it. */
61
+ children: ReactNode | ((maxHeight: number) => ReactNode);
62
+ }
63
+ export declare function CommentPopover({ pin, corner, viewport, width: wanted, onEscape, children }: CommentPopoverProps): ReactNode;
64
+ /**
65
+ * Who a box's `@` can name: the agent (when the viewer may send to it), who has the artifact and who is here (asked for
66
+ * at the first `@`), then whoever the threads name. `picked`: whom a message being edited already names.
67
+ */
68
+ export declare function useMentionsSpec<A>(comments: CommentsController<A>, agent: AgentBadge, sendable: boolean, picked?: readonly string[]): MentionsSpec;
69
+ export interface CommentPinsProps<A> {
70
+ comments: CommentsController<A>;
71
+ /** The surface's camera (pins re-place when it changes). */
72
+ camera: Camera;
73
+ /** The surface's size: pins and cards are kept inside it; pins past its edges become "More comments" tabs. */
74
+ viewport: Size;
75
+ /** Where an anchor's pin sits on the surface shown now; `null`: not here (another page, no pin, orphaned). */
76
+ place(anchor: A): PinPlace | null;
77
+ /** The world box an open thread highlights, optionally rotated about its center. */
78
+ highlight?(anchor: A): (Box & {
79
+ rotate?: number;
80
+ }) | null;
81
+ /** What lies under a world point (where a dragged pin lands); without it (and {@link onMove}) pins are not dragged. */
82
+ anchorAt?(world: Point): A;
83
+ /** Pins can be dragged to move their thread (default: when {@link anchorAt} or {@link onMove} is given); a function
84
+ * decides it thread by thread. */
85
+ movable?: boolean | ((thread: CommentThread) => boolean);
86
+ /** A pin dropped at a screen point: the host moves the thread itself (instead of `comments.move(anchorAt(…))`). */
87
+ onMove?(id: string, screen: Point): void;
88
+ agent: AgentBadge;
89
+ /** Changes whenever pins may have moved without threads or camera changing (document edits, layout). */
90
+ revision?: unknown;
91
+ /** Position pins with transforms and keep their world anchors until `place` or `revision` changes. */
92
+ screenTransform?: boolean;
93
+ /** Pins past the surface's edges become "More comments" tabs at that edge (default: on). */
94
+ piles?: boolean;
95
+ /** Bars over the surface's edges (px): a toolbar at its top or its bottom, which the tabs keep clear of. */
96
+ insets?: {
97
+ top?: number;
98
+ bottom?: number;
99
+ };
100
+ }
101
+ export declare function CommentPins<A>({ comments, camera, viewport, place, highlight, anchorAt, movable, onMove, agent, revision, screenTransform, piles, insets }: CommentPinsProps<A>): ReactNode;
102
+ export interface ThreadCardProps<A> {
103
+ comments: CommentsController<A>;
104
+ agent: AgentBadge;
105
+ thread: CommentThread;
106
+ /** How its anchor resolves (default: asked of the controller); a note under the first comment says what changed. */
107
+ state?: AnchorState;
108
+ /** The comments scroll past this height; the reply box stays under them. */
109
+ maxHeight?: number;
110
+ /** The close button (default: closes the card). */
111
+ onClose?(): void;
112
+ }
113
+ export declare function ThreadCard<A>(props: ThreadCardProps<A>): ReactNode;
114
+ export interface CommentComposerProps<A> {
115
+ comments: CommentsController<A>;
116
+ agent: AgentBadge;
117
+ /** What the new thread is on. */
118
+ anchor: A;
119
+ /** Escape and Cancel (default: drops the draft). */
120
+ onCancel?(): void;
121
+ }
122
+ export declare function CommentComposer<A>(props: CommentComposerProps<A>): ReactNode;
123
+ export interface CommentsButtonProps<A> {
124
+ comments: CommentsController<A>;
125
+ /** The comment-mode key its tooltip names (default C). */
126
+ shortcut?: string;
127
+ /** The tooltips' side (default: below, for a bar at the top). */
128
+ side?: 'top' | 'bottom';
129
+ }
130
+ export declare function CommentsButton<A>({ comments, shortcut, side }: CommentsButtonProps<A>): ReactNode;
131
+ export {};