Skip to content

Commit dde9963

Browse files
committed
Adding in docs
1 parent 26daf56 commit dde9963

File tree

9 files changed

+420
-33
lines changed

9 files changed

+420
-33
lines changed

richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextConfig.kt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
11
package com.mohamedrejeb.richeditor.model
22

3+
/**
4+
* RichTextConfig - Configuration management class for customizing Rich Text Editor appearance and behavior.
5+
*
6+
* This class provides centralized configuration for all visual and behavioral aspects of the rich text editor:
7+
*
8+
* **Link Styling Configuration**:
9+
* - `linkColor`: Sets the color for hyperlink text (default: Color.Blue)
10+
* - `linkTextDecoration`: Controls link text decoration like underlines (default: TextDecoration.Underline)
11+
*
12+
* **Code Span Styling Configuration**:
13+
* - `codeSpanColor`: Text color for inline code spans (default: Color.Unspecified)
14+
* - `codeSpanBackgroundColor`: Background color for code spans (default: Color.Transparent)
15+
* - `codeSpanStrokeColor`: Border/stroke color for code spans (default: Color.LightGray)
16+
*
17+
* **List Indentation Configuration**:
18+
* - `listIndent`: Universal indentation for both ordered and unordered lists (default: 38)
19+
* - `orderedListIndent`: Specific indentation for numbered lists (default: 38)
20+
* - `unorderedListIndent`: Specific indentation for bullet lists (default: 38)
21+
*
22+
* **List Style Type Configuration**:
23+
* - `orderedListStyleType`: Numbering style for ordered lists (1,2,3 vs i,ii,iii vs A,B,C)
24+
* - `unorderedListStyleType`: Bullet style for unordered lists (•, ◦, ▪)
25+
*
26+
* **Editor Behavior Configuration**:
27+
* - `preserveStyleOnEmptyLine`: Whether formatting persists on empty lines (default: true)
28+
* - `exitListOnEmptyItem`: Whether pressing Enter on empty list item exits the list (default: true)
29+
*
30+
* **Key Features**:
31+
* - **Reactive Updates**: All configuration changes automatically trigger UI updates
32+
* - **Nested List Support**: Different styles for different nesting levels
33+
* - **Cross-Platform Consistency**: Same configuration works across all supported platforms
34+
* - **Runtime Modification**: Configuration can be changed dynamically during editor usage
35+
*
36+
* **Usage Patterns**:
37+
* - Access via `richTextState.config` property
38+
* - Modify properties directly to see immediate visual changes
39+
* - Commonly used for theming and customizing editor appearance
40+
* - Essential for implementing custom formatting toolbars and style controls
41+
*
42+
* This configuration system enables developers to create rich text editors that match their
43+
* application's design system and user experience requirements.
44+
*/
45+
346
import androidx.compose.ui.graphics.Color
447
import androidx.compose.ui.text.style.TextDecoration
548
import com.mohamedrejeb.richeditor.paragraph.type.OrderedListStyleType

richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextState.kt

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
package com.mohamedrejeb.richeditor.model
22

