1
+ import { AutoHeightControl } from "@lowcoder-ee/comps/controls/autoHeightControl" ;
2
+ import { BoolControl } from "@lowcoder-ee/comps/controls/boolControl" ;
3
+ import { StringControl } from "@lowcoder-ee/comps/controls/codeControl" ;
4
+ import { stringExposingStateControl } from "@lowcoder-ee/comps/controls/codeStateControl" ;
5
+ import { dropdownControl } from "@lowcoder-ee/comps/controls/dropdownControl" ;
6
+ import { clickEvent , doubleClickEvent , eventHandlerControl } from "@lowcoder-ee/comps/controls/eventHandlerControl" ;
7
+ import { styleControl } from "@lowcoder-ee/comps/controls/styleControl" ;
8
+ import { AnimationStyle , TextStyle } from "@lowcoder-ee/comps/controls/styleControlConstants" ;
9
+ import { EditorContext } from "@lowcoder-ee/comps/editorState" ;
10
+ import { withDefault } from "@lowcoder-ee/comps/generators/simpleGenerators" ;
11
+ import { NewChildren } from "@lowcoder-ee/comps/generators/uiCompBuilder" ;
12
+ import { hiddenPropertyView } from "@lowcoder-ee/comps/utils/propertyUtils" ;
13
+ import { RecordConstructorToComp } from "lowcoder-core" ;
14
+ import { ScrollBar , Section , sectionNames } from "lowcoder-design" ;
15
+ import React , { useContext , useMemo } from "react" ;
16
+ import { trans } from "i18n" ;
17
+
18
+ // Event options for the chat component
19
+ const EventOptions = [ clickEvent , doubleClickEvent ] as const ;
20
+
21
+ // Define the component's children map
22
+ export const chatCompChildrenMap = {
23
+ chatName : stringExposingStateControl ( "chatName" , "Chat Room" ) ,
24
+ userId : stringExposingStateControl ( "userId" , "user_1" ) ,
25
+ userName : stringExposingStateControl ( "userName" , "User" ) ,
26
+ applicationId : stringExposingStateControl ( "applicationId" , "lowcoder_app" ) ,
27
+ roomId : stringExposingStateControl ( "roomId" , "general" ) ,
28
+ mode : dropdownControl ( [
29
+ { label : "🌐 Collaborative (Real-time)" , value : "collaborative" } ,
30
+ { label : "🔀 Hybrid (Local + Real-time)" , value : "hybrid" } ,
31
+ { label : "📱 Local Only" , value : "local" }
32
+ ] , "collaborative" ) ,
33
+
34
+ // Room Management Configuration
35
+ allowRoomCreation : withDefault ( BoolControl , true ) ,
36
+ allowRoomJoining : withDefault ( BoolControl , true ) ,
37
+ roomPermissionMode : dropdownControl ( [
38
+ { label : "🌐 Open (Anyone can join public rooms)" , value : "open" } ,
39
+ { label : "🔐 Invite Only (Admin invitation required)" , value : "invite" } ,
40
+ { label : "👤 Admin Only (Only admins can manage)" , value : "admin" }
41
+ ] , "open" ) ,
42
+ showAvailableRooms : withDefault ( BoolControl , true ) ,
43
+ maxRoomsDisplay : withDefault ( StringControl , "10" ) ,
44
+
45
+ // UI Configuration
46
+ leftPanelWidth : withDefault ( StringControl , "200px" ) ,
47
+ showRooms : withDefault ( BoolControl , true ) ,
48
+ autoHeight : AutoHeightControl ,
49
+ onEvent : eventHandlerControl ( EventOptions ) ,
50
+ style : styleControl ( TextStyle , 'style' ) ,
51
+ animationStyle : styleControl ( AnimationStyle , 'animationStyle' ) ,
52
+ } ;
53
+
54
+ export type ChatCompChildrenType = NewChildren < RecordConstructorToComp < typeof chatCompChildrenMap > > ;
55
+
56
+ // Property view component
57
+ export const ChatPropertyView = React . memo ( ( props : {
58
+ children : ChatCompChildrenType
59
+ } ) => {
60
+ const editorContext = useContext ( EditorContext ) ;
61
+ const editorModeStatus = useMemo ( ( ) => editorContext . editorModeStatus , [ editorContext . editorModeStatus ] ) ;
62
+
63
+ const basicSection = useMemo ( ( ) => (
64
+ < Section name = { sectionNames . basic } >
65
+ { props . children . chatName . propertyView ( {
66
+ label : "Chat Name" ,
67
+ tooltip : "Name displayed in the chat header"
68
+ } ) }
69
+ { props . children . userId . propertyView ( {
70
+ label : "User ID" ,
71
+ tooltip : "Unique identifier for the current user"
72
+ } ) }
73
+ { props . children . userName . propertyView ( {
74
+ label : "User Name" ,
75
+ tooltip : "Display name for the current user"
76
+ } ) }
77
+ { props . children . applicationId . propertyView ( {
78
+ label : "Application ID" ,
79
+ tooltip : "Unique identifier for this Lowcoder application - all chat components with the same Application ID can discover each other's rooms"
80
+ } ) }
81
+ { props . children . roomId . propertyView ( {
82
+ label : "Initial Room" ,
83
+ tooltip : "Default room to join when the component loads (within the application scope)"
84
+ } ) }
85
+ { props . children . mode . propertyView ( {
86
+ label : "Sync Mode" ,
87
+ tooltip : "Choose how messages are synchronized: Collaborative (real-time), Hybrid (local + real-time), or Local only"
88
+ } ) }
89
+ </ Section >
90
+ ) , [ props . children ] ) ;
91
+
92
+ const roomManagementSection = useMemo ( ( ) => (
93
+ < Section name = "Room Management" >
94
+ { props . children . allowRoomCreation . propertyView ( {
95
+ label : "Allow Room Creation" ,
96
+ tooltip : "Allow users to create new chat rooms"
97
+ } ) }
98
+ { props . children . allowRoomJoining . propertyView ( {
99
+ label : "Allow Room Joining" ,
100
+ tooltip : "Allow users to join existing rooms"
101
+ } ) }
102
+ { props . children . roomPermissionMode . propertyView ( {
103
+ label : "Permission Mode" ,
104
+ tooltip : "Control how users can join rooms"
105
+ } ) }
106
+ { props . children . showAvailableRooms . propertyView ( {
107
+ label : "Show Available Rooms" ,
108
+ tooltip : "Display list of available rooms to join"
109
+ } ) }
110
+ { props . children . maxRoomsDisplay . propertyView ( {
111
+ label : "Max Rooms to Display" ,
112
+ tooltip : "Maximum number of rooms to show in the list"
113
+ } ) }
114
+ </ Section >
115
+ ) , [ props . children ] ) ;
116
+
117
+ const interactionSection = useMemo ( ( ) =>
118
+ [ "logic" , "both" ] . includes ( editorModeStatus ) && (
119
+ < Section name = { sectionNames . interaction } >
120
+ { hiddenPropertyView ( props . children ) }
121
+ { props . children . onEvent . getPropertyView ( ) }
122
+ </ Section >
123
+ ) , [ editorModeStatus , props . children ] ) ;
124
+
125
+ const layoutSection = useMemo ( ( ) =>
126
+ [ "layout" , "both" ] . includes ( editorModeStatus ) && (
127
+ < >
128
+ < Section name = { sectionNames . layout } >
129
+ { props . children . autoHeight . getPropertyView ( ) }
130
+ { props . children . leftPanelWidth . propertyView ( {
131
+ label : "Left Panel Width" ,
132
+ tooltip : "Width of the rooms/people panel (e.g., 300px, 25%)"
133
+ } ) }
134
+ { props . children . showRooms . propertyView ( {
135
+ label : "Show Rooms"
136
+ } ) }
137
+ </ Section >
138
+ < Section name = { sectionNames . style } >
139
+ { props . children . style . getPropertyView ( ) }
140
+ </ Section >
141
+ < Section name = { sectionNames . animationStyle } hasTooltip = { true } >
142
+ { props . children . animationStyle . getPropertyView ( ) }
143
+ </ Section >
144
+ </ >
145
+ ) , [ editorModeStatus , props . children ] ) ;
146
+
147
+ return (
148
+ < >
149
+ { basicSection }
150
+ { roomManagementSection }
151
+ { interactionSection }
152
+ { layoutSection }
153
+ </ >
154
+ ) ;
155
+ } ) ;
0 commit comments