From fc151cec2f59b3768f989b91732974d223cf8c8a Mon Sep 17 00:00:00 2001 From: woksin Date: Sat, 21 Nov 2026 22:21:11 +0100 Subject: [PATCH] Mark chat and schema component roots for component picking --- Documentation/ComponentPicker/index.md | 2 + Source/Chat/ChatConversation.tsx | 251 ++++++++++-------- Source/Chat/ChatMessageBody.tsx | 2 +- Source/Chat/ChatTopicList.tsx | 2 +- Source/Chat/Kit/Avatar/PersonAvatarCircle.tsx | 1 + Source/Chat/Kit/ChatComposer.tsx | 2 +- Source/Chat/Kit/ChatMessageBubble.tsx | 182 +++++++------ Source/Chat/Kit/Emoji/EmojiPicker.tsx | 2 +- Source/Chat/Kit/FailedReply.tsx | 2 +- .../Chat/Kit/Mentions/MentionSuggestions.tsx | 2 +- Source/Chat/Kit/MessageReactions.tsx | 2 +- Source/Chat/Kit/ReactionPicker.tsx | 2 +- Source/Chat/Kit/TypingIndicator.tsx | 2 +- .../when_no_topic_actions_are_offered.ts | 2 +- .../SchemaEditor/Tree/PropertyTypeGlyph.tsx | 2 +- .../componentMarkerCoverage.ts | 26 +- .../when_checking_component_markers.ts | 2 +- ...ring_marked_chat_and_schema_components.tsx | 178 +++++++++++++ 18 files changed, 441 insertions(+), 223 deletions(-) create mode 100644 Source/for_component_identity/when_rendering_marked_chat_and_schema_components.tsx diff --git a/Documentation/ComponentPicker/index.md b/Documentation/ComponentPicker/index.md index 619937d6..df972c56 100644 --- a/Documentation/ComponentPicker/index.md +++ b/Documentation/ComponentPicker/index.md @@ -17,6 +17,8 @@ The picker recognizes a component by `data-cratis-component=""` on its roo `data-cratis-part` identifies a part inside the component, such as `label`, `title` or `close`; `data-cratis-component` identifies the component itself. Some public components do not yet have their own marker. For an unmarked element, the picker selects its nearest marked ancestor, if one exists. The package's identity specs track marker coverage and require new public components to be accounted for. +Chat composer, conversation, message body, message bubble, topic list, emoji picker, failed reply, mention suggestions, reactions, avatar, typing indicator, and property-type glyph roots expose their own markers. `ChatSidebarForObservableQueries` and `GlyphMenu` remain unmarked: the former delegates through a fragment, and the latter combines a trigger with portal content. + ## Pick a component Render your screen under [CratisComponentsProvider](../Common/cratis-components-provider.md), then use `useComponentPicker()` to start and stop picking. Render the returned `picker` once under that provider and call `start()` when the user asks to select something: diff --git a/Source/Chat/ChatConversation.tsx b/Source/Chat/ChatConversation.tsx index 97f911bf..ebeb300e 100644 --- a/Source/Chat/ChatConversation.tsx +++ b/Source/Chat/ChatConversation.tsx @@ -220,6 +220,126 @@ const typingLabel = ( return labels?.typingSeveral ?? 'Several people are typing'; }; +const conversationStatusLabel = ( + status: ChatStatus, + labels: ChatConversationLabels | undefined, +) => { + switch (status) { + case ChatStatus.Loading: + return {labels?.loading ?? 'Loading messages…'}; + case ChatStatus.Failed: + return {labels?.failed ?? 'Could not load messages.'}; + case ChatStatus.Unauthorized: + return {labels?.unauthorized ?? 'You are not authorized to view these messages.'}; + default: + return labels?.empty ?? 'No messages yet. Say hello!'; + } +}; + +const renderConversationStatus = ( + messageCount: number, + status: ChatStatus, + labels: ChatConversationLabels | undefined, +) => { + if (messageCount > 0 && status !== ChatStatus.Failed && status !== ChatStatus.Unauthorized) return null; + return ( +

+ {conversationStatusLabel(status, labels)} +

+ ); +}; + +interface ConversationMessageProps extends Pick, + 'renderAvatar' | 'renderAuthorName' | 'renderMessageExtra' | 'buildAvatarUrl' | 'labels'> { + message: TMessage; + author: ChatAuthor; + info: MessageRenderInfo; + availableActions: ChatMessageAction[]; + quickReply: boolean; + onQuickReply: (name: string) => void; +} + +const renderMessageAuthor = ( + message: ChatMessage, + author: ChatAuthor, + { renderAvatar, renderAuthorName, buildAvatarUrl }: Pick, +) => ( +
+ {renderAvatar ? ( + renderAvatar(message.authorId, author) + ) : ( + + )} + + {renderAuthorName ? renderAuthorName(message.authorId, author) : author.name} + +
+); + +const renderMessageActions = ({ + message, author, availableActions, quickReply, labels, onQuickReply, +}: Pick, 'message' | 'author' | 'availableActions' | 'quickReply' | 'labels' | 'onQuickReply'>) => ( +
+ {quickReply && ( + + )} + {availableActions.map((action) => ( +