3+
/**
4+
* RichTextState - The core state management class for the Rich Text Editor library.
5+
*
6+
* This class serves as the central hub for managing all aspects of rich text editing and provides:
7+
* - **Text Content Management**: Stores and manages the rich text content with formatting
8+
* - **Selection and Cursor Control**: Tracks text selection, cursor position, and composition state
9+
* - **Styling Operations**: Applies and manages span styles (bold, italic, etc.) and paragraph styles
10+
* - **List Management**: Handles ordered/unordered lists with nesting and indentation
11+
* - **Link Management**: Creates, edits, and removes hyperlinks with custom styling
12+
* - **Import/Export Functionality**: Converts between rich text and HTML/Markdown/Lexical formats
13+
* - **Configuration Management**: Provides centralized configuration for colors, indentation, and behavior
14+
* - **State Persistence**: Supports saving and restoring editor state across sessions
15+
*
16+
* Key architectural features:
17+
* - **Reactive State**: Uses Compose state management for automatic UI updates
18+
* - **Immutable Operations**: All text modifications return new state instances
19+
* - **Format Compatibility**: Supports multiple rich text formats (HTML, Markdown, Lexical JSON)
20+
* - **Cross-Platform**: Works consistently across Android, Desktop, iOS, and Web platforms
21+
* - **Performance Optimized**: Efficient text processing and minimal recompositions
22+
*
23+
* Usage patterns:
24+
* - **Editor Integration**: Used with RichTextEditor composables for interactive editing
25+
* - **Display Integration**: Used with RichText composables for read-only display
26+
* - **Programmatic Control**: Allows full programmatic control over text content and formatting
27+
* - **Custom Toolbars**: Provides state information for building custom formatting toolbars
28+
*
29+
* This class is the foundation that enables rich text editing capabilities across the entire library
30+
* and serves as the primary interface for developers implementing rich text functionality.
31+
*/
32+
333
import androidx.compose.foundation.text.InlineTextContent
434
import androidx.compose.runtime.*
535
import androidx.compose.runtime.saveable.Saver
@@ -46,6 +76,49 @@ import kotlin.reflect.KClass
4676
import com.mohamedrejeb.richeditor.parser.utils.H1SpanStyle
4777
import com.mohamedrejeb.richeditor.parser.utils.H2SpanStyle
4878

