|
1 | 1 | package com.kjcommunities |
2 | 2 |
|
| 3 | +/** |
| 4 | + * KJDemoScreen - A comprehensive demonstration screen for the Rich Text Editor library. |
| 5 | + * |
| 6 | + * This class serves as a Slack-like chat interface that demonstrates how to: |
| 7 | + * - Configure and use RichTextState with custom styling (green hyperlinks, code spans, list indentation) |
| 8 | + * - Implement a rich text editor with a custom toolbar panel |
| 9 | + * - Display formatted messages using the RichText component |
| 10 | + * - Handle Lexical JSON import/export functionality |
| 11 | + * - Copy Lexical JSON data to clipboard for debugging |
| 12 | + * - Manage multiple RichTextState instances for chat messages |
| 13 | + * - Integrate link dialog functionality for hyperlink creation/editing |
| 14 | + * |
| 15 | + * The screen includes: |
| 16 | + * - Clean top navigation bar with back button |
| 17 | + * - Message display area showing formatted rich text content |
| 18 | + * - Rich text editor with formatting toolbar at the bottom |
| 19 | + * - Send functionality to add messages to the chat |
| 20 | + * |
| 21 | + * This serves as a clean, production-ready demo interface for the rich text editor library. |
| 22 | + */ |
| 23 | + |
3 | 24 | import androidx.compose.foundation.Image |
4 | 25 | import androidx.compose.foundation.background |
5 | 26 | import androidx.compose.foundation.border |
@@ -54,7 +75,7 @@ fun KJDemoScreen( |
54 | 75 | val openLinkDialog = remember { mutableStateOf(false) } |
55 | 76 |
|
56 | 77 | LaunchedEffect(Unit) { |
57 | | - richTextState.config.linkColor = Color(0xFF1d9bd1) |
| 78 | + richTextState.config.linkColor = Color(0xFF00C851) // Green color for links |
58 | 79 | richTextState.config.linkTextDecoration = TextDecoration.None |
59 | 80 | richTextState.config.codeSpanColor = Color(0xFFd7882d) |
60 | 81 | richTextState.config.codeSpanBackgroundColor = Color.Transparent |
@@ -82,114 +103,7 @@ fun KJDemoScreen( |
82 | 103 | } |
83 | 104 | }, |
84 | 105 | actions = { |
85 | | - // Test icon 0: Run round-trip test |
86 | | - IconButton( |
87 | | - onClick = { |
88 | | - try { |
89 | | - println("🧪 Running Lexical Round-Trip Test...") |
90 | | - val testResult = LexicalRoundTripTest.runTest() |
91 | | - |
92 | | - if (testResult.success) { |
93 | | - println("✅ ROUND-TRIP TEST PASSED!") |
94 | | - println("- Text matches: ${testResult.textMatches}") |
95 | | - println("- Demo JSON works: ${testResult.demoJsonWorks}") |
96 | | - println("- Heading styles work: ${testResult.headingStylesWork}") |
97 | | - println("- Original length: ${testResult.originalTextLength}") |
98 | | - println("- Imported length: ${testResult.importedTextLength}") |
99 | | - println("- JSON length: ${testResult.exportedJsonLength}") |
100 | | - } else { |
101 | | - println("❌ ROUND-TRIP TEST FAILED!") |
102 | | - testResult.error?.let { println("Error: $it") } |
103 | | - println("- Text matches: ${testResult.textMatches}") |
104 | | - println("- Demo JSON works: ${testResult.demoJsonWorks}") |
105 | | - println("- Heading styles work: ${testResult.headingStylesWork}") |
106 | | - } |
107 | | - |
108 | | - println("Details: ${testResult.details}") |
109 | | - } catch (e: Exception) { |
110 | | - println("🧪 ❌ ERROR in round-trip test: ${e.message}") |
111 | | - e.printStackTrace() |
112 | | - } |
113 | | - } |
114 | | - ) { |
115 | | - Icon( |
116 | | - imageVector = Icons.Outlined.PlayArrow, |
117 | | - contentDescription = "Run Round-Trip Test", |
118 | | - tint = Color.Green |
119 | | - ) |
120 | | - } |
121 | | - |
122 | | - // Test icon 1: Load minified JSON from resource file |
123 | | - IconButton( |
124 | | - onClick = { |
125 | | - try { |
126 | | - val minifiedJson = LexicalTestData.getMinifiedTestJson() |
127 | | - |
128 | | - println("🔥 JSON Length: ${minifiedJson.length}") |
129 | | - println("🔥 Creating new RichTextState...") |
130 | | - |
131 | | - // Create a new RichTextState and load the JSON |
132 | | - val testMessage = RichTextState() |
133 | | - println("🔥 Calling setLexicalText...") |
134 | | - testMessage.setLexicalText(minifiedJson) |
135 | | - |
136 | | - println("🔥 setLexicalText completed. Message text length: ${testMessage.annotatedString.text.length}") |
137 | | - println("🔥 Message text: ${testMessage.annotatedString.text.take(100)}...") |
138 | | - |
139 | | - // Add it to the messages |
140 | | - println("🔥 Current messages list size: ${messages.size}") |
141 | | - messages.add(testMessage) |
142 | | - println("🔥 Messages list size after add: ${messages.size}") |
143 | | - |
144 | | - println("🔥 ✅ MINIFIED JSON TEST COMPLETED SUCCESSFULLY") |
145 | | - } catch (e: Exception) { |
146 | | - println("🔥 ❌ ERROR in minified JSON test: ${e.message}") |
147 | | - e.printStackTrace() |
148 | | - } |
149 | | - } |
150 | | - ) { |
151 | | - Icon( |
152 | | - imageVector = Icons.Outlined.PlayArrow, |
153 | | - contentDescription = "Load Minified JSON Test", |
154 | | - tint = Color.White |
155 | | - ) |
156 | | - } |
157 | | - |
158 | | - // Test icon 2: Load pretty-printed JSON from resource file |
159 | | - IconButton( |
160 | | - onClick = { |
161 | | - try { |
162 | | - val prettyJson = LexicalTestData.getPrettyTestJson() |
163 | | - |
164 | | - println("🌟 Pretty JSON Length: ${prettyJson.length}") |
165 | | - println("🌟 Creating new RichTextState...") |
166 | | - |
167 | | - // Create a new RichTextState and load the JSON |
168 | | - val testMessage = RichTextState() |
169 | | - println("🌟 Calling setLexicalText...") |
170 | | - testMessage.setLexicalText(prettyJson) |
171 | | - |
172 | | - println("🌟 setLexicalText completed. Message text length: ${testMessage.annotatedString.text.length}") |
173 | | - println("🌟 Message text: ${testMessage.annotatedString.text.take(100)}...") |
174 | | - |
175 | | - // Add it to the messages |
176 | | - println("🌟 Current messages list size: ${messages.size}") |
177 | | - messages.add(testMessage) |
178 | | - println("🌟 Messages list size after add: ${messages.size}") |
179 | | - |
180 | | - println("🌟 ✅ PRETTY JSON TEST COMPLETED SUCCESSFULLY") |
181 | | - } catch (e: Exception) { |
182 | | - println("🌟 ❌ ERROR in pretty JSON test: ${e.message}") |
183 | | - e.printStackTrace() |
184 | | - } |
185 | | - } |
186 | | - ) { |
187 | | - Icon( |
188 | | - imageVector = Icons.Outlined.Settings, |
189 | | - contentDescription = "Load Pretty JSON Test", |
190 | | - tint = Color.White |
191 | | - ) |
192 | | - } |
| 106 | + // Actions removed for cleaner demo interface |
193 | 107 | }, |
194 | 108 | colors = TopAppBarDefaults.topAppBarColors( |
195 | 109 | containerColor = Color(0xFF1a1d21), |
@@ -265,7 +179,7 @@ fun KJDemoScreen( |
265 | 179 | clipboardManager.setText(AnnotatedString(lexicalJson)) |
266 | 180 | // TODO: Could add a toast/snackbar here to show success |
267 | 181 | } catch (e: Exception) { |
268 | | - println("Error copying Lexical JSON: ${e.message}") |
| 182 | + e.printStackTrace() |
269 | 183 | } |
270 | 184 | }, |
271 | 185 | modifier = Modifier.size(24.dp) |
|
0 commit comments