@object-ui/plugin-detail 3.0.3 → 3.1.1

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 (141) hide show
  1. package/.turbo/turbo-build.log +45 -8
  2. package/CHANGELOG.md +11 -0
  3. package/dist/AddressField-B1iVr404.js +96 -0
  4. package/dist/AutoNumberField-BxnFqllo.js +8 -0
  5. package/dist/AvatarField-Duw4xOLZ.js +82 -0
  6. package/dist/BooleanField-CZ4axVeq.js +37 -0
  7. package/dist/CodeField-BSz-mk2v.js +21 -0
  8. package/dist/ColorField-B522ad8m.js +42 -0
  9. package/dist/CurrencyField-Cwr3_pow.js +43 -0
  10. package/dist/DateField-DCo6dxud.js +21 -0
  11. package/dist/DateTimeField-BWfBuANO.js +28 -0
  12. package/dist/EmailField-CpwbdVCU.js +31 -0
  13. package/dist/FileField-DVAUAJ8e.js +133 -0
  14. package/dist/FormulaField-CJkkwIK8.js +9 -0
  15. package/dist/GeolocationField-DNCKitgo.js +123 -0
  16. package/dist/GridField-DSblZNfp.js +30 -0
  17. package/dist/ImageField-DBAlnMon.js +90 -0
  18. package/dist/LocationField-DsHsXA6R.js +31 -0
  19. package/dist/LookupField-CsT0QQz2.js +96 -0
  20. package/dist/MasterDetailField-Db8b7Gqs.js +108 -0
  21. package/dist/NumberField-0IGp7lcA.js +26 -0
  22. package/dist/ObjectField-BLApgJtS.js +48 -0
  23. package/dist/PasswordField-pHKyNlmo.js +38 -0
  24. package/dist/PercentField-CwgKmlIb.js +63 -0
  25. package/dist/PhoneField-lKtbYOdN.js +31 -0
  26. package/dist/QRCodeField-BTTasT3w.js +77 -0
  27. package/dist/RatingField-De2X-l44.js +47 -0
  28. package/dist/RichTextField-B5QnvUOr.js +38 -0
  29. package/dist/SelectField-C9AZRHWu.js +26 -0
  30. package/dist/SignatureField-BgcEmYzd.js +85 -0
  31. package/dist/SliderField-BzrttVOY.js +30 -0
  32. package/dist/SummaryField-ugYPYxjP.js +9 -0
  33. package/dist/TextAreaField-DSE_CaU6.js +39 -0
  34. package/dist/TextField-DFQ4T9PR.js +32 -0
  35. package/dist/TimeField-F0cfmsps.js +21 -0
  36. package/dist/UrlField-DLXrFIH-.js +33 -0
  37. package/dist/UserField-PXMmxJY9.js +49 -0
  38. package/dist/VectorField-CKg9jdGa.js +25 -0
  39. package/dist/index-qQ1C-yUR.js +59976 -0
  40. package/dist/index.js +32 -55026
  41. package/dist/index.umd.cjs +41 -30
  42. package/dist/plugin-detail.css +1 -1
  43. package/dist/src/ActivityTimeline.d.ts +20 -0
  44. package/dist/src/ActivityTimeline.d.ts.map +1 -0
  45. package/dist/src/CommentAttachment.d.ts +25 -0
  46. package/dist/src/CommentAttachment.d.ts.map +1 -0
  47. package/dist/src/CommentInput.d.ts +24 -0
  48. package/dist/src/CommentInput.d.ts.map +1 -0
  49. package/dist/src/DetailSection.d.ts +8 -0
  50. package/dist/src/DetailSection.d.ts.map +1 -1
  51. package/dist/src/DetailView.d.ts +4 -0
  52. package/dist/src/DetailView.d.ts.map +1 -1
  53. package/dist/src/DetailView.stories.d.ts +8 -0
  54. package/dist/src/DetailView.stories.d.ts.map +1 -1
  55. package/dist/src/DiffView.d.ts +24 -0
  56. package/dist/src/DiffView.d.ts.map +1 -0
  57. package/dist/src/FieldChangeItem.d.ts +21 -0
  58. package/dist/src/FieldChangeItem.d.ts.map +1 -0
  59. package/dist/src/HeaderHighlight.d.ts +18 -0
  60. package/dist/src/HeaderHighlight.d.ts.map +1 -0
  61. package/dist/src/InlineCreateRelated.d.ts +32 -0
  62. package/dist/src/InlineCreateRelated.d.ts.map +1 -0
  63. package/dist/src/MentionAutocomplete.d.ts +43 -0
  64. package/dist/src/MentionAutocomplete.d.ts.map +1 -0
  65. package/dist/src/PointInTimeRestore.d.ts +28 -0
  66. package/dist/src/PointInTimeRestore.d.ts.map +1 -0
  67. package/dist/src/ReactionPicker.d.ts +25 -0
  68. package/dist/src/ReactionPicker.d.ts.map +1 -0
  69. package/dist/src/RecordActivityTimeline.d.ts +49 -0
  70. package/dist/src/RecordActivityTimeline.d.ts.map +1 -0
  71. package/dist/src/RecordChatterPanel.d.ts +48 -0
  72. package/dist/src/RecordChatterPanel.d.ts.map +1 -0
  73. package/dist/src/RecordComments.d.ts +20 -0
  74. package/dist/src/RecordComments.d.ts.map +1 -0
  75. package/dist/src/RecordNavigationEnhanced.d.ts +18 -0
  76. package/dist/src/RecordNavigationEnhanced.d.ts.map +1 -0
  77. package/dist/src/RelatedList.d.ts +20 -0
  78. package/dist/src/RelatedList.d.ts.map +1 -1
  79. package/dist/src/RelationshipGraph.d.ts +23 -0
  80. package/dist/src/RelationshipGraph.d.ts.map +1 -0
  81. package/dist/src/RichTextCommentInput.d.ts +24 -0
  82. package/dist/src/RichTextCommentInput.d.ts.map +1 -0
  83. package/dist/src/SectionGroup.d.ts +21 -0
  84. package/dist/src/SectionGroup.d.ts.map +1 -0
  85. package/dist/src/SubscriptionToggle.d.ts +22 -0
  86. package/dist/src/SubscriptionToggle.d.ts.map +1 -0
  87. package/dist/src/ThreadedReplies.d.ts +26 -0
  88. package/dist/src/ThreadedReplies.d.ts.map +1 -0
  89. package/dist/src/autoLayout.d.ts +34 -0
  90. package/dist/src/autoLayout.d.ts.map +1 -0
  91. package/dist/src/index.d.ts +40 -0
  92. package/dist/src/index.d.ts.map +1 -1
  93. package/dist/src/useDetailTranslation.d.ts +34 -0
  94. package/dist/src/useDetailTranslation.d.ts.map +1 -0
  95. package/package.json +8 -7
  96. package/src/ActivityTimeline.tsx +184 -0
  97. package/src/CommentAttachment.tsx +192 -0
  98. package/src/CommentInput.tsx +81 -0
  99. package/src/DetailSection.tsx +81 -10
  100. package/src/DetailView.stories.tsx +76 -0
  101. package/src/DetailView.tsx +519 -66
  102. package/src/DiffView.tsx +231 -0
  103. package/src/FieldChangeItem.tsx +46 -0
  104. package/src/HeaderHighlight.tsx +67 -0
  105. package/src/InlineCreateRelated.tsx +291 -0
  106. package/src/MentionAutocomplete.tsx +123 -0
  107. package/src/PointInTimeRestore.tsx +261 -0
  108. package/src/ReactionPicker.tsx +106 -0
  109. package/src/RecordActivityTimeline.tsx +429 -0
  110. package/src/RecordChatterPanel.tsx +202 -0
  111. package/src/RecordComments.tsx +215 -0
  112. package/src/RecordNavigationEnhanced.tsx +211 -0
  113. package/src/RelatedList.tsx +314 -19
  114. package/src/RelationshipGraph.tsx +286 -0
  115. package/src/RichTextCommentInput.tsx +348 -0
  116. package/src/SectionGroup.tsx +101 -0
  117. package/src/SubscriptionToggle.tsx +60 -0
  118. package/src/ThreadedReplies.tsx +161 -0
  119. package/src/__tests__/ActivityTimeline.test.tsx +119 -0
  120. package/src/__tests__/ActivityTimelineFiltering.test.tsx +143 -0
  121. package/src/__tests__/CommentInput.test.tsx +57 -0
  122. package/src/__tests__/DetailSection.test.tsx +320 -0
  123. package/src/__tests__/DetailView.test.tsx +415 -1
  124. package/src/__tests__/FieldChangeItem.test.tsx +119 -0
  125. package/src/__tests__/HeaderHighlight.test.tsx +68 -0
  126. package/src/__tests__/MentionAutocomplete.test.tsx +97 -0
  127. package/src/__tests__/ReactionPicker.test.tsx +113 -0
  128. package/src/__tests__/RecordActivityTimeline.test.tsx +395 -0
  129. package/src/__tests__/RecordChatterPanel.test.tsx +227 -0
  130. package/src/__tests__/RecordComments.test.tsx +96 -0
  131. package/src/__tests__/RecordCommentsPinSearch.test.tsx +133 -0
  132. package/src/__tests__/RelatedList.test.tsx +160 -0
  133. package/src/__tests__/SectionGroup.test.tsx +101 -0
  134. package/src/__tests__/SubscriptionToggle.test.tsx +84 -0
  135. package/src/__tests__/ThreadedReplies.test.tsx +212 -0
  136. package/src/__tests__/autoLayout.test.ts +184 -0
  137. package/src/__tests__/phase12-features.test.tsx +583 -0
  138. package/src/__tests__/roadmap-features.test.tsx +478 -0
  139. package/src/autoLayout.ts +111 -0
  140. package/src/index.tsx +50 -0
  141. package/src/useDetailTranslation.ts +114 -0