79+
/**
80+
* rememberRichTextState - Creates and remembers a RichTextState instance with automatic state preservation.
81+
*
82+
* This composable function provides the standard way to create and manage RichTextState in Compose:
83+
*
84+
* **State Management Features**:
85+
* - **Automatic Persistence**: Saves and restores rich text content across configuration changes
86+
* - **Compose Integration**: Fully integrated with Compose's state management system
87+
* - **Memory Efficiency**: Efficiently manages state lifecycle and memory usage
88+
* - **Recomposition Optimization**: Minimizes unnecessary recompositions for better performance
89+
*
90+
* **Persistence Behavior**:
91+
* - **Content Preservation**: Rich text content and formatting are preserved across app lifecycle
92+
* - **Selection State**: Text selection and cursor position are maintained during state restoration
93+
* - **Configuration Changes**: Survives screen rotations, theme changes, and other configuration updates
94+
* - **Process Death**: Handles Android process death and restoration gracefully
95+
*
96+
* **Usage Patterns**:
97+
* - **Standard Creation**: Primary method for creating RichTextState in Compose applications
98+
* - **Screen-Level State**: Typically called at screen or major component level
99+
* - **Shared State**: Can be passed down to child components for shared rich text editing
100+
* - **Multiple Instances**: Multiple independent instances can be created for different text fields
101+
*
102+
* **Integration Examples**:
103+
* ```kotlin
104+
* // Basic usage
105+
* val richTextState = rememberRichTextState()
106+
* RichTextEditor(state = richTextState)
107+
*
108+
* // With initial content
109+
* val richTextState = rememberRichTextState()
110+
* LaunchedEffect(Unit) {
111+
* richTextState.setHtml("<p><b>Initial content</b></p>")
112+
* }
113+
*
114+
* // Multiple editors
115+
* val titleState = rememberRichTextState()
116+
* val contentState = rememberRichTextState()
117+
* ```
118+
*
119+
* This function is essential for proper rich text state management in Compose applications
120+
* and ensures optimal user experience with automatic state preservation.
121+
*/
49122
@Composable
50123
public fun rememberRichTextState(): RichTextState {
51124
return rememberSaveable(saver = RichTextState.Saver) {

richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichText.kt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
11
package com.mohamedrejeb.richeditor.ui
22

3+
/**
4+
* BasicRichText - A foundational composable for displaying rich text content in read-only mode.
5+
*
6+
* This composable serves as the core display component for rich text content and provides:
7+
*
8+
* **Rich Text Display Capabilities**:
9+
* - **Formatted Text Rendering**: Displays text with bold, italic, underline, color, and other formatting
10+
* - **Interactive Links**: Clickable hyperlinks with hover states and custom styling
11+
* - **List Visualization**: Properly formatted ordered and unordered lists with nesting
12+
* - **Code Span Display**: Inline code formatting with background and border styling
13+
* - **Custom Styling**: Support for custom rich span styles and visual effects
14+
* - **Typography Integration**: Seamless integration with Compose typography systems
15+
*
16+
* **Interaction Features**:
17+
* - **Link Navigation**: Automatic link handling with platform-appropriate URL opening
18+
* - **Text Selection**: Optional text selection for copying formatted content
19+
* - **Hover Effects**: Mouse hover states for interactive elements (desktop platforms)
20+
* - **Touch Feedback**: Appropriate touch feedback for interactive elements
21+
* - **Accessibility**: Full screen reader and accessibility service integration
22+
*
23+
* **Layout and Styling**:
24+
* - **Text Flow**: Proper text wrapping, line breaking, and paragraph spacing
25+
* - **Overflow Handling**: Configurable text overflow behavior (clip, ellipsis, visible)
26+
* - **Line Limits**: Support for maximum and minimum line constraints
27+
* - **Inline Content**: Support for embedding custom composables within text
28+
* - **Text Measurement**: Provides text layout results for advanced positioning
29+
*
30+
* **Performance Optimization**:
31+
* - **Efficient Rendering**: Optimized for displaying large rich text documents
32+
* - **Lazy Loading**: Supports lazy loading of images and embedded content
33+
* - **Memory Management**: Efficient memory usage for complex formatted text
34+
* - **Recomposition Optimization**: Minimal recompositions for better performance
35+
*
36+
* **Platform Integration**:
37+
* - **Cross-Platform**: Consistent rendering across Android, Desktop, iOS, and Web
38+
* - **Image Loading**: Configurable image loading with custom ImageLoader support
39+
* - **URL Handling**: Platform-appropriate URL handling and external link opening
40+
* - **Font Support**: Support for custom fonts and platform-specific typography
41+
*
42+
* **Usage Patterns**:
43+
* - **Content Display**: Blog posts, articles, and formatted document display
44+
* - **Message Rendering**: Chat messages and communication content with rich formatting
45+
* - **Documentation**: Help text, tooltips, and instructional content
46+
* - **Previews**: Read-only previews of rich text content being edited elsewhere
47+
* - **Static Content**: Formatted static content like terms of service or about pages
48+
*
49+
* This component is designed for scenarios where rich text content needs to be displayed
50+
* without editing capabilities, providing optimal performance and user experience for
51+
* read-only rich text presentation.
52+
*/
53+
354
import androidx.compose.foundation.gestures.awaitEachGesture
455
import androidx.compose.foundation.text.BasicText
556
import androidx.compose.foundation.text.InlineTextContent

richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11
package com.mohamedrejeb.richeditor.ui
22

3+
/**
4+
* BasicRichTextEditor - The foundational composable for rich text editing functionality.
5+
*
6+
* This composable serves as the core building block for all rich text editing interfaces and provides:
7+
*
8+
* **Core Editing Capabilities**:
9+
* - **Rich Text Input**: Handles text input with formatting preservation and application
10+
* - **Selection Management**: Manages text selection, cursor positioning, and composition state
11+
* - **Keyboard Integration**: Processes keyboard input, shortcuts, and IME actions
12+
* - **Touch Interaction**: Handles tap gestures, text selection, and cursor placement
13+
* - **Clipboard Operations**: Supports copy, cut, paste with rich formatting preservation
14+
*
15+
* **Styling and Formatting**:
16+
* - **Span Styles**: Applies bold, italic, underline, color, and other character-level formatting
17+
* - **Paragraph Styles**: Manages paragraph-level formatting like alignment and indentation
18+
* - **List Support**: Handles ordered and unordered lists with proper nesting
19+
* - **Link Management**: Creates and manages hyperlinks with custom styling
20+
* - **Custom Styles**: Supports custom rich span styles and visual transformations
21+
*
22+
* **Platform Integration**:
23+
* - **Cross-Platform**: Works consistently across Android, Desktop, iOS, and Web
24+
* - **Accessibility**: Integrates with platform accessibility services
25+
* - **Input Methods**: Supports various input methods and keyboard layouts
26+
* - **Performance**: Optimized for smooth editing experience with large documents
27+
*
28+
* **Architecture Features**:
29+
* - **Decoration Box Pattern**: Uses decoration box for flexible UI customization
30+
* - **State Management**: Integrates with RichTextState for reactive updates
31+
* - **Modifier Support**: Fully supports Compose modifier chain for styling
32+
* - **Interaction Source**: Provides interaction state for custom UI behaviors
33+
*
34+
* **Usage Patterns**:
35+
* - **Foundation Component**: Used as base for Material Design text fields (RichTextEditor, OutlinedRichTextEditor)
36+
* - **Custom Implementations**: Enables building custom rich text editors with specific design requirements
37+
* - **Minimal UI**: Provides rich text editing without built-in decorations like borders or labels
38+
* - **Advanced Customization**: Allows full control over appearance through decoration box parameter
39+
*
40+
* This composable is designed for developers who need maximum flexibility in creating rich text
41+
* editing interfaces while maintaining full rich text functionality and cross-platform compatibility.
42+
*/
43+
344
import androidx.compose.foundation.interaction.Interaction
445
import androidx.compose.foundation.interaction.MutableInteractionSource
546
import androidx.compose.foundation.interaction.PressInteraction

richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material3/OutlinedRichTextEditor.kt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
11
package com.mohamedrejeb.richeditor.ui.material3
22

3+
/**
4+
* OutlinedRichTextEditor (Material 3) - A Material Design 3 outlined text field with rich text editing capabilities.
5+
*
6+
* This composable provides a Material Design 3 outlined text field experience with comprehensive rich text support:
7+
*
8+
* **Material Design 3 Outlined Features**:
9+
* - **Outlined Container**: Clean outlined design with customizable border colors and thickness
10+
* - **Label Cutout**: Floating label with proper border cutout for seamless integration
11+
* - **Focus Animation**: Smooth border color and thickness transitions on focus changes
12+
* - **Supporting Text**: Helper text positioned below the field for guidance or validation
13+
* - **Leading/Trailing Icons**: Icon slots with proper spacing and alignment
14+
* - **Error Handling**: Comprehensive error state styling with color and border changes
15+
* - **Transparent Background**: Clean appearance that works well on various backgrounds
16+
*
17+
* **Rich Text Editing Features**:
18+
* - **Character Formatting**: Bold, italic, underline, strikethrough, color, and font styling
19+
* - **Paragraph Control**: Text alignment, indentation, line height, and spacing
20+
* - **List Management**: Nested ordered and unordered lists with customizable styling
21+
* - **Link Creation**: Interactive hyperlinks with hover states and custom appearance
22+
* - **Code Formatting**: Inline code spans with syntax highlighting support
23+
* - **Format Conversion**: Seamless import/export between HTML, Markdown, and Lexical formats
24+
*
25+
* **Advanced Interaction**:
26+
* - **Keyboard Shortcuts**: Full keyboard shortcut support for formatting operations
27+
* - **Gesture Recognition**: Touch gestures for text selection and cursor positioning
28+
* - **Clipboard Rich Text**: Preserves formatting in copy/paste operations
29+
* - **Undo/Redo System**: Comprehensive undo/redo with formatting state preservation
30+
* - **Selection Management**: Advanced text selection with formatting context awareness
31+
*
32+
* **Design System Integration**:
33+
* - **Theme Compatibility**: Automatically adapts to Material 3 color schemes and typography
34+
* - **Density Support**: Responds to Material density settings for compact/comfortable layouts
35+
* - **Motion Integration**: Uses Material motion specifications for animations
36+
* - **Accessibility First**: Built-in accessibility features following Material guidelines
37+
* - **Responsive Design**: Adapts to different screen sizes and orientations
38+
*
39+
* **Use Cases & Applications**:
40+
* - **Document Editing**: Professional document creation with rich formatting
41+
* - **Content Management**: CMS interfaces requiring formatted text input
42+
* - **Communication**: Email composition, messaging with rich text support
43+
* - **Educational**: Note-taking applications with formatting capabilities
44+
* - **Creative Writing**: Writing applications with advanced text formatting
45+
*
46+
* The outlined variant is particularly suitable for forms and interfaces where a cleaner,
47+
* less visually heavy appearance is desired while maintaining full rich text functionality
48+
* and Material Design 3 compliance.
49+
*/
50+
351
import androidx.compose.foundation.interaction.Interaction
452
import androidx.compose.foundation.interaction.MutableInteractionSource
553
import androidx.compose.foundation.layout.*

richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material3/RichText.kt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
11
package com.mohamedrejeb.richeditor.ui.material3
22

3+
/**
4+
* RichText (Material 3) - A Material Design 3 text component for displaying rich text content.
5+
*
6+
* This composable provides a Material Design 3 styled text display with comprehensive rich text support:
7+
*
8+
* **Material Design 3 Integration**:
9+
* - **Typography System**: Seamlessly integrates with Material 3 typography scale and font families
10+
* - **Color System**: Automatically adapts to Material 3 color schemes and theme changes
11+
* - **Content Color**: Respects Material 3 content color hierarchy and alpha values
12+
* - **Density Support**: Responds to Material density settings for optimal spacing
13+
* - **Theme Consistency**: Maintains visual consistency with other Material 3 components
14+
*
15+
* **Rich Text Display Features**:
16+
* - **Text Formatting**: Displays bold, italic, underline, strikethrough, and colored text
17+
* - **Interactive Hyperlinks**: Clickable links with Material 3 color theming and hover states
18+
* - **List Rendering**: Properly formatted ordered and unordered lists with Material spacing
19+
* - **Code Spans**: Inline code display with Material 3 surface colors and typography
20+
* - **Custom Styles**: Support for custom rich span styles following Material guidelines
21+
* - **Paragraph Styling**: Text alignment, line height, and spacing following Material specs
22+
*
23+
* **Typography and Layout**:
24+
* - **Font Scaling**: Respects system font size preferences and accessibility settings
25+
* - **Line Height**: Optimal line spacing for readability across different text sizes
26+
* - **Text Overflow**: Configurable overflow handling with ellipsis or clipping
27+
* - **Text Wrapping**: Intelligent word wrapping and line breaking
28+
* - **Baseline Alignment**: Proper baseline alignment with other Material components
29+
*
30+
* **Accessibility and Interaction**:
31+
* - **Screen Reader Support**: Full accessibility support with proper content descriptions
32+
* - **High Contrast**: Adapts to high contrast accessibility settings
33+
* - **Touch Targets**: Appropriate touch target sizes for interactive elements
34+
* - **Keyboard Navigation**: Support for keyboard navigation of interactive content
35+
* - **Focus Management**: Proper focus handling for embedded interactive elements
36+
*
37+
* **Performance and Platform**:
38+
* - **Efficient Rendering**: Optimized text rendering for smooth scrolling and performance
39+
* - **Cross-Platform**: Consistent appearance across Android, Desktop, iOS, and Web
40+
* - **Memory Optimization**: Efficient memory usage for large text documents
41+
* - **Image Integration**: Support for embedded images with Material loading states
42+
*
43+
* **Common Use Cases**:
44+
* - **Content Display**: Articles, blog posts, and formatted content in Material apps
45+
* - **Message Display**: Chat messages and communication content with rich formatting
46+
* - **Help Content**: Documentation, tooltips, and instructional text
47+
* - **Card Content**: Rich text content within Material cards and surfaces
48+
* - **List Items**: Formatted text within Material list items and components
49+
*
50+
* This component is ideal for displaying rich text content in Material Design 3 applications
51+
* where consistency with the design system and optimal user experience are priorities.
52+
*/
53+
354
import androidx.compose.foundation.text.InlineTextContent
455
import androidx.compose.material3.LocalContentColor
556
import androidx.compose.material3.LocalTextStyle

0 commit comments

Comments
 (0)