oneslash-design-system 2.16.0 → 2.17.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/README.md +1 -1
- package/dist/DESIGN.md +26 -3
- package/dist/cases/accept-invite/signed-in.jsx +1 -1
- package/dist/cases/accept-invite/signed-out.jsx +1 -1
- package/dist/cases/accept-invite.md +2 -2
- package/dist/cases/agent-options/cards.d.ts +1 -0
- package/dist/cases/agent-options/cards.jsx +91 -0
- package/dist/cases/agent-options.md +168 -0
- package/dist/cases/agent-pending-reply/steps.d.ts +1 -0
- package/dist/cases/agent-pending-reply/steps.jsx +149 -0
- package/dist/cases/agent-pending-reply/streaming.d.ts +1 -0
- package/dist/cases/agent-pending-reply/streaming.jsx +146 -0
- package/dist/cases/agent-pending-reply.md +432 -0
- package/dist/cases/agent-plan-proposal/changes.d.ts +1 -0
- package/dist/cases/agent-plan-proposal/changes.jsx +224 -0
- package/dist/cases/agent-plan-proposal/steps.d.ts +1 -0
- package/dist/cases/agent-plan-proposal/steps.jsx +211 -0
- package/dist/cases/agent-plan-proposal.md +656 -0
- package/dist/cases/agent-question/choices.d.ts +1 -0
- package/dist/cases/agent-question/choices.jsx +132 -0
- package/dist/cases/agent-question/free-text.d.ts +1 -0
- package/dist/cases/agent-question/free-text.jsx +81 -0
- package/dist/cases/agent-question.md +338 -0
- package/dist/cases/agent-shows-sources.md +2 -2
- package/dist/cases/artifact-card/card.d.ts +1 -0
- package/dist/cases/artifact-card/card.jsx +45 -0
- package/dist/cases/artifact-card.md +103 -0
- package/dist/cases/composer-limit/notice-with-action.d.ts +1 -0
- package/dist/cases/composer-limit/notice-with-action.jsx +87 -0
- package/dist/cases/composer-limit/notice.d.ts +1 -0
- package/dist/cases/composer-limit/notice.jsx +84 -0
- package/dist/cases/composer-limit.md +286 -0
- package/dist/cases/conversation-starters/chips.d.ts +1 -0
- package/dist/cases/conversation-starters/chips.jsx +69 -0
- package/dist/cases/conversation-starters/none.d.ts +1 -0
- package/dist/cases/conversation-starters/none.jsx +45 -0
- package/dist/cases/conversation-starters.md +208 -0
- package/dist/cases/mention-list/in-composer.d.ts +1 -0
- package/dist/cases/mention-list/in-composer.jsx +169 -0
- package/dist/cases/mention-list.md +252 -0
- package/dist/cases/message-actions/hover-toolbar.d.ts +1 -0
- package/dist/cases/message-actions/hover-toolbar.jsx +229 -0
- package/dist/cases/message-actions/menu.d.ts +1 -0
- package/dist/cases/message-actions/menu.jsx +258 -0
- package/dist/cases/message-actions.md +651 -0
- package/dist/cases/message-attachments/in-composer.d.ts +1 -0
- package/dist/cases/message-attachments/in-composer.jsx +134 -0
- package/dist/cases/message-attachments/in-message.d.ts +1 -0
- package/dist/cases/message-attachments/in-message.jsx +46 -0
- package/dist/cases/message-attachments.md +310 -0
- package/dist/cases/message-composer/plain.d.ts +1 -0
- package/dist/cases/message-composer/plain.jsx +57 -0
- package/dist/cases/message-composer/with-tools.d.ts +1 -0
- package/dist/cases/message-composer/with-tools.jsx +182 -0
- package/dist/cases/message-composer.md +356 -0
- package/dist/cases/message-edit/in-place.d.ts +1 -0
- package/dist/cases/message-edit/in-place.jsx +99 -0
- package/dist/cases/message-edit.md +179 -0
- package/dist/cases/message-reactions/chips.d.ts +1 -0
- package/dist/cases/message-reactions/chips.jsx +118 -0
- package/dist/cases/message-reactions/quick-pick.d.ts +1 -0
- package/dist/cases/message-reactions/quick-pick.jsx +155 -0
- package/dist/cases/message-reactions.md +371 -0
- package/dist/cases/message-row/grouped.d.ts +1 -0
- package/dist/cases/message-row/grouped.jsx +56 -0
- package/dist/cases/message-row/person-and-agent.d.ts +1 -0
- package/dist/cases/message-row/person-and-agent.jsx +41 -0
- package/dist/cases/message-row.md +189 -0
- package/dist/cases/reply-feedback/thumbs.d.ts +1 -0
- package/dist/cases/reply-feedback/thumbs.jsx +191 -0
- package/dist/cases/reply-feedback/with-reason.d.ts +1 -0
- package/dist/cases/reply-feedback/with-reason.jsx +221 -0
- package/dist/cases/reply-feedback.md +552 -0
- package/dist/cases/reply-sources/cards.d.ts +1 -0
- package/dist/cases/reply-sources/cards.jsx +83 -0
- package/dist/cases/reply-sources/tag-only.d.ts +1 -0
- package/dist/cases/reply-sources/tag-only.jsx +45 -0
- package/dist/cases/reply-sources.md +247 -0
- package/dist/cases/slash-command-list/in-composer.d.ts +1 -0
- package/dist/cases/slash-command-list/in-composer.jsx +162 -0
- package/dist/cases/slash-command-list.md +247 -0
- package/dist/cases/success-feedback.md +1 -1
- package/dist/cases/typing-and-status/line.d.ts +1 -0
- package/dist/cases/typing-and-status/line.jsx +50 -0
- package/dist/cases/typing-and-status.md +96 -0
- package/dist/cases.json +1276 -14
- package/dist/components/button.d.ts +3 -2
- package/dist/components/button.jsx +9 -7
- package/dist/components/composer.d.ts +74 -0
- package/dist/components/composer.jsx +122 -0
- package/dist/components/fileChip.d.ts +33 -0
- package/dist/components/fileChip.jsx +61 -0
- package/dist/components/iconButton.d.ts +3 -3
- package/dist/components/iconButton.jsx +9 -7
- package/dist/components/layout.d.ts +7 -1
- package/dist/components/layout.jsx +5 -2
- package/dist/components/menu.d.ts +21 -0
- package/dist/components/menu.jsx +27 -3
- package/dist/components/menuItem.d.ts +9 -1
- package/dist/components/menuItem.jsx +5 -4
- package/dist/components/message.d.ts +28 -0
- package/dist/components/message.jsx +25 -0
- package/dist/components/paragraph.d.ts +3 -1
- package/dist/components/paragraph.jsx +2 -2
- package/dist/components/popover.d.ts +7 -1
- package/dist/components/popover.jsx +35 -9
- package/dist/components/radioGroup.d.ts +8 -1
- package/dist/components/radioGroup.jsx +19 -8
- package/dist/components/sourceCard.d.ts +23 -0
- package/dist/components/sourceCard.jsx +56 -0
- package/dist/components/stepList.d.ts +17 -0
- package/dist/components/stepList.jsx +79 -0
- package/dist/components/tag.d.ts +9 -1
- package/dist/components/tag.jsx +6 -4
- package/dist/components/textarea.jsx +3 -18
- package/dist/components/userImage.d.ts +9 -1
- package/dist/components/userImage.jsx +10 -3
- package/dist/internal/autoGrow.d.ts +11 -0
- package/dist/internal/autoGrow.js +28 -0
- package/dist/internal/composer.d.ts +16 -0
- package/dist/internal/composer.js +18 -0
- package/dist/internal/menu.d.ts +6 -0
- package/dist/internal/menu.js +31 -0
- package/dist/native-mapping.json +32 -1
- package/dist/stories/Button.stories.d.ts +1 -0
- package/dist/stories/Button.stories.jsx +17 -1
- package/dist/stories/Cases.generated.stories.d.ts +30 -0
- package/dist/stories/Cases.generated.stories.jsx +60 -0
- package/dist/stories/Composer.stories.d.ts +23 -0
- package/dist/stories/Composer.stories.jsx +121 -0
- package/dist/stories/FileChip.stories.d.ts +7 -0
- package/dist/stories/FileChip.stories.jsx +35 -0
- package/dist/stories/IconButton.stories.d.ts +1 -0
- package/dist/stories/IconButton.stories.jsx +18 -1
- package/dist/stories/Menu.stories.d.ts +4 -0
- package/dist/stories/Menu.stories.jsx +46 -1
- package/dist/stories/MenuItem.stories.d.ts +1 -0
- package/dist/stories/MenuItem.stories.jsx +8 -0
- package/dist/stories/Message.stories.d.ts +10 -0
- package/dist/stories/Message.stories.jsx +77 -0
- package/dist/stories/PageComponents.stories.d.ts +1 -0
- package/dist/stories/PageComponents.stories.jsx +21 -0
- package/dist/stories/RadioGroup.stories.d.ts +2 -0
- package/dist/stories/RadioGroup.stories.jsx +40 -1
- package/dist/stories/SourceCard.stories.d.ts +8 -0
- package/dist/stories/SourceCard.stories.jsx +33 -0
- package/dist/stories/StepList.stories.d.ts +8 -0
- package/dist/stories/StepList.stories.jsx +35 -0
- package/dist/stories/UserImage.stories.d.ts +2 -0
- package/dist/stories/UserImage.stories.jsx +19 -0
- package/package.json +4 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function MessageActionsHoverToolbar(): import("react").JSX.Element;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
+
if (ar || !(i in from)) {
|
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
+
ar[i] = from[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
};
|
|
22
|
+
import { useEffect, useRef, useState } from 'react';
|
|
23
|
+
import { Bot } from 'lucide-react';
|
|
24
|
+
import Toaster, { toast, dismissToast } from '../../components/toaster';
|
|
25
|
+
import Message from '../../components/message';
|
|
26
|
+
import UserImage from '../../components/userImage';
|
|
27
|
+
import Tag from '../../components/tag';
|
|
28
|
+
import TimeStamp from '../../components/timeStamp';
|
|
29
|
+
import Heading from '../../components/heading';
|
|
30
|
+
import Paragraph from '../../components/paragraph';
|
|
31
|
+
import Composer from '../../components/composer';
|
|
32
|
+
import Button from '../../components/button';
|
|
33
|
+
import IconButton from '../../components/iconButton';
|
|
34
|
+
import Tooltip from '../../components/tooltip';
|
|
35
|
+
import { Center, Cluster, Stack } from '../../components/layout';
|
|
36
|
+
// A real app reads this from the session.
|
|
37
|
+
var me = 'Dana Lee';
|
|
38
|
+
var firstThread = [
|
|
39
|
+
{ id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The press kit is in the shared folder.' },
|
|
40
|
+
{ id: 'm2', from: 'Acme Agent', agent: true, at: new Date('2025-01-15T11:41:00Z'), text: 'I checked the press kit. Two images have no alt text.' },
|
|
41
|
+
{ id: 'm3', from: me, at: new Date('2025-01-15T11:44:00Z'), text: 'Thanks. I will add the alt text today.' },
|
|
42
|
+
];
|
|
43
|
+
export default function MessageActionsHoverToolbar() {
|
|
44
|
+
var _a = useState(firstThread), thread = _a[0], setThread = _a[1];
|
|
45
|
+
var _b = useState(''), text = _b[0], setText = _b[1];
|
|
46
|
+
var _c = useState(null), copiedId = _c[0], setCopiedId = _c[1];
|
|
47
|
+
var _d = useState(null), editingId = _d[0], setEditingId = _d[1];
|
|
48
|
+
var _e = useState(''), draft = _e[0], setDraft = _e[1];
|
|
49
|
+
var _f = useState(false), saving = _f[0], setSaving = _f[1];
|
|
50
|
+
// The row whose footer asks to confirm the delete. One row at a time.
|
|
51
|
+
var _g = useState(null), confirmingId = _g[0], setConfirmingId = _g[1];
|
|
52
|
+
var _h = useState(false), deleting = _h[0], setDeleting = _h[1];
|
|
53
|
+
var copyTimer = useRef();
|
|
54
|
+
// One timer per request, so a save and a delete never clear each other's.
|
|
55
|
+
var saveTimer = useRef();
|
|
56
|
+
var deleteTimer = useRef();
|
|
57
|
+
var toastIds = useRef([]);
|
|
58
|
+
var field = useRef(null);
|
|
59
|
+
var box = useRef(null);
|
|
60
|
+
var cancelDelete = useRef(null);
|
|
61
|
+
// Each row's buttons by row id, so focus can move to one when the thing that had it is gone.
|
|
62
|
+
var reactButtons = useRef({});
|
|
63
|
+
var editButtons = useRef({});
|
|
64
|
+
var deleteButtons = useRef({});
|
|
65
|
+
// Where focus goes after the next render, once the element it goes to is on screen.
|
|
66
|
+
var focusNext = useRef();
|
|
67
|
+
// The clipboard answers later; by then the example may be gone.
|
|
68
|
+
var mounted = useRef(true);
|
|
69
|
+
// On unmount it stops the timers and closes every toast it opened.
|
|
70
|
+
useEffect(function () { return function () {
|
|
71
|
+
mounted.current = false;
|
|
72
|
+
clearTimeout(copyTimer.current);
|
|
73
|
+
clearTimeout(saveTimer.current);
|
|
74
|
+
clearTimeout(deleteTimer.current);
|
|
75
|
+
toastIds.current.forEach(function (id) { return dismissToast(id); });
|
|
76
|
+
toastIds.current = [];
|
|
77
|
+
}; }, []);
|
|
78
|
+
useEffect(function () {
|
|
79
|
+
var move = focusNext.current;
|
|
80
|
+
focusNext.current = undefined;
|
|
81
|
+
move === null || move === void 0 ? void 0 : move();
|
|
82
|
+
});
|
|
83
|
+
var editingRow = thread.find(function (m) { return m.id === editingId; });
|
|
84
|
+
var canSave = !!editingRow && draft.trim() !== '' && draft.trim() !== editingRow.text;
|
|
85
|
+
// A real app opens its reaction picker here; this one adds or removes a thumbs-up.
|
|
86
|
+
function react(id) {
|
|
87
|
+
setThread(function (rows) { return rows.map(function (m) { return (m.id === id ? __assign(__assign({}, m), { reacted: !m.reacted }) : m); }); });
|
|
88
|
+
}
|
|
89
|
+
function copy(m) {
|
|
90
|
+
var _a;
|
|
91
|
+
(_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText(m.text).then(function () {
|
|
92
|
+
if (!mounted.current)
|
|
93
|
+
return;
|
|
94
|
+
setCopiedId(m.id);
|
|
95
|
+
clearTimeout(copyTimer.current);
|
|
96
|
+
copyTimer.current = setTimeout(function () { return setCopiedId(null); }, 2000);
|
|
97
|
+
}, function () { });
|
|
98
|
+
}
|
|
99
|
+
// The field takes focus, with the caret after the text.
|
|
100
|
+
function startEditing(m) {
|
|
101
|
+
setDraft(m.text);
|
|
102
|
+
setEditingId(m.id);
|
|
103
|
+
focusNext.current = function () {
|
|
104
|
+
var _a, _b, _c, _d;
|
|
105
|
+
var end = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.value.length) !== null && _b !== void 0 ? _b : 0;
|
|
106
|
+
(_c = field.current) === null || _c === void 0 ? void 0 : _c.focus();
|
|
107
|
+
(_d = field.current) === null || _d === void 0 ? void 0 : _d.setSelectionRange(end, end);
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
// The field that had focus is gone, so focus goes to the row's Edit button.
|
|
111
|
+
function stopEditing(id) {
|
|
112
|
+
setEditingId(null);
|
|
113
|
+
focusNext.current = function () { var _a; return (_a = editButtons.current[id]) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
114
|
+
}
|
|
115
|
+
function cancelEditing() {
|
|
116
|
+
if (saving || !editingId)
|
|
117
|
+
return;
|
|
118
|
+
stopEditing(editingId);
|
|
119
|
+
}
|
|
120
|
+
function save() {
|
|
121
|
+
if (saving || !canSave || !editingId)
|
|
122
|
+
return;
|
|
123
|
+
var id = editingId;
|
|
124
|
+
var value = draft.trim();
|
|
125
|
+
setSaving(true);
|
|
126
|
+
// Stands in for the request to the server.
|
|
127
|
+
saveTimer.current = setTimeout(function () {
|
|
128
|
+
setSaving(false);
|
|
129
|
+
setThread(function (rows) { return rows.map(function (m) { return (m.id === id ? __assign(__assign({}, m), { text: value, edited: true }) : m); }); });
|
|
130
|
+
stopEditing(id);
|
|
131
|
+
}, 1200);
|
|
132
|
+
}
|
|
133
|
+
// The confirm opens in the row's footer, with focus on 'Cancel'.
|
|
134
|
+
function askToDelete(id) {
|
|
135
|
+
setConfirmingId(id);
|
|
136
|
+
focusNext.current = function () { var _a; return (_a = cancelDelete.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
137
|
+
}
|
|
138
|
+
// 'Cancel' goes away with the confirm, so focus goes back to the row's Delete button.
|
|
139
|
+
function keepMessage() {
|
|
140
|
+
if (deleting || !confirmingId)
|
|
141
|
+
return;
|
|
142
|
+
var id = confirmingId;
|
|
143
|
+
setConfirmingId(null);
|
|
144
|
+
focusNext.current = function () { var _a; return (_a = deleteButtons.current[id]) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
145
|
+
}
|
|
146
|
+
function confirmDelete() {
|
|
147
|
+
if (deleting || !confirmingId)
|
|
148
|
+
return;
|
|
149
|
+
var id = confirmingId;
|
|
150
|
+
var next = thread[thread.findIndex(function (m) { return m.id === id; }) + 1];
|
|
151
|
+
setDeleting(true);
|
|
152
|
+
// Stands in for the request to the server.
|
|
153
|
+
deleteTimer.current = setTimeout(function () {
|
|
154
|
+
setDeleting(false);
|
|
155
|
+
setConfirmingId(null);
|
|
156
|
+
setThread(function (rows) { return rows.filter(function (m) { return m.id !== id; }); });
|
|
157
|
+
toastIds.current.push(toast({ type: 'success', message: 'Message deleted.' }));
|
|
158
|
+
// The row is gone: focus goes to the next row's first action, or to the message box when none follows.
|
|
159
|
+
// If the next row's button is not on screen, focus goes to the message box.
|
|
160
|
+
focusNext.current = function () { var _a, _b; return (_b = ((_a = (next ? reactButtons.current[next.id] : null)) !== null && _a !== void 0 ? _a : box.current)) === null || _b === void 0 ? void 0 : _b.focus(); };
|
|
161
|
+
}, 1200);
|
|
162
|
+
}
|
|
163
|
+
function send() {
|
|
164
|
+
// A real app sends the message to the server here and shows it at once.
|
|
165
|
+
setThread(function (rows) { return __spreadArray(__spreadArray([], rows, true), [{ id: "m".concat(rows.length + 1), from: me, at: new Date(), text: text.trim() }], false); });
|
|
166
|
+
setText('');
|
|
167
|
+
}
|
|
168
|
+
return (<Center width="page">
|
|
169
|
+
{/* A real app mounts one Toaster near its root. */}
|
|
170
|
+
<Toaster />
|
|
171
|
+
<Stack gap="large">
|
|
172
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
173
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
174
|
+
<Stack gap="small">
|
|
175
|
+
{thread.map(function (m) {
|
|
176
|
+
var own = m.from === me;
|
|
177
|
+
var editing = m.id === editingId;
|
|
178
|
+
var confirming = m.id === confirmingId;
|
|
179
|
+
return (<Message key={m.id} aria-label={m.agent ? "".concat(m.from, ", agent") : m.from} avatar={m.agent ? <UserImage userHandle={m.from} icon={Bot} decorative/> : <UserImage userHandle={m.from} decorative/>} name={m.from} meta={<>
|
|
180
|
+
{m.agent && <Tag variant="contained" size="small" label="Agent"/>}
|
|
181
|
+
<TimeStamp createdAt={m.at} dateFormat="absolute" data="time"/>
|
|
182
|
+
{m.agent && <Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>}
|
|
183
|
+
{m.edited && <Paragraph size="caption" tone="secondary" measure="none">(edited)</Paragraph>}
|
|
184
|
+
</>} footer={m.reacted || confirming ? (<Stack gap="small">
|
|
185
|
+
{m.reacted && <Tag variant="contained" size="small" state="selected" label="👍 1" aria-label="Thumbs up, 1 reaction"/>}
|
|
186
|
+
{confirming && (
|
|
187
|
+
// The confirm is in the row, as the case 'Delete confirm' says for a row in a dense list.
|
|
188
|
+
<Stack gap="small">
|
|
189
|
+
<Paragraph size="body2" measure="none">Delete this message?</Paragraph>
|
|
190
|
+
<Cluster gap="small">
|
|
191
|
+
<Button ref={cancelDelete} size="small" type="tertiary" state={deleting ? 'disabled' : 'enabled'} label="Cancel" aria-label="Cancel deleting your message" onClickButton={keepMessage}/>
|
|
192
|
+
<Button size="small" type="primary" color="danger" state="enabled" label="Delete" aria-label="Delete this message" loading={deleting} onClickButton={confirmDelete}/>
|
|
193
|
+
</Cluster>
|
|
194
|
+
</Stack>)}
|
|
195
|
+
</Stack>) : undefined}
|
|
196
|
+
// Shown while the pointer is on the row or focus is in it, and always on a touch screen.
|
|
197
|
+
actions={editing || confirming ? undefined : (<>
|
|
198
|
+
<Tooltip title="Add reaction">
|
|
199
|
+
<IconButton ref={function (el) { reactButtons.current[m.id] = el; }} color="iconOnly" state="enabled" size="small" iconName="SmilePlus" ariaLabel={"Add reaction to message from ".concat(m.from)} onClick={function () { return react(m.id); }}/>
|
|
200
|
+
</Tooltip>
|
|
201
|
+
<Tooltip title={copiedId === m.id ? 'Copied' : 'Copy'}>
|
|
202
|
+
<IconButton color="iconOnly" state="enabled" size="small" iconName={copiedId === m.id ? 'Check' : 'Copy'} ariaLabel={copiedId === m.id ? 'Copied' : "Copy message from ".concat(m.from)} onClick={function () { return copy(m); }}/>
|
|
203
|
+
</Tooltip>
|
|
204
|
+
{own && (<Tooltip title="Edit">
|
|
205
|
+
<IconButton ref={function (el) { editButtons.current[m.id] = el; }} color="iconOnly" state="enabled" size="small" iconName="Pencil" ariaLabel="Edit your message" onClick={function () { return startEditing(m); }}/>
|
|
206
|
+
</Tooltip>)}
|
|
207
|
+
{own && (<Tooltip title="Delete">
|
|
208
|
+
<IconButton ref={function (el) { deleteButtons.current[m.id] = el; }} color="iconOnly" state="enabled" size="small" iconName="Trash2" ariaLabel="Delete your message" onClick={function () { return askToDelete(m.id); }}/>
|
|
209
|
+
</Tooltip>)}
|
|
210
|
+
</>)}>
|
|
211
|
+
{editing ? (
|
|
212
|
+
// Edit works as the case 'Message edit' says.
|
|
213
|
+
<Composer ref={field} id="message-actions-hover-edit" aria-label="Edit message" value={draft} onChange={setDraft} onSubmit={save} canSubmit={canSave} disabled={saving} onKeyDown={function (e) {
|
|
214
|
+
if (e.key === 'Escape') {
|
|
215
|
+
e.preventDefault();
|
|
216
|
+
e.stopPropagation();
|
|
217
|
+
cancelEditing();
|
|
218
|
+
}
|
|
219
|
+
}} actions={<Cluster gap="small">
|
|
220
|
+
<Button size="small" type="tertiary" state={saving ? 'disabled' : 'enabled'} label="Cancel" onClickButton={cancelEditing}/>
|
|
221
|
+
<Button size="small" type="primary" state={canSave ? 'enabled' : 'disabled'} label="Save" loading={saving} onClickButton={save}/>
|
|
222
|
+
</Cluster>}/>) : (<Paragraph measure="none">{m.text}</Paragraph>)}
|
|
223
|
+
</Message>);
|
|
224
|
+
})}
|
|
225
|
+
</Stack>
|
|
226
|
+
<Composer ref={box} id="message-actions-hover-message" aria-label="Message" placeholder="Message the team" value={text} onChange={setText} onSubmit={send}/>
|
|
227
|
+
</Stack>
|
|
228
|
+
</Center>);
|
|
229
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function MessageActionsMenu(): import("react").JSX.Element;
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
+
if (ar || !(i in from)) {
|
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
+
ar[i] = from[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
};
|
|
22
|
+
import { useEffect, useRef, useState } from 'react';
|
|
23
|
+
import { Bot } from 'lucide-react';
|
|
24
|
+
import Toaster, { toast, dismissToast } from '../../components/toaster';
|
|
25
|
+
import Message from '../../components/message';
|
|
26
|
+
import UserImage from '../../components/userImage';
|
|
27
|
+
import Tag from '../../components/tag';
|
|
28
|
+
import TimeStamp from '../../components/timeStamp';
|
|
29
|
+
import Heading from '../../components/heading';
|
|
30
|
+
import Paragraph from '../../components/paragraph';
|
|
31
|
+
import Composer from '../../components/composer';
|
|
32
|
+
import Button from '../../components/button';
|
|
33
|
+
import IconButton from '../../components/iconButton';
|
|
34
|
+
import Tooltip from '../../components/tooltip';
|
|
35
|
+
import Popover from '../../components/popover';
|
|
36
|
+
import Menu from '../../components/menu';
|
|
37
|
+
import MenuItem from '../../components/menuItem';
|
|
38
|
+
import { Center, Cluster, Stack } from '../../components/layout';
|
|
39
|
+
// A real app reads this from the session.
|
|
40
|
+
var me = 'Dana Lee';
|
|
41
|
+
var firstThread = [
|
|
42
|
+
{ id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The press kit is in the shared folder.' },
|
|
43
|
+
{ id: 'm2', from: 'Acme Agent', agent: true, at: new Date('2025-01-15T11:41:00Z'), text: 'I checked the press kit. Two images have no alt text.' },
|
|
44
|
+
{ id: 'm3', from: me, at: new Date('2025-01-15T11:44:00Z'), text: 'Thanks. I will add the alt text today.' },
|
|
45
|
+
];
|
|
46
|
+
export default function MessageActionsMenu() {
|
|
47
|
+
var _a = useState(firstThread), thread = _a[0], setThread = _a[1];
|
|
48
|
+
var _b = useState(''), text = _b[0], setText = _b[1];
|
|
49
|
+
// The row whose menu is open, and the More button it opens from. Both stay set while the menu fades out.
|
|
50
|
+
var _c = useState(null), menuRow = _c[0], setMenuRow = _c[1];
|
|
51
|
+
var _d = useState(null), menuAnchor = _d[0], setMenuAnchor = _d[1];
|
|
52
|
+
var _e = useState(false), menuOpen = _e[0], setMenuOpen = _e[1];
|
|
53
|
+
var _f = useState(null), editingId = _f[0], setEditingId = _f[1];
|
|
54
|
+
var _g = useState(''), draft = _g[0], setDraft = _g[1];
|
|
55
|
+
var _h = useState(false), saving = _h[0], setSaving = _h[1];
|
|
56
|
+
// The row whose footer asks to confirm the delete. One row at a time.
|
|
57
|
+
var _j = useState(null), confirmingId = _j[0], setConfirmingId = _j[1];
|
|
58
|
+
var _k = useState(false), deleting = _k[0], setDeleting = _k[1];
|
|
59
|
+
// One timer per request, so a save and a delete never clear each other's.
|
|
60
|
+
var saveTimer = useRef();
|
|
61
|
+
var deleteTimer = useRef();
|
|
62
|
+
var toastIds = useRef([]);
|
|
63
|
+
var field = useRef(null);
|
|
64
|
+
var box = useRef(null);
|
|
65
|
+
var cancelDelete = useRef(null);
|
|
66
|
+
// Each row's More button by row id, so focus can move to one when the thing that had it is gone.
|
|
67
|
+
var moreButtons = useRef({});
|
|
68
|
+
// Where focus goes after the next render, once the element it goes to is on screen.
|
|
69
|
+
var focusNext = useRef();
|
|
70
|
+
// The clipboard answers later; by then the example may be gone.
|
|
71
|
+
var mounted = useRef(true);
|
|
72
|
+
// On unmount it stops the timers and closes every toast it opened.
|
|
73
|
+
useEffect(function () { return function () {
|
|
74
|
+
mounted.current = false;
|
|
75
|
+
clearTimeout(saveTimer.current);
|
|
76
|
+
clearTimeout(deleteTimer.current);
|
|
77
|
+
toastIds.current.forEach(function (id) { return dismissToast(id); });
|
|
78
|
+
toastIds.current = [];
|
|
79
|
+
}; }, []);
|
|
80
|
+
useEffect(function () {
|
|
81
|
+
var move = focusNext.current;
|
|
82
|
+
focusNext.current = undefined;
|
|
83
|
+
move === null || move === void 0 ? void 0 : move();
|
|
84
|
+
});
|
|
85
|
+
var editingRow = thread.find(function (m) { return m.id === editingId; });
|
|
86
|
+
var canSave = !!editingRow && draft.trim() !== '' && draft.trim() !== editingRow.text;
|
|
87
|
+
// A real app opens its reaction picker here; this one adds or removes a thumbs-up.
|
|
88
|
+
function react(m) {
|
|
89
|
+
setThread(function (rows) { return rows.map(function (r) { return (r.id === m.id ? __assign(__assign({}, r), { reacted: !r.reacted }) : r); }); });
|
|
90
|
+
}
|
|
91
|
+
// The menu closes when an item is chosen, so a copy shows a toast rather than a check.
|
|
92
|
+
function copy(m) {
|
|
93
|
+
var _a;
|
|
94
|
+
(_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText(m.text).then(function () {
|
|
95
|
+
if (!mounted.current)
|
|
96
|
+
return;
|
|
97
|
+
toastIds.current.push(toast({ type: 'success', message: 'Message copied.' }));
|
|
98
|
+
}, function () { });
|
|
99
|
+
}
|
|
100
|
+
// A real app sends the task to the server here.
|
|
101
|
+
function createTask(m) {
|
|
102
|
+
toastIds.current.push(toast({ type: 'success', message: "Task created from ".concat(m.from, "'s message.") }));
|
|
103
|
+
}
|
|
104
|
+
// A real app asks for a reason in a Modal, then sends the report.
|
|
105
|
+
function report(m) {
|
|
106
|
+
toastIds.current.push(toast({ type: 'success', message: "".concat(m.from, "'s message reported to the workspace admins.") }));
|
|
107
|
+
}
|
|
108
|
+
function openMenu(m, anchor) {
|
|
109
|
+
if (menuOpen && (menuRow === null || menuRow === void 0 ? void 0 : menuRow.id) === m.id) {
|
|
110
|
+
closeMenu();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
setMenuRow(m);
|
|
114
|
+
setMenuAnchor(anchor);
|
|
115
|
+
setMenuOpen(true);
|
|
116
|
+
}
|
|
117
|
+
// Escape, a click outside and every item close the menu. Popover's returnFocus gives focus back to More.
|
|
118
|
+
function closeMenu() {
|
|
119
|
+
setMenuOpen(false);
|
|
120
|
+
}
|
|
121
|
+
function choose(action) {
|
|
122
|
+
if (!menuRow)
|
|
123
|
+
return;
|
|
124
|
+
var m = menuRow;
|
|
125
|
+
closeMenu();
|
|
126
|
+
action(m);
|
|
127
|
+
}
|
|
128
|
+
// The field takes focus, with the caret after the text.
|
|
129
|
+
function startEditing(m) {
|
|
130
|
+
setDraft(m.text);
|
|
131
|
+
setEditingId(m.id);
|
|
132
|
+
focusNext.current = function () {
|
|
133
|
+
var _a, _b, _c, _d;
|
|
134
|
+
var end = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.value.length) !== null && _b !== void 0 ? _b : 0;
|
|
135
|
+
(_c = field.current) === null || _c === void 0 ? void 0 : _c.focus();
|
|
136
|
+
(_d = field.current) === null || _d === void 0 ? void 0 : _d.setSelectionRange(end, end);
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
// The field that had focus is gone, so focus goes to the row's More button.
|
|
140
|
+
function stopEditing(id) {
|
|
141
|
+
setEditingId(null);
|
|
142
|
+
focusNext.current = function () { var _a; return (_a = moreButtons.current[id]) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
143
|
+
}
|
|
144
|
+
function cancelEditing() {
|
|
145
|
+
if (saving || !editingId)
|
|
146
|
+
return;
|
|
147
|
+
stopEditing(editingId);
|
|
148
|
+
}
|
|
149
|
+
function save() {
|
|
150
|
+
if (saving || !canSave || !editingId)
|
|
151
|
+
return;
|
|
152
|
+
var id = editingId;
|
|
153
|
+
var value = draft.trim();
|
|
154
|
+
setSaving(true);
|
|
155
|
+
// Stands in for the request to the server.
|
|
156
|
+
saveTimer.current = setTimeout(function () {
|
|
157
|
+
setSaving(false);
|
|
158
|
+
setThread(function (rows) { return rows.map(function (m) { return (m.id === id ? __assign(__assign({}, m), { text: value, edited: true }) : m); }); });
|
|
159
|
+
stopEditing(id);
|
|
160
|
+
}, 1200);
|
|
161
|
+
}
|
|
162
|
+
// The confirm opens in the row's footer, with focus on 'Cancel'.
|
|
163
|
+
function askToDelete(m) {
|
|
164
|
+
setConfirmingId(m.id);
|
|
165
|
+
focusNext.current = function () { var _a; return (_a = cancelDelete.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
166
|
+
}
|
|
167
|
+
// 'Cancel' goes away with the confirm, so focus goes back to the row's More button.
|
|
168
|
+
function keepMessage() {
|
|
169
|
+
if (deleting || !confirmingId)
|
|
170
|
+
return;
|
|
171
|
+
var id = confirmingId;
|
|
172
|
+
setConfirmingId(null);
|
|
173
|
+
focusNext.current = function () { var _a; return (_a = moreButtons.current[id]) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
174
|
+
}
|
|
175
|
+
function confirmDelete() {
|
|
176
|
+
if (deleting || !confirmingId)
|
|
177
|
+
return;
|
|
178
|
+
var id = confirmingId;
|
|
179
|
+
var next = thread[thread.findIndex(function (m) { return m.id === id; }) + 1];
|
|
180
|
+
setDeleting(true);
|
|
181
|
+
// Stands in for the request to the server.
|
|
182
|
+
deleteTimer.current = setTimeout(function () {
|
|
183
|
+
setDeleting(false);
|
|
184
|
+
setConfirmingId(null);
|
|
185
|
+
setThread(function (rows) { return rows.filter(function (m) { return m.id !== id; }); });
|
|
186
|
+
toastIds.current.push(toast({ type: 'success', message: 'Message deleted.' }));
|
|
187
|
+
// The row is gone: focus goes to the next row's More button, or to the message box when none follows.
|
|
188
|
+
// If the next row's button is not on screen, focus goes to the message box.
|
|
189
|
+
focusNext.current = function () { var _a, _b; return (_b = ((_a = (next ? moreButtons.current[next.id] : null)) !== null && _a !== void 0 ? _a : box.current)) === null || _b === void 0 ? void 0 : _b.focus(); };
|
|
190
|
+
}, 1200);
|
|
191
|
+
}
|
|
192
|
+
function send() {
|
|
193
|
+
// A real app sends the message to the server here and shows it at once.
|
|
194
|
+
setThread(function (rows) { return __spreadArray(__spreadArray([], rows, true), [{ id: "m".concat(rows.length + 1), from: me, at: new Date(), text: text.trim() }], false); });
|
|
195
|
+
setText('');
|
|
196
|
+
}
|
|
197
|
+
return (<Center width="page">
|
|
198
|
+
{/* A real app mounts one Toaster near its root. */}
|
|
199
|
+
<Toaster />
|
|
200
|
+
<Stack gap="large">
|
|
201
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
202
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
203
|
+
<Stack gap="small">
|
|
204
|
+
{thread.map(function (m) {
|
|
205
|
+
var editing = m.id === editingId;
|
|
206
|
+
var confirming = m.id === confirmingId;
|
|
207
|
+
return (<Message key={m.id} aria-label={m.agent ? "".concat(m.from, ", agent") : m.from} avatar={m.agent ? <UserImage userHandle={m.from} icon={Bot} decorative/> : <UserImage userHandle={m.from} decorative/>} name={m.from} meta={<>
|
|
208
|
+
{m.agent && <Tag variant="contained" size="small" label="Agent"/>}
|
|
209
|
+
<TimeStamp createdAt={m.at} dateFormat="absolute" data="time"/>
|
|
210
|
+
{m.agent && <Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>}
|
|
211
|
+
{m.edited && <Paragraph size="caption" tone="secondary" measure="none">(edited)</Paragraph>}
|
|
212
|
+
</>} footer={m.reacted || confirming ? (<Stack gap="small">
|
|
213
|
+
{m.reacted && <Tag variant="contained" size="small" state="selected" label="👍 1" aria-label="Thumbs up, 1 reaction"/>}
|
|
214
|
+
{confirming && (
|
|
215
|
+
// The confirm is in the row, as the case 'Delete confirm' says for a row in a dense list.
|
|
216
|
+
<Stack gap="small">
|
|
217
|
+
<Paragraph size="body2" measure="none">Delete this message?</Paragraph>
|
|
218
|
+
<Cluster gap="small">
|
|
219
|
+
<Button ref={cancelDelete} size="small" type="tertiary" state={deleting ? 'disabled' : 'enabled'} label="Cancel" aria-label="Cancel deleting your message" onClickButton={keepMessage}/>
|
|
220
|
+
<Button size="small" type="primary" color="danger" state="enabled" label="Delete" aria-label="Delete this message" loading={deleting} onClickButton={confirmDelete}/>
|
|
221
|
+
</Cluster>
|
|
222
|
+
</Stack>)}
|
|
223
|
+
</Stack>) : undefined}
|
|
224
|
+
// One More button. Shown while the pointer is on the row or focus is in it, and always on a touch screen.
|
|
225
|
+
// It stays on screen while its menu is open, though the pointer and focus are in the menu.
|
|
226
|
+
actionsVisible={menuOpen && (menuRow === null || menuRow === void 0 ? void 0 : menuRow.id) === m.id} actions={editing || confirming ? undefined : (<Tooltip title="More">
|
|
227
|
+
<IconButton ref={function (el) { moreButtons.current[m.id] = el; }} color="iconOnly" state={menuOpen && (menuRow === null || menuRow === void 0 ? void 0 : menuRow.id) === m.id ? 'selected' : 'enabled'} size="small" iconName="Ellipsis" ariaLabel={"More actions for message from ".concat(m.from)} aria-haspopup="menu" aria-expanded={menuOpen && (menuRow === null || menuRow === void 0 ? void 0 : menuRow.id) === m.id} onClick={function (e) { return openMenu(m, e.currentTarget); }}/>
|
|
228
|
+
</Tooltip>)}>
|
|
229
|
+
{editing ? (
|
|
230
|
+
// Edit works as the case 'Message edit' says.
|
|
231
|
+
<Composer ref={field} id="message-actions-menu-edit" aria-label="Edit message" value={draft} onChange={setDraft} onSubmit={save} canSubmit={canSave} disabled={saving} onKeyDown={function (e) {
|
|
232
|
+
if (e.key === 'Escape') {
|
|
233
|
+
e.preventDefault();
|
|
234
|
+
e.stopPropagation();
|
|
235
|
+
cancelEditing();
|
|
236
|
+
}
|
|
237
|
+
}} actions={<Cluster gap="small">
|
|
238
|
+
<Button size="small" type="tertiary" state={saving ? 'disabled' : 'enabled'} label="Cancel" onClickButton={cancelEditing}/>
|
|
239
|
+
<Button size="small" type="primary" state={canSave ? 'enabled' : 'disabled'} label="Save" loading={saving} onClickButton={save}/>
|
|
240
|
+
</Cluster>}/>) : (<Paragraph measure="none">{m.text}</Paragraph>)}
|
|
241
|
+
</Message>);
|
|
242
|
+
})}
|
|
243
|
+
</Stack>
|
|
244
|
+
<Composer ref={box} id="message-actions-menu-message" aria-label="Message" placeholder="Message the team" value={text} onChange={setText} onSubmit={send}/>
|
|
245
|
+
</Stack>
|
|
246
|
+
{/* A navigable Menu focuses its first item and takes the arrow keys, Home, End and letters. */}
|
|
247
|
+
<Popover open={menuOpen} anchorEl={menuAnchor} onClose={closeMenu} returnFocus>
|
|
248
|
+
<Menu navigable aria-label="Message actions" width={200}>
|
|
249
|
+
<MenuItem size="small" iconName="SmilePlus" label="Add Reaction" onClick={function () { return choose(react); }}/>
|
|
250
|
+
<MenuItem size="small" iconName="Copy" label="Copy" onClick={function () { return choose(copy); }}/>
|
|
251
|
+
{(menuRow === null || menuRow === void 0 ? void 0 : menuRow.from) === me && <MenuItem size="small" iconName="Pencil" label="Edit" onClick={function () { return choose(startEditing); }}/>}
|
|
252
|
+
<MenuItem size="small" iconName="ClipboardPlus" label="Create Task" onClick={function () { return choose(createTask); }}/>
|
|
253
|
+
{(menuRow === null || menuRow === void 0 ? void 0 : menuRow.from) !== me && <MenuItem size="small" iconName="Flag" label="Report" onClick={function () { return choose(report); }}/>}
|
|
254
|
+
{(menuRow === null || menuRow === void 0 ? void 0 : menuRow.from) === me && <MenuItem size="small" color="danger" iconName="Trash2" label="Delete" onClick={function () { return choose(askToDelete); }}/>}
|
|
255
|
+
</Menu>
|
|
256
|
+
</Popover>
|
|
257
|
+
</Center>);
|
|
258
|
+
}
|