@object-ui/plugin-detail 3.0.3 → 3.1.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 (131) hide show
  1. package/.turbo/turbo-build.log +45 -8
  2. package/dist/AddressField-C07oUOY6.js +96 -0
  3. package/dist/AutoNumberField-BxnFqllo.js +8 -0
  4. package/dist/AvatarField-VThNABzo.js +82 -0
  5. package/dist/BooleanField-CGHKBzAi.js +37 -0
  6. package/dist/CodeField-Co_muhRR.js +21 -0
  7. package/dist/ColorField-DLid_tFz.js +42 -0
  8. package/dist/CurrencyField-Bw-LqANM.js +43 -0
  9. package/dist/DateField-BNHAzMB2.js +21 -0
  10. package/dist/DateTimeField-DjAyn_DQ.js +28 -0
  11. package/dist/EmailField-xoNcSppb.js +31 -0
  12. package/dist/FileField-DbNJwjU2.js +133 -0
  13. package/dist/FormulaField-CJkkwIK8.js +9 -0
  14. package/dist/GeolocationField-C1AnS6VV.js +123 -0
  15. package/dist/GridField-DATAHIKf.js +30 -0
  16. package/dist/ImageField-CEKJpyJp.js +90 -0
  17. package/dist/LocationField-jDWXjlpx.js +31 -0
  18. package/dist/LookupField-DQ08L9UQ.js +96 -0
  19. package/dist/MasterDetailField-Dbk529Ea.js +108 -0
  20. package/dist/NumberField-BVroN9aV.js +26 -0
  21. package/dist/ObjectField-CT3l_IHW.js +48 -0
  22. package/dist/PasswordField-DweVLEE0.js +38 -0
  23. package/dist/PercentField-ZpWUK97K.js +63 -0
  24. package/dist/PhoneField-mw-9fqZ_.js +31 -0
  25. package/dist/QRCodeField-Cbb9ck59.js +77 -0
  26. package/dist/RatingField-CSqgLS6t.js +47 -0
  27. package/dist/RichTextField-BpfBOd99.js +38 -0
  28. package/dist/SelectField-B9Ei-5jl.js +26 -0
  29. package/dist/SignatureField-DgGpHnQ8.js +85 -0
  30. package/dist/SliderField-C6HvOHd8.js +30 -0
  31. package/dist/SummaryField-ugYPYxjP.js +9 -0
  32. package/dist/TextAreaField-BK3RgzY3.js +39 -0
  33. package/dist/TextField-Bvzx3atT.js +32 -0
  34. package/dist/TimeField-Cuz9-Uai.js +21 -0
  35. package/dist/UrlField-B6XHTV73.js +33 -0
  36. package/dist/UserField-ooTul2d6.js +49 -0
  37. package/dist/VectorField-CKg9jdGa.js +25 -0
  38. package/dist/index-CnlyRfY_.js +59461 -0
  39. package/dist/index.js +30 -55026
  40. package/dist/index.umd.cjs +41 -30
  41. package/dist/plugin-detail.css +1 -1
  42. package/dist/src/ActivityTimeline.d.ts +20 -0
  43. package/dist/src/ActivityTimeline.d.ts.map +1 -0
  44. package/dist/src/CommentAttachment.d.ts +25 -0
  45. package/dist/src/CommentAttachment.d.ts.map +1 -0
  46. package/dist/src/CommentInput.d.ts +24 -0
  47. package/dist/src/CommentInput.d.ts.map +1 -0
  48. package/dist/src/DetailSection.d.ts +6 -0
  49. package/dist/src/DetailSection.d.ts.map +1 -1
  50. package/dist/src/DetailView.d.ts +4 -0
  51. package/dist/src/DetailView.d.ts.map +1 -1
  52. package/dist/src/DetailView.stories.d.ts +8 -0
  53. package/dist/src/DetailView.stories.d.ts.map +1 -1
  54. package/dist/src/DiffView.d.ts +24 -0
  55. package/dist/src/DiffView.d.ts.map +1 -0
  56. package/dist/src/FieldChangeItem.d.ts +21 -0
  57. package/dist/src/FieldChangeItem.d.ts.map +1 -0
  58. package/dist/src/InlineCreateRelated.d.ts +32 -0
  59. package/dist/src/InlineCreateRelated.d.ts.map +1 -0
  60. package/dist/src/MentionAutocomplete.d.ts +43 -0
  61. package/dist/src/MentionAutocomplete.d.ts.map +1 -0
  62. package/dist/src/PointInTimeRestore.d.ts +28 -0
  63. package/dist/src/PointInTimeRestore.d.ts.map +1 -0
  64. package/dist/src/ReactionPicker.d.ts +25 -0
  65. package/dist/src/ReactionPicker.d.ts.map +1 -0
  66. package/dist/src/RecordActivityTimeline.d.ts +49 -0
  67. package/dist/src/RecordActivityTimeline.d.ts.map +1 -0
  68. package/dist/src/RecordChatterPanel.d.ts +48 -0
  69. package/dist/src/RecordChatterPanel.d.ts.map +1 -0
  70. package/dist/src/RecordComments.d.ts +20 -0
  71. package/dist/src/RecordComments.d.ts.map +1 -0
  72. package/dist/src/RecordNavigationEnhanced.d.ts +18 -0
  73. package/dist/src/RecordNavigationEnhanced.d.ts.map +1 -0
  74. package/dist/src/RelatedList.d.ts +4 -0
  75. package/dist/src/RelatedList.d.ts.map +1 -1
  76. package/dist/src/RelationshipGraph.d.ts +23 -0
  77. package/dist/src/RelationshipGraph.d.ts.map +1 -0
  78. package/dist/src/RichTextCommentInput.d.ts +24 -0
  79. package/dist/src/RichTextCommentInput.d.ts.map +1 -0
  80. package/dist/src/SubscriptionToggle.d.ts +22 -0
  81. package/dist/src/SubscriptionToggle.d.ts.map +1 -0
  82. package/dist/src/ThreadedReplies.d.ts +26 -0
  83. package/dist/src/ThreadedReplies.d.ts.map +1 -0
  84. package/dist/src/autoLayout.d.ts +34 -0
  85. package/dist/src/autoLayout.d.ts.map +1 -0
  86. package/dist/src/index.d.ts +36 -0
  87. package/dist/src/index.d.ts.map +1 -1
  88. package/dist/src/useDetailTranslation.d.ts +34 -0
  89. package/dist/src/useDetailTranslation.d.ts.map +1 -0
  90. package/package.json +8 -7
  91. package/src/ActivityTimeline.tsx +184 -0
  92. package/src/CommentAttachment.tsx +192 -0
  93. package/src/CommentInput.tsx +81 -0
  94. package/src/DetailSection.tsx +74 -9
  95. package/src/DetailView.stories.tsx +76 -0
  96. package/src/DetailView.tsx +270 -27
  97. package/src/DiffView.tsx +231 -0
  98. package/src/FieldChangeItem.tsx +46 -0
  99. package/src/InlineCreateRelated.tsx +291 -0
  100. package/src/MentionAutocomplete.tsx +123 -0
  101. package/src/PointInTimeRestore.tsx +261 -0
  102. package/src/ReactionPicker.tsx +106 -0
  103. package/src/RecordActivityTimeline.tsx +429 -0
  104. package/src/RecordChatterPanel.tsx +202 -0
  105. package/src/RecordComments.tsx +215 -0
  106. package/src/RecordNavigationEnhanced.tsx +211 -0
  107. package/src/RelatedList.tsx +37 -8
  108. package/src/RelationshipGraph.tsx +286 -0
  109. package/src/RichTextCommentInput.tsx +348 -0
  110. package/src/SubscriptionToggle.tsx +60 -0
  111. package/src/ThreadedReplies.tsx +161 -0
  112. package/src/__tests__/ActivityTimeline.test.tsx +119 -0
  113. package/src/__tests__/ActivityTimelineFiltering.test.tsx +143 -0
  114. package/src/__tests__/CommentInput.test.tsx +57 -0
  115. package/src/__tests__/DetailSection.test.tsx +320 -0
  116. package/src/__tests__/DetailView.test.tsx +415 -1
  117. package/src/__tests__/FieldChangeItem.test.tsx +119 -0
  118. package/src/__tests__/MentionAutocomplete.test.tsx +97 -0
  119. package/src/__tests__/ReactionPicker.test.tsx +113 -0
  120. package/src/__tests__/RecordActivityTimeline.test.tsx +395 -0
  121. package/src/__tests__/RecordChatterPanel.test.tsx +227 -0
  122. package/src/__tests__/RecordComments.test.tsx +96 -0
  123. package/src/__tests__/RecordCommentsPinSearch.test.tsx +133 -0
  124. package/src/__tests__/RelatedList.test.tsx +66 -0
  125. package/src/__tests__/SubscriptionToggle.test.tsx +84 -0
  126. package/src/__tests__/ThreadedReplies.test.tsx +212 -0
  127. package/src/__tests__/autoLayout.test.ts +184 -0
  128. package/src/__tests__/phase12-features.test.tsx +583 -0
  129. package/src/autoLayout.ts +111 -0
  130. package/src/index.tsx +46 -0
  131. package/src/useDetailTranslation.ts +103 -0