@@ -0,0 +1,348 @@
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 {
12
+ Bold,
13
+ Italic,
14
+ List,
15
+ Code,
16
+ AtSign,
17
+ Eye,
18
+ Edit,
19
+ Send,
20
+ } from 'lucide-react';
21
+
22
+ export interface MentionSuggestion {
23
+ id: string;
24
+ label: string;
25
+ avatarUrl?: string;
26
+ }
27
+
28
+ export interface RichTextCommentInputProps {
29
+ value: string;
30
+ onChange: (value: string) => void;
31
+ onSubmit?: () => void | Promise<void>;
32
+ mentionSuggestions?: MentionSuggestion[];
33
+ placeholder?: string;
34
+ className?: string;
35
+ disabled?: boolean;
36
+ }
37
+
38
+ /** Render minimal markdown to HTML for preview. */
39
+ function renderMarkdown(text: string): string {
40
+ let html = text
41
+ // Escape HTML
42
+ .replace(/&/g, '&amp;')
43
+ .replace(/</g, '&lt;')
44
+ .replace(/>/g, '&gt;')
45
+ // Code blocks (```)
46
+ .replace(/```([\s\S]*?)```/g, '<pre class="bg-muted rounded p-2 text-xs font-mono my-1 overflow-x-auto">$1</pre>')
47
+ // Inline code
48
+ .replace(/`([^`]+)`/g, '<code class="bg-muted rounded px-1 py-0.5 text-xs font-mono">$1</code>')
49
+ // Bold
50
+ .replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
51
+ // Italic
52
+ .replace(/\*(.+?)\*/g, '<em>$1</em>')
53
+ // @mentions
54
+ .replace(/@(\w+)/g, '<span class="text-primary font-medium">@$1</span>')
55
+ // Unordered lists
56
+ .replace(/^- (.+)$/gm, '<li class="ml-4 list-disc">$1</li>')
57
+ // Line breaks
58
+ .replace(/\n/g, '<br/>');
59
+
60
+ // Wrap consecutive <li> in <ul>
61
+ html = html.replace(
62
+ /(<li[^>]*>.*?<\/li>(?:<br\/>)?)+/g,
63
+ (match) => `<ul class="my-1">${match.replace(/<br\/>/g, '')}</ul>`,
64
+ );
65
+
66
+ return html;
67
+ }
68
+
69
+ export const RichTextCommentInput: React.FC<RichTextCommentInputProps> = ({
70
+ value,
71
+ onChange,
72
+ onSubmit,
73
+ mentionSuggestions = [],
74
+ placeholder = 'Write a comment…',
75
+ className,
76
+ disabled = false,
77
+ }) => {
78
+ const [isPreview, setIsPreview] = React.useState(false);
79
+ const [showMentions, setShowMentions] = React.useState(false);
80
+ const [mentionQuery, setMentionQuery] = React.useState('');
81
+ const [mentionIndex, setMentionIndex] = React.useState(0);
82
+ const textareaRef = React.useRef<HTMLTextAreaElement>(null);
83
+
84
+ const filteredMentions = React.useMemo(() => {
85
+ if (!mentionQuery) return mentionSuggestions;
86
+ const query = mentionQuery.toLowerCase();
87
+ return mentionSuggestions.filter((s) =>
88
+ s.label.toLowerCase().includes(query),
89
+ );
90
+ }, [mentionQuery, mentionSuggestions]);
91
+
92
+ const insertAtCursor = React.useCallback(
93
+ (before: string, after: string = '') => {
94
+ const textarea = textareaRef.current;
95
+ if (!textarea) return;
96
+ const start = textarea.selectionStart;
97
+ const end = textarea.selectionEnd;
98
+ const selected = value.slice(start, end);
99
+ const newValue =
100
+ value.slice(0, start) + before + selected + after + value.slice(end);
101
+ onChange(newValue);
102
+ // Restore cursor after the insertion
103
+ requestAnimationFrame(() => {
104
+ textarea.focus();
105
+ const cursorPos = start + before.length + selected.length;
106
+ textarea.setSelectionRange(cursorPos, cursorPos);
107
+ });
108
+ },
109
+ [value, onChange],
110
+ );
111
+
112
+ const handleBold = React.useCallback(() => insertAtCursor('**', '**'), [insertAtCursor]);
113
+ const handleItalic = React.useCallback(() => insertAtCursor('*', '*'), [insertAtCursor]);
114
+ const handleList = React.useCallback(() => insertAtCursor('\n- ', ''), [insertAtCursor]);
115
+ const handleCode = React.useCallback(() => insertAtCursor('`', '`'), [insertAtCursor]);
116
+
117
+ const handleMentionTrigger = React.useCallback(() => {
118
+ insertAtCursor('@', '');
119
+ setShowMentions(true);
120
+ setMentionQuery('');
121
+ setMentionIndex(0);
122
+ }, [insertAtCursor]);
123
+
124
+ const handleSelectMention = React.useCallback(
125
+ (suggestion: MentionSuggestion) => {
126
+ const textarea = textareaRef.current;
127
+ if (!textarea) return;
128
+ const cursorPos = textarea.selectionStart;
129
+ // Find the last '@' before cursor to replace the partial query
130
+ const textBefore = value.slice(0, cursorPos);
131
+ const atIndex = textBefore.lastIndexOf('@');
132
+ if (atIndex !== -1) {
133
+ const newValue =
134
+ value.slice(0, atIndex) + `@${suggestion.label} ` + value.slice(cursorPos);
135
+ onChange(newValue);
136
+ }
137
+ setShowMentions(false);
138
+ setMentionQuery('');
139
+ requestAnimationFrame(() => textarea.focus());
140
+ },
141
+ [value, onChange],
142
+ );
143
+
144
+ const handleTextChange = React.useCallback(
145
+ (e: React.ChangeEvent<HTMLTextAreaElement>) => {
146
+ const newValue = e.target.value;
147
+ onChange(newValue);
148
+
149
+ // Detect @mention trigger
150
+ const cursorPos = e.target.selectionStart;
151
+ const textBefore = newValue.slice(0, cursorPos);
152
+ const lastAtIndex = textBefore.lastIndexOf('@');
153
+
154
+ if (lastAtIndex !== -1) {
155
+ const textAfterAt = textBefore.slice(lastAtIndex + 1);
156
+ // Only show if @ is at start or preceded by whitespace and no space in query
157
+ const charBeforeAt = lastAtIndex > 0 ? textBefore[lastAtIndex - 1] : ' ';
158
+ if (/\s/.test(charBeforeAt) && !/\s/.test(textAfterAt)) {
159
+ setShowMentions(true);
160
+ setMentionQuery(textAfterAt);
161
+ setMentionIndex(0);
162
+ return;
163
+ }
164
+ }
165
+ setShowMentions(false);
166
+ },
167
+ [onChange],
168
+ );
169
+
170
+ const handleKeyDown = React.useCallback(
171
+ (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
172
+ if (showMentions && filteredMentions.length > 0) {
173
+ if (e.key === 'ArrowDown') {
174
+ e.preventDefault();
175
+ setMentionIndex((prev) =>
176
+ prev < filteredMentions.length - 1 ? prev + 1 : 0,
177
+ );
178
+ return;
179
+ }
180
+ if (e.key === 'ArrowUp') {
181
+ e.preventDefault();
182
+ setMentionIndex((prev) =>
183
+ prev > 0 ? prev - 1 : filteredMentions.length - 1,
184
+ );
185
+ return;
186
+ }
187
+ if (e.key === 'Enter' || e.key === 'Tab') {
188
+ e.preventDefault();
189
+ handleSelectMention(filteredMentions[mentionIndex]);
190
+ return;
191
+ }
192
+ if (e.key === 'Escape') {
193
+ setShowMentions(false);
194
+ return;
195
+ }
196
+ }
197
+
198
+ // Ctrl+Enter to submit
199
+ if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
200
+ e.preventDefault();
201
+ onSubmit?.();
202
+ }
203
+ },
204
+ [showMentions, filteredMentions, mentionIndex, handleSelectMention, onSubmit],
205
+ );
206
+
207
+ return (
208
+ <div className={cn('border rounded-md', className)}>
209
+ {/* Toolbar */}
210
+ <div className="flex items-center gap-0.5 px-2 py-1.5 border-b bg-muted/30">
211
+ <Button
212
+ variant="ghost"
213
+ size="icon"
214
+ className="h-7 w-7"
215
+ onClick={handleBold}
216
+ disabled={disabled || isPreview}
217
+ title="Bold (Ctrl+B)"
218
+ >
219
+ <Bold className="h-3.5 w-3.5" />
220
+ </Button>
221
+ <Button
222
+ variant="ghost"
223
+ size="icon"
224
+ className="h-7 w-7"
225
+ onClick={handleItalic}
226
+ disabled={disabled || isPreview}
227
+ title="Italic (Ctrl+I)"
228
+ >
229
+ <Italic className="h-3.5 w-3.5" />
230
+ </Button>
231
+ <Button
232
+ variant="ghost"
233
+ size="icon"
234
+ className="h-7 w-7"
235
+ onClick={handleList}
236
+ disabled={disabled || isPreview}
237
+ title="List"
238
+ >
239
+ <List className="h-3.5 w-3.5" />
240
+ </Button>
241
+ <Button
242
+ variant="ghost"
243
+ size="icon"
244
+ className="h-7 w-7"
245
+ onClick={handleCode}
246
+ disabled={disabled || isPreview}
247
+ title="Inline code"
248
+ >
249
+ <Code className="h-3.5 w-3.5" />
250
+ </Button>
251
+ <Button
252
+ variant="ghost"
253
+ size="icon"
254
+ className="h-7 w-7"
255
+ onClick={handleMentionTrigger}
256
+ disabled={disabled || isPreview}
257
+ title="Mention someone"
258
+ >
259
+ <AtSign className="h-3.5 w-3.5" />
260
+ </Button>
261
+
262
+ <div className="flex-1" />
263
+
264
+ <Button
265
+ variant="ghost"
266
+ size="icon"
267
+ className="h-7 w-7"
268
+ onClick={() => setIsPreview(!isPreview)}
269
+ title={isPreview ? 'Edit' : 'Preview'}
270
+ >
271
+ {isPreview ? (
272
+ <Edit className="h-3.5 w-3.5" />
273
+ ) : (
274
+ <Eye className="h-3.5 w-3.5" />
275
+ )}
276
+ </Button>
277
+
278
+ {onSubmit && (
279
+ <Button
280
+ variant="ghost"
281
+ size="icon"
282
+ className="h-7 w-7"
283
+ onClick={onSubmit}
284
+ disabled={disabled || !value.trim()}
285
+ title="Submit (Ctrl+Enter)"
286
+ >
287
+ <Send className="h-3.5 w-3.5" />
288
+ </Button>
289
+ )}
290
+ </div>
291
+
292
+ {/* Editor / Preview */}
293
+ <div className="relative">
294
+ {isPreview ? (
295
+ <div
296
+ className="min-h-[80px] px-3 py-2 text-sm prose prose-sm max-w-none"
297
+ dangerouslySetInnerHTML={{ __html: renderMarkdown(value) }}
298
+ />
299
+ ) : (
300
+ <>
301
+ <textarea
302
+ ref={textareaRef}
303
+ className="w-full min-h-[80px] px-3 py-2 text-sm bg-transparent resize-none focus:outline-none placeholder:text-muted-foreground"
304
+ placeholder={placeholder}
305
+ value={value}
306
+ onChange={handleTextChange}
307
+ onKeyDown={handleKeyDown}
308
+ disabled={disabled}
309
+ />
310
+
311
+ {/* @mention dropdown */}
312
+ {showMentions && filteredMentions.length > 0 && (
313
+ <div className="absolute left-2 bottom-full mb-1 w-56 bg-popover border rounded-md shadow-md z-50 max-h-40 overflow-y-auto">
314
+ {filteredMentions.map((suggestion, index) => (
315
+ <button
316
+ key={suggestion.id}
317
+ type="button"
318
+ className={cn(
319
+ 'w-full text-left px-3 py-1.5 text-sm flex items-center gap-2 hover:bg-accent transition-colors',
320
+ index === mentionIndex && 'bg-accent',
321
+ )}
322
+ onMouseDown={(e) => {
323
+ e.preventDefault();
324
+ handleSelectMention(suggestion);
325
+ }}
326
+ >
327
+ {suggestion.avatarUrl ? (
328
+ <img
329
+ src={suggestion.avatarUrl}
330
+ alt={suggestion.label}
331
+ className="h-5 w-5 rounded-full object-cover"
332
+ />
333
+ ) : (
334
+ <div className="h-5 w-5 rounded-full bg-muted flex items-center justify-center text-[10px] font-medium">
335
+ {suggestion.label.charAt(0).toUpperCase()}
336
+ </div>
337
+ )}
338
+ <span>{suggestion.label}</span>
339
+ </button>
340
+ ))}
341
+ </div>
342
+ )}
343
+ </>
344
+ )}
345
+ </div>
346
+ </div>
347
+ );
348
+ };
@@ -0,0 +1,101 @@
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 {
11
+ cn,
12
+ Collapsible,
13
+ CollapsibleTrigger,
14
+ CollapsibleContent,
15
+ } from '@object-ui/components';
16
+ import { ChevronDown, ChevronRight } from 'lucide-react';
17
+ import { DetailSection } from './DetailSection';
18
+ import type { SectionGroup as SectionGroupType } from '@object-ui/types';
19
+
20
+ export interface SectionGroupProps {
21
+ group: SectionGroupType;
22
+ data?: any;
23
+ className?: string;
24
+ objectSchema?: any;
25
+ /** Object name for i18n field label resolution */
26
+ objectName?: string;
27
+ isEditing?: boolean;
28
+ onFieldChange?: (field: string, value: any) => void;
29
+ }
30
+
31
+ export const SectionGroup: React.FC<SectionGroupProps> = ({
32
+ group,
33
+ data,
34
+ className,
35
+ objectSchema,
36
+ objectName,
37
+ isEditing = false,
38
+ onFieldChange,
39
+ }) => {
40
+ const collapsible = group.collapsible ?? true;
41
+ const [isCollapsed, setIsCollapsed] = React.useState(group.defaultCollapsed ?? false);
42
+
43
+ const sectionsContent = (
44
+ <div className="space-y-3 sm:space-y-4">
45
+ {group.sections.map((section, index) => (
46
+ <DetailSection
47
+ key={index}
48
+ section={section}
49
+ data={data}
50
+ objectSchema={objectSchema}
51
+ objectName={objectName}
52
+ isEditing={isEditing}
53
+ onFieldChange={onFieldChange}
54
+ />
55
+ ))}
56
+ </div>
57
+ );
58
+
59
+ if (!collapsible) {
60
+ return (
61
+ <div className={cn('space-y-3', className)}>
62
+ <div className="flex items-center gap-2 pb-2 border-b">
63
+ {group.icon && <span className="text-muted-foreground">{group.icon}</span>}
64
+ <h3 className="text-lg font-semibold">{group.title}</h3>
65
+ </div>
66
+ {group.description && (
67
+ <p className="text-sm text-muted-foreground">{group.description}</p>
68
+ )}
69
+ {sectionsContent}
70
+ </div>
71
+ );
72
+ }
73
+
74
+ return (
75
+ <Collapsible
76
+ open={!isCollapsed}
77
+ onOpenChange={(open) => setIsCollapsed(!open)}
78
+ className={className}
79
+ >
80
+ <CollapsibleTrigger asChild>
81
+ <div className="flex items-center gap-2 pb-2 border-b cursor-pointer hover:bg-muted/50 transition-colors rounded-t-md px-2 py-1.5">
82
+ {isCollapsed ? (
83
+ <ChevronRight className="h-4 w-4 text-muted-foreground shrink-0" />
84
+ ) : (
85
+ <ChevronDown className="h-4 w-4 text-muted-foreground shrink-0" />
86
+ )}
87
+ {group.icon && <span className="text-muted-foreground">{group.icon}</span>}
88
+ <h3 className="text-lg font-semibold">{group.title}</h3>
89
+ </div>
90
+ </CollapsibleTrigger>
91
+ {group.description && !isCollapsed && (
92
+ <p className="text-sm text-muted-foreground mt-1">{group.description}</p>
93
+ )}
94
+ <CollapsibleContent>
95
+ <div className="mt-3">
96
+ {sectionsContent}
97
+ </div>
98
+ </CollapsibleContent>
99
+ </Collapsible>
100
+ );
101
+ };
@@ -0,0 +1,60 @@
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 { Bell, BellOff } from 'lucide-react';
12
+ import type { RecordSubscription } from '@object-ui/types';
13
+
14
+ export interface SubscriptionToggleProps {
15
+ /** Current subscription state */
16
+ subscription: RecordSubscription;
17
+ /** Called when user toggles subscription */
18
+ onToggle?: (subscribed: boolean) => void | Promise<void>;
19
+ className?: string;
20
+ }
21
+
22
+ /**
23
+ * SubscriptionToggle — Bell icon toggle for record notification subscriptions.
24
+ * Aligned with @objectstack/spec RecordSubscriptionSchema.
25
+ */
26
+ export const SubscriptionToggle: React.FC<SubscriptionToggleProps> = ({
27
+ subscription,
28
+ onToggle,
29
+ className,
30
+ }) => {
31
+ const [isLoading, setIsLoading] = React.useState(false);
32
+
33
+ const handleToggle = React.useCallback(async () => {
34
+ if (!onToggle) return;
35
+ setIsLoading(true);
36
+ try {
37
+ await onToggle(!subscription.subscribed);
38
+ } finally {
39
+ setIsLoading(false);
40
+ }
41
+ }, [onToggle, subscription.subscribed]);
42
+
43
+ return (
44
+ <Button
45
+ variant="ghost"
46
+ size="icon"
47
+ className={cn('h-8 w-8', className)}
48
+ onClick={handleToggle}
49
+ disabled={isLoading || !onToggle}
50
+ aria-label={subscription.subscribed ? 'Unsubscribe from notifications' : 'Subscribe to notifications'}
51
+ title={subscription.subscribed ? 'Subscribed — click to unsubscribe' : 'Subscribe to notifications'}
52
+ >
53
+ {subscription.subscribed ? (
54
+ <Bell className="h-4 w-4 text-primary" />
55
+ ) : (
56
+ <BellOff className="h-4 w-4 text-muted-foreground" />
57
+ )}
58
+ </Button>
59
+ );
60
+ };
@@ -0,0 +1,161 @@
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, ChevronDown, ChevronRight, Send } from 'lucide-react';
12
+ import type { FeedItem } from '@object-ui/types';
13
+
14
+ export interface ThreadedRepliesProps {
15
+ /** Parent feed item (root comment) */
16
+ parentItem: FeedItem;
17
+ /** Reply feed items (children) */
18
+ replies: FeedItem[];
19
+ /** Called when a reply is submitted */
20
+ onAddReply?: (parentId: string | number, text: string) => void | Promise<void>;
21
+ /** Whether to show the reply input */
22
+ showReplyInput?: boolean;
23
+ className?: string;
24
+ }
25
+
26
+ function formatTimestamp(timestamp: string): string {
27
+ try {
28
+ const date = new Date(timestamp);
29
+ const now = new Date();
30
+ const diffMs = now.getTime() - date.getTime();
31
+ const diffMins = Math.floor(diffMs / 60000);
32
+
33
+ if (diffMins < 1) return 'just now';
34
+ if (diffMins < 60) return `${diffMins}m ago`;
35
+ const diffHours = Math.floor(diffMins / 60);
36
+ if (diffHours < 24) return `${diffHours}h ago`;
37
+ const diffDays = Math.floor(diffHours / 24);
38
+ if (diffDays < 7) return `${diffDays}d ago`;
39
+ return date.toLocaleDateString();
40
+ } catch {
41
+ return timestamp;
42
+ }
43
+ }
44
+
45
+ /**
46
+ * ThreadedReplies — Displays a collapsible thread of replies under a parent comment.
47
+ * Supports adding new replies and showing reply count.
48
+ */
49
+ export const ThreadedReplies: React.FC<ThreadedRepliesProps> = ({
50
+ parentItem,
51
+ replies,
52
+ onAddReply,
53
+ showReplyInput = true,
54
+ className,
55
+ }) => {
56
+ const [expanded, setExpanded] = React.useState(false);
57
+ const [replyText, setReplyText] = React.useState('');
58
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
59
+
60
+ const handleSubmitReply = React.useCallback(async () => {
61
+ const text = replyText.trim();
62
+ if (!text || !onAddReply) return;
63
+ setIsSubmitting(true);
64
+ try {
65
+ await onAddReply(parentItem.id, text);
66
+ setReplyText('');
67
+ } finally {
68
+ setIsSubmitting(false);
69
+ }
70
+ }, [replyText, onAddReply, parentItem.id]);
71
+
72
+ const handleKeyDown = React.useCallback(
73
+ (e: React.KeyboardEvent) => {
74
+ if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
75
+ e.preventDefault();
76
+ handleSubmitReply();
77
+ }
78
+ },
79
+ [handleSubmitReply],
80
+ );
81
+
82
+ if (replies.length === 0 && !showReplyInput) return null;
83
+
84
+ return (
85
+ <div className={cn('ml-10 mt-1', className)}>
86
+ {/* Toggle */}
87
+ {replies.length > 0 && (
88
+ <button
89
+ type="button"
90
+ className="flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors mb-1"
91
+ onClick={() => setExpanded(!expanded)}
92
+ aria-expanded={expanded}
93
+ >
94
+ {expanded ? (
95
+ <ChevronDown className="h-3 w-3" />
96
+ ) : (
97
+ <ChevronRight className="h-3 w-3" />
98
+ )}
99
+ <MessageSquare className="h-3 w-3" />
100
+ <span>{replies.length} {replies.length === 1 ? 'reply' : 'replies'}</span>
101
+ </button>
102
+ )}
103
+
104
+ {/* Replies list */}
105
+ {expanded && (
106
+ <div className="space-y-2 border-l-2 border-border pl-3">
107
+ {replies.map((reply) => (
108
+ <div key={reply.id} className="flex gap-2">
109
+ <div className="shrink-0">
110
+ {reply.actorAvatarUrl ? (
111
+ <img
112
+ src={reply.actorAvatarUrl}
113
+ alt={reply.actor}
114
+ className="h-6 w-6 rounded-full object-cover"
115
+ />
116
+ ) : (
117
+ <div className="h-6 w-6 rounded-full bg-muted flex items-center justify-center text-[10px] font-medium text-muted-foreground">
118
+ {reply.actor.charAt(0).toUpperCase()}
119
+ </div>
120
+ )}
121
+ </div>
122
+ <div className="flex-1 min-w-0">
123
+ <div className="flex items-center gap-1.5">
124
+ <span className="text-xs font-medium">{reply.actor}</span>
125
+ <span className="text-[10px] text-muted-foreground">
126
+ {formatTimestamp(reply.createdAt)}
127
+ </span>
128
+ </div>
129
+ <p className="text-xs whitespace-pre-wrap break-words">{reply.body}</p>
130
+ </div>
131
+ </div>
132
+ ))}
133
+ </div>
134
+ )}
135
+
136
+ {/* Reply input */}
137
+ {showReplyInput && onAddReply && (
138
+ <div className="flex gap-1.5 mt-1.5">
139
+ <input
140
+ className="flex-1 rounded-md border border-input bg-background px-2 py-1 text-xs placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
141
+ placeholder="Reply…"
142
+ value={replyText}
143
+ onChange={(e) => setReplyText(e.target.value)}
144
+ onKeyDown={handleKeyDown}
145
+ disabled={isSubmitting}
146
+ />
147
+ <Button
148
+ variant="ghost"
149
+ size="icon"
150
+ className="h-6 w-6 shrink-0"
151
+ onClick={handleSubmitReply}
152
+ disabled={!replyText.trim() || isSubmitting}
153
+ aria-label="Send reply"
154
+ >
155
+ <Send className="h-3 w-3" />
156
+ </Button>
157
+ </div>
158
+ )}
159
+ </div>
160
+ );
161
+ };