@@ -0,0 +1,429 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import * as React from 'react';
10
+ import { cn, Card, CardHeader, CardTitle, CardContent, Button } from '@object-ui/components';
11
+ import {
12
+ Activity,
13
+ Edit,
14
+ PlusCircle,
15
+ Trash2,
16
+ MessageSquare,
17
+ ArrowRightLeft,
18
+ Calendar,
19
+ CheckSquare,
20
+ Zap,
21
+ Mail,
22
+ Phone,
23
+ ChevronDown,
24
+ Loader2,
25
+ } from 'lucide-react';
26
+ import type { FeedItem, FeedItemType, RecordActivityComponentProps, RecordSubscription } from '@object-ui/types';
27
+ import { FieldChangeItem } from './FieldChangeItem';
28
+ import { ReactionPicker } from './ReactionPicker';
29
+ import { ThreadedReplies } from './ThreadedReplies';
30
+ import { SubscriptionToggle } from './SubscriptionToggle';
31
+
32
+ export type FeedFilterMode = 'all' | 'comments_only' | 'changes_only' | 'tasks_only';
33
+
34
+ export interface RecordActivityTimelineProps {
35
+ /** Feed items to display */
36
+ items: FeedItem[];
37
+ /** Activity configuration from RecordActivityComponentProps */
38
+ config?: RecordActivityComponentProps;
39
+ /** Filter mode for the timeline */
40
+ filterMode?: FeedFilterMode;
41
+ /** Called when filter mode changes */
42
+ onFilterChange?: (mode: FeedFilterMode) => void;
43
+ /** Whether there are more items to load */
44
+ hasMore?: boolean;
45
+ /** Called when user wants to load more items */
46
+ onLoadMore?: () => void | Promise<void>;
47
+ /** Loading state */
48
+ loading?: boolean;
49
+ /** Called when a comment is submitted */
50
+ onAddComment?: (text: string) => void | Promise<void>;
51
+ /** Called when a reply is submitted */
52
+ onAddReply?: (parentId: string | number, text: string) => void | Promise<void>;
53
+ /** Called when user toggles a reaction */
54
+ onToggleReaction?: (itemId: string | number, emoji: string) => void | Promise<void>;
55
+ /** Subscription state */
56
+ subscription?: RecordSubscription;
57
+ /** Called when user toggles subscription */
58
+ onToggleSubscription?: (subscribed: boolean) => void | Promise<void>;
59
+ /** When true, collapse to only the comment input when there are no items */
60
+ collapseWhenEmpty?: boolean;
61
+ className?: string;
62
+ }
63
+
64
+ const FEED_TYPE_ICONS: Record<FeedItemType, React.ElementType> = {
65
+ comment: MessageSquare,
66
+ field_change: Edit,
67
+ task: CheckSquare,
68
+ event: Calendar,
69
+ system: Zap,
70
+ email: Mail,
71
+ call: Phone,
72
+ };
73
+
74
+ const FEED_TYPE_COLORS: Record<FeedItemType, string> = {
75
+ comment: 'bg-purple-100 text-purple-600',
76
+ field_change: 'bg-blue-100 text-blue-600',
77
+ task: 'bg-green-100 text-green-600',
78
+ event: 'bg-amber-100 text-amber-600',
79
+ system: 'bg-gray-100 text-gray-600',
80
+ email: 'bg-indigo-100 text-indigo-600',
81
+ call: 'bg-teal-100 text-teal-600',
82
+ };
83
+
84
+ const FILTER_OPTIONS: { value: FeedFilterMode; label: string }[] = [
85
+ { value: 'all', label: 'All Activity' },
86
+ { value: 'comments_only', label: 'Comments Only' },
87
+ { value: 'changes_only', label: 'Field Changes' },
88
+ { value: 'tasks_only', label: 'Tasks Only' },
89
+ ];
90
+
91
+ function formatTimestamp(timestamp: string): string {
92
+ try {
93
+ const date = new Date(timestamp);
94
+ const now = new Date();
95
+ const diffMs = now.getTime() - date.getTime();
96
+ const diffMins = Math.floor(diffMs / 60000);
97
+
98
+ if (diffMins < 1) return 'just now';
99
+ if (diffMins < 60) return `${diffMins}m ago`;
100
+ const diffHours = Math.floor(diffMins / 60);
101
+ if (diffHours < 24) return `${diffHours}h ago`;
102
+ const diffDays = Math.floor(diffHours / 24);
103
+ if (diffDays < 7) return `${diffDays}d ago`;
104
+ return date.toLocaleDateString();
105
+ } catch {
106
+ return timestamp;
107
+ }
108
+ }
109
+
110
+ function filterItems(items: FeedItem[], mode: FeedFilterMode): FeedItem[] {
111
+ switch (mode) {
112
+ case 'comments_only':
113
+ return items.filter((i) => i.type === 'comment');
114
+ case 'changes_only':
115
+ return items.filter((i) => i.type === 'field_change');
116
+ case 'tasks_only':
117
+ return items.filter((i) => i.type === 'task');
118
+ default:
119
+ return items;
120
+ }
121
+ }
122
+
123
+ /**
124
+ * RecordActivityTimeline — Unified timeline renderer for Airtable-style activity feeds.
125
+ *
126
+ * Renders different feed item types (comment, field_change, task, event, system, etc.)
127
+ * in a unified timeline. Supports filtering, pagination, reactions, and threading.
128
+ *
129
+ * Aligned with @objectstack/spec RecordActivityProps.
130
+ */
131
+ export const RecordActivityTimeline: React.FC<RecordActivityTimelineProps> = ({
132
+ items,
133
+ config,
134
+ filterMode: controlledFilter,
135
+ onFilterChange,
136
+ hasMore = false,
137
+ onLoadMore,
138
+ loading: _loading = false,
139
+ onAddComment,
140
+ onAddReply,
141
+ onToggleReaction,
142
+ subscription,
143
+ onToggleSubscription,
144
+ collapseWhenEmpty = false,
145
+ className,
146
+ }) => {
147
+ const [internalFilter, setInternalFilter] = React.useState<FeedFilterMode>('all');
148
+ const [commentText, setCommentText] = React.useState('');
149
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
150
+ const [isLoadingMore, setIsLoadingMore] = React.useState(false);
151
+
152
+ const activeFilter = controlledFilter ?? internalFilter;
153
+ const showFilter = config?.showFilterToggle !== false;
154
+ const showCommentInput = config?.showCommentInput !== false && !!onAddComment;
155
+ const enableReactions = config?.enableReactions ?? false;
156
+ const enableThreading = config?.enableThreading ?? false;
157
+ const showSubscription = config?.showSubscriptionToggle ?? false;
158
+
159
+ const filtered = React.useMemo(
160
+ () => filterItems(items, activeFilter),
161
+ [items, activeFilter],
162
+ );
163
+
164
+ // Group replies by parentId
165
+ const rootItems = React.useMemo(() => {
166
+ if (!enableThreading) return filtered;
167
+ return filtered.filter((i) => !i.parentId);
168
+ }, [filtered, enableThreading]);
169
+
170
+ const repliesByParent = React.useMemo(() => {
171
+ if (!enableThreading) return new Map<string | number, FeedItem[]>();
172
+ const map = new Map<string | number, FeedItem[]>();
173
+ for (const item of filtered) {
174
+ if (item.parentId) {
175
+ const existing = map.get(item.parentId) ?? [];
176
+ existing.push(item);
177
+ map.set(item.parentId, existing);
178
+ }
179
+ }
180
+ return map;
181
+ }, [filtered, enableThreading]);
182
+
183
+ const handleFilterChange = React.useCallback(
184
+ (mode: FeedFilterMode) => {
185
+ if (onFilterChange) {
186
+ onFilterChange(mode);
187
+ } else {
188
+ setInternalFilter(mode);
189
+ }
190
+ },
191
+ [onFilterChange],
192
+ );
193
+
194
+ const handleAddComment = React.useCallback(async () => {
195
+ const text = commentText.trim();
196
+ if (!text || !onAddComment) return;
197
+ setIsSubmitting(true);
198
+ try {
199
+ await onAddComment(text);
200
+ setCommentText('');
201
+ } finally {
202
+ setIsSubmitting(false);
203
+ }
204
+ }, [commentText, onAddComment]);
205
+
206
+ const handleKeyDown = React.useCallback(
207
+ (e: React.KeyboardEvent) => {
208
+ if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
209
+ e.preventDefault();
210
+ handleAddComment();
211
+ }
212
+ },
213
+ [handleAddComment],
214
+ );
215
+
216
+ const handleLoadMore = React.useCallback(async () => {
217
+ if (!onLoadMore) return;
218
+ setIsLoadingMore(true);
219
+ try {
220
+ await onLoadMore();
221
+ } finally {
222
+ setIsLoadingMore(false);
223
+ }
224
+ }, [onLoadMore]);
225
+
226
+ return (
227
+ <Card className={cn('', className)}>
228
+ <CardHeader>
229
+ <div className="flex items-center justify-between">
230
+ <CardTitle className="flex items-center gap-2 text-base">
231
+ <Activity className="h-4 w-4" />
232
+ Activity
233
+ <span className="text-sm font-normal text-muted-foreground">
234
+ ({filtered.length})
235
+ </span>
236
+ </CardTitle>
237
+ <div className="flex items-center gap-1">
238
+ {showSubscription && subscription && (
239
+ <SubscriptionToggle
240
+ subscription={subscription}
241
+ onToggle={onToggleSubscription}
242
+ />
243
+ )}
244
+ </div>
245
+ </div>
246
+ </CardHeader>
247
+ <CardContent className="space-y-4">
248
+ {/* Filter dropdown */}
249
+ {showFilter && (
250
+ <div className="flex items-center gap-2">
251
+ <select
252
+ className="rounded-md border border-input bg-background px-2.5 py-1.5 text-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
253
+ value={activeFilter}
254
+ onChange={(e) => handleFilterChange(e.target.value as FeedFilterMode)}
255
+ aria-label="Filter activity"
256
+ >
257
+ {FILTER_OPTIONS.map((opt) => (
258
+ <option key={opt.value} value={opt.value}>
259
+ {opt.label}
260
+ </option>
261
+ ))}
262
+ </select>
263
+ </div>
264
+ )}
265
+
266
+ {/* Comment Input */}
267
+ {showCommentInput && (
268
+ <div className="flex gap-2">
269
+ <textarea
270
+ className="flex-1 min-h-[60px] rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring resize-none"
271
+ placeholder="Leave a comment… (Ctrl+Enter to submit)"
272
+ value={commentText}
273
+ onChange={(e) => setCommentText(e.target.value)}
274
+ onKeyDown={handleKeyDown}
275
+ disabled={isSubmitting}
276
+ />
277
+ <Button
278
+ size="icon"
279
+ variant="default"
280
+ onClick={handleAddComment}
281
+ disabled={!commentText.trim() || isSubmitting}
282
+ className="shrink-0 self-end"
283
+ aria-label="Submit comment"
284
+ >
285
+ <MessageSquare className="h-4 w-4" />
286
+ </Button>
287
+ </div>
288
+ )}
289
+
290
+ {/* Timeline */}
291
+ {filtered.length === 0 ? (
292
+ collapseWhenEmpty ? null : (
293
+ <p className="text-sm text-muted-foreground text-center py-4">
294
+ No activity recorded
295
+ </p>
296
+ )
297
+ ) : (
298
+ <div className="relative">
299
+ {/* Timeline line */}
300
+ <div className="absolute left-4 top-2 bottom-2 w-px bg-border" />
301
+
302
+ <div className="space-y-4">
303
+ {rootItems.map((item) => {
304
+ const Icon = FEED_TYPE_ICONS[item.type] || Zap;
305
+ const colorClass =
306
+ FEED_TYPE_COLORS[item.type] || 'bg-gray-100 text-gray-600';
307
+ const replies = repliesByParent.get(item.id) ?? [];
308
+
309
+ return (
310
+ <div key={item.id}>
311
+ <div className="flex gap-3 relative">
312
+ {/* Icon */}
313
+ <div
314
+ className={cn(
315
+ 'shrink-0 h-8 w-8 rounded-full flex items-center justify-center z-10',
316
+ colorClass,
317
+ )}
318
+ >
319
+ {item.actorAvatarUrl ? (
320
+ <img
321
+ src={item.actorAvatarUrl}
322
+ alt={item.actor}
323
+ className="h-8 w-8 rounded-full object-cover"
324
+ />
325
+ ) : (
326
+ <Icon className="h-3.5 w-3.5" />
327
+ )}
328
+ </div>
329
+ {/* Content */}
330
+ <div className="flex-1 min-w-0 pt-1">
331
+ <div className="flex items-center gap-2 mb-0.5">
332
+ <span className="text-sm font-medium">{item.actor}</span>
333
+ {item.source && (
334
+ <span className="text-xs text-muted-foreground">
335
+ via {item.source}
336
+ </span>
337
+ )}
338
+ <span className="text-xs text-muted-foreground">
339
+ {formatTimestamp(item.createdAt)}
340
+ </span>
341
+ {item.edited && (
342
+ <span className="text-xs text-muted-foreground italic">(edited)</span>
343
+ )}
344
+ {item.pinned && (
345
+ <span className="text-xs text-amber-600">📌 Pinned</span>
346
+ )}
347
+ </div>
348
+
349
+ {/* Body text */}
350
+ {item.body && (
351
+ <p className="text-sm whitespace-pre-wrap break-words text-muted-foreground">
352
+ {item.body}
353
+ </p>
354
+ )}
355
+
356
+ {/* Field changes */}
357
+ {item.type === 'field_change' && item.fieldChanges && (
358
+ <div className="space-y-1 mt-1">
359
+ {item.fieldChanges.map((change, idx) => (
360
+ <FieldChangeItem key={idx} change={change} />
361
+ ))}
362
+ </div>
363
+ )}
364
+
365
+ {/* Reactions */}
366
+ {enableReactions && item.reactions && item.reactions.length > 0 && (
367
+ <div className="mt-1.5">
368
+ <ReactionPicker
369
+ reactions={item.reactions}
370
+ onToggleReaction={
371
+ onToggleReaction
372
+ ? (emoji) => onToggleReaction(item.id, emoji)
373
+ : undefined
374
+ }
375
+ />
376
+ </div>
377
+ )}
378
+
379
+ {/* Add reaction button (even if no reactions yet) */}
380
+ {enableReactions && (!item.reactions || item.reactions.length === 0) && onToggleReaction && (
381
+ <div className="mt-1.5">
382
+ <ReactionPicker
383
+ reactions={[]}
384
+ onToggleReaction={(emoji) => onToggleReaction(item.id, emoji)}
385
+ />
386
+ </div>
387
+ )}
388
+ </div>
389
+ </div>
390
+
391
+ {/* Threading */}
392
+ {enableThreading && (item.replyCount ?? 0) > 0 && (
393
+ <ThreadedReplies
394
+ parentItem={item}
395
+ replies={replies}
396
+ onAddReply={onAddReply}
397
+ showReplyInput={!!onAddReply}
398
+ />
399
+ )}
400
+ </div>
401
+ );
402
+ })}
403
+ </div>
404
+ </div>
405
+ )}
406
+
407
+ {/* Load More */}
408
+ {hasMore && (
409
+ <div className="text-center pt-2">
410
+ <Button
411
+ variant="ghost"
412
+ size="sm"
413
+ onClick={handleLoadMore}
414
+ disabled={isLoadingMore}
415
+ aria-label="Load more activity"
416
+ >
417
+ {isLoadingMore ? (
418
+ <Loader2 className="h-4 w-4 animate-spin mr-1" />
419
+ ) : (
420
+ <ChevronDown className="h-4 w-4 mr-1" />
421
+ )}
422
+ Load more
423
+ </Button>
424
+ </div>
425
+ )}
426
+ </CardContent>
427
+ </Card>
428
+ );
429
+ };
@@ -0,0 +1,202 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import * as React from 'react';
10
+ import { cn, Button } from '@object-ui/components';
11
+ import { MessageSquare, PanelRightOpen, PanelRightClose, X } from 'lucide-react';
12
+ import type { RecordChatterComponentProps, FeedItem, RecordSubscription } from '@object-ui/types';
13
+ import { RecordActivityTimeline } from './RecordActivityTimeline';
14
+ import type { FeedFilterMode, RecordActivityTimelineProps } from './RecordActivityTimeline';
15
+
16
+ export interface RecordChatterPanelProps {
17
+ /** Chatter panel configuration from RecordChatterComponentProps */
18
+ config?: RecordChatterComponentProps;
19
+ /** Feed items to display in the embedded timeline */
20
+ items: FeedItem[];
21
+ /** Whether there are more items to load */
22
+ hasMore?: boolean;
23
+ /** Called when user wants to load more */
24
+ onLoadMore?: () => void | Promise<void>;
25
+ /** Loading state */
26
+ loading?: boolean;
27
+ /** Called when a comment is submitted */
28
+ onAddComment?: (text: string) => void | Promise<void>;
29
+ /** Called when a reply is submitted */
30
+ onAddReply?: (parentId: string | number, text: string) => void | Promise<void>;
31
+ /** Called when user toggles a reaction */
32
+ onToggleReaction?: (itemId: string | number, emoji: string) => void | Promise<void>;
33
+ /** Subscription state */
34
+ subscription?: RecordSubscription;
35
+ /** Called when user toggles subscription */
36
+ onToggleSubscription?: (subscribed: boolean) => void | Promise<void>;
37
+ /** Filter mode */
38
+ filterMode?: FeedFilterMode;
39
+ /** Called when filter changes */
40
+ onFilterChange?: (mode: FeedFilterMode) => void;
41
+ className?: string;
42
+ }
43
+
44
+ /**
45
+ * RecordChatterPanel — Side/inline/drawer panel for record discussions.
46
+ *
47
+ * Consumes RecordChatterComponentProps from the spec protocol.
48
+ * Supports three positions: bottom (inline), right (sidebar), left (sidebar).
49
+ * Can be collapsible/expandable.
50
+ *
51
+ * Embeds RecordActivityTimeline as the feed sub-component.
52
+ */
53
+ export const RecordChatterPanel: React.FC<RecordChatterPanelProps> = ({
54
+ config,
55
+ items,
56
+ hasMore,
57
+ onLoadMore,
58
+ loading,
59
+ onAddComment,
60
+ onAddReply,
61
+ onToggleReaction,
62
+ subscription,
63
+ onToggleSubscription,
64
+ filterMode,
65
+ onFilterChange,
66
+ className,
67
+ }) => {
68
+ const position = config?.position ?? 'right';
69
+ const width = config?.width ?? '360px';
70
+ const collapsible = config?.collapsible ?? true;
71
+ const defaultCollapsed = config?.defaultCollapsed ?? false;
72
+
73
+ const [collapsed, setCollapsed] = React.useState(defaultCollapsed);
74
+
75
+ const isSidebar = position === 'right' || position === 'left';
76
+ const isInline = position === 'bottom';
77
+
78
+ // Sidebar mode
79
+ if (isSidebar) {
80
+ if (collapsed && collapsible) {
81
+ return (
82
+ <div
83
+ className={cn(
84
+ 'flex items-start pt-4',
85
+ position === 'right' ? 'border-l' : 'border-r',
86
+ className,
87
+ )}
88
+ >
89
+ <Button
90
+ variant="ghost"
91
+ size="icon"
92
+ className="h-8 w-8 mx-1"
93
+ onClick={() => setCollapsed(false)}
94
+ aria-label="Open discussion panel"
95
+ >
96
+ <PanelRightOpen className="h-4 w-4" />
97
+ </Button>
98
+ </div>
99
+ );
100
+ }
101
+
102
+ return (
103
+ <div
104
+ className={cn(
105
+ 'flex flex-col overflow-hidden',
106
+ position === 'right' ? 'border-l' : 'border-r',
107
+ className,
108
+ )}
109
+ style={{ width, minWidth: width }}
110
+ >
111
+ {/* Header */}
112
+ <div className="flex items-center justify-between px-4 py-3 border-b">
113
+ <div className="flex items-center gap-2">
114
+ <MessageSquare className="h-4 w-4" />
115
+ <span className="text-sm font-medium">Discussion</span>
116
+ </div>
117
+ {collapsible && (
118
+ <Button
119
+ variant="ghost"
120
+ size="icon"
121
+ className="h-7 w-7"
122
+ onClick={() => setCollapsed(true)}
123
+ aria-label="Close discussion panel"
124
+ >
125
+ <X className="h-3.5 w-3.5" />
126
+ </Button>
127
+ )}
128
+ </div>
129
+
130
+ {/* Embedded Timeline */}
131
+ <div className="flex-1 overflow-y-auto">
132
+ <RecordActivityTimeline
133
+ items={items}
134
+ config={config?.feed}
135
+ hasMore={hasMore}
136
+ onLoadMore={onLoadMore}
137
+ loading={loading}
138
+ onAddComment={onAddComment}
139
+ onAddReply={onAddReply}
140
+ onToggleReaction={onToggleReaction}
141
+ subscription={subscription}
142
+ onToggleSubscription={onToggleSubscription}
143
+ filterMode={filterMode}
144
+ onFilterChange={onFilterChange}
145
+ className="border-0 shadow-none"
146
+ />
147
+ </div>
148
+ </div>
149
+ );
150
+ }
151
+
152
+ // Inline / bottom mode
153
+ return (
154
+ <div className={cn('', className)}>
155
+ {collapsible && collapsed ? (
156
+ <Button
157
+ variant="ghost"
158
+ className="w-full justify-start gap-2 text-muted-foreground"
159
+ onClick={() => setCollapsed(false)}
160
+ aria-label="Show discussion"
161
+ >
162
+ <MessageSquare className="h-4 w-4" />
163
+ <span>Show Discussion ({items.length})</span>
164
+ </Button>
165
+ ) : (
166
+ <div>
167
+ {collapsible && (
168
+ <div className="flex items-center justify-between mb-2">
169
+ <div className="flex items-center gap-2 text-sm font-medium">
170
+ <MessageSquare className="h-4 w-4" />
171
+ Discussion
172
+ </div>
173
+ <Button
174
+ variant="ghost"
175
+ size="icon"
176
+ className="h-7 w-7"
177
+ onClick={() => setCollapsed(true)}
178
+ aria-label="Hide discussion"
179
+ >
180
+ <PanelRightClose className="h-3.5 w-3.5" />
181
+ </Button>
182
+ </div>
183
+ )}
184
+ <RecordActivityTimeline
185
+ items={items}
186
+ config={config?.feed}
187
+ hasMore={hasMore}
188
+ onLoadMore={onLoadMore}
189
+ loading={loading}
190
+ onAddComment={onAddComment}
191
+ onAddReply={onAddReply}
192
+ onToggleReaction={onToggleReaction}
193
+ subscription={subscription}
194
+ onToggleSubscription={onToggleSubscription}
195
+ filterMode={filterMode}
196
+ onFilterChange={onFilterChange}
197
+ />
198
+ </div>
199
+ )}
200
+ </div>
201
+ );
202
+ };