react-native-richify 1.0.0

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 (172) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +231 -0
  3. package/lib/commonjs/components/OverlayText.d.js +6 -0
  4. package/lib/commonjs/components/OverlayText.d.js.map +1 -0
  5. package/lib/commonjs/components/OverlayText.js +45 -0
  6. package/lib/commonjs/components/OverlayText.js.map +1 -0
  7. package/lib/commonjs/components/RichTextInput.d.js +6 -0
  8. package/lib/commonjs/components/RichTextInput.d.js.map +1 -0
  9. package/lib/commonjs/components/RichTextInput.js +160 -0
  10. package/lib/commonjs/components/RichTextInput.js.map +1 -0
  11. package/lib/commonjs/components/Toolbar.d.js +6 -0
  12. package/lib/commonjs/components/Toolbar.d.js.map +1 -0
  13. package/lib/commonjs/components/Toolbar.js +99 -0
  14. package/lib/commonjs/components/Toolbar.js.map +1 -0
  15. package/lib/commonjs/components/ToolbarButton.d.js +6 -0
  16. package/lib/commonjs/components/ToolbarButton.d.js.map +1 -0
  17. package/lib/commonjs/components/ToolbarButton.js +63 -0
  18. package/lib/commonjs/components/ToolbarButton.js.map +1 -0
  19. package/lib/commonjs/constants/defaultStyles.d.js +6 -0
  20. package/lib/commonjs/constants/defaultStyles.d.js.map +1 -0
  21. package/lib/commonjs/constants/defaultStyles.js +172 -0
  22. package/lib/commonjs/constants/defaultStyles.js.map +1 -0
  23. package/lib/commonjs/context/RichTextContext.d.js +6 -0
  24. package/lib/commonjs/context/RichTextContext.d.js.map +1 -0
  25. package/lib/commonjs/context/RichTextContext.js +61 -0
  26. package/lib/commonjs/context/RichTextContext.js.map +1 -0
  27. package/lib/commonjs/hooks/useFormatting.d.js +6 -0
  28. package/lib/commonjs/hooks/useFormatting.d.js.map +1 -0
  29. package/lib/commonjs/hooks/useFormatting.js +82 -0
  30. package/lib/commonjs/hooks/useFormatting.js.map +1 -0
  31. package/lib/commonjs/hooks/useRichText.d.js +6 -0
  32. package/lib/commonjs/hooks/useRichText.d.js.map +1 -0
  33. package/lib/commonjs/hooks/useRichText.js +136 -0
  34. package/lib/commonjs/hooks/useRichText.js.map +1 -0
  35. package/lib/commonjs/hooks/useSelection.d.js +6 -0
  36. package/lib/commonjs/hooks/useSelection.d.js.map +1 -0
  37. package/lib/commonjs/hooks/useSelection.js +39 -0
  38. package/lib/commonjs/hooks/useSelection.js.map +1 -0
  39. package/lib/commonjs/index.d.js +186 -0
  40. package/lib/commonjs/index.d.js.map +1 -0
  41. package/lib/commonjs/index.js +186 -0
  42. package/lib/commonjs/index.js.map +1 -0
  43. package/lib/commonjs/package.json +1 -0
  44. package/lib/commonjs/types/index.d.js +6 -0
  45. package/lib/commonjs/types/index.d.js.map +1 -0
  46. package/lib/commonjs/types/index.js +6 -0
  47. package/lib/commonjs/types/index.js.map +1 -0
  48. package/lib/commonjs/utils/formatter.d.js +13 -0
  49. package/lib/commonjs/utils/formatter.d.js.map +1 -0
  50. package/lib/commonjs/utils/formatter.js +229 -0
  51. package/lib/commonjs/utils/formatter.js.map +1 -0
  52. package/lib/commonjs/utils/parser.d.js +6 -0
  53. package/lib/commonjs/utils/parser.d.js.map +1 -0
  54. package/lib/commonjs/utils/parser.js +221 -0
  55. package/lib/commonjs/utils/parser.js.map +1 -0
  56. package/lib/commonjs/utils/styleMapper.d.js +6 -0
  57. package/lib/commonjs/utils/styleMapper.d.js.map +1 -0
  58. package/lib/commonjs/utils/styleMapper.js +87 -0
  59. package/lib/commonjs/utils/styleMapper.js.map +1 -0
  60. package/lib/module/components/OverlayText.d.js +4 -0
  61. package/lib/module/components/OverlayText.d.js.map +1 -0
  62. package/lib/module/components/OverlayText.js +41 -0
  63. package/lib/module/components/OverlayText.js.map +1 -0
  64. package/lib/module/components/RichTextInput.d.js +4 -0
  65. package/lib/module/components/RichTextInput.d.js.map +1 -0
  66. package/lib/module/components/RichTextInput.js +155 -0
  67. package/lib/module/components/RichTextInput.js.map +1 -0
  68. package/lib/module/components/Toolbar.d.js +4 -0
  69. package/lib/module/components/Toolbar.d.js.map +1 -0
  70. package/lib/module/components/Toolbar.js +95 -0
  71. package/lib/module/components/Toolbar.js.map +1 -0
  72. package/lib/module/components/ToolbarButton.d.js +4 -0
  73. package/lib/module/components/ToolbarButton.d.js.map +1 -0
  74. package/lib/module/components/ToolbarButton.js +59 -0
  75. package/lib/module/components/ToolbarButton.js.map +1 -0
  76. package/lib/module/constants/defaultStyles.d.js +4 -0
  77. package/lib/module/constants/defaultStyles.d.js.map +1 -0
  78. package/lib/module/constants/defaultStyles.js +168 -0
  79. package/lib/module/constants/defaultStyles.js.map +1 -0
  80. package/lib/module/context/RichTextContext.d.js +4 -0
  81. package/lib/module/context/RichTextContext.d.js.map +1 -0
  82. package/lib/module/context/RichTextContext.js +55 -0
  83. package/lib/module/context/RichTextContext.js.map +1 -0
  84. package/lib/module/hooks/useFormatting.d.js +11 -0
  85. package/lib/module/hooks/useFormatting.d.js.map +1 -0
  86. package/lib/module/hooks/useFormatting.js +78 -0
  87. package/lib/module/hooks/useFormatting.js.map +1 -0
  88. package/lib/module/hooks/useRichText.d.js +4 -0
  89. package/lib/module/hooks/useRichText.d.js.map +1 -0
  90. package/lib/module/hooks/useRichText.js +132 -0
  91. package/lib/module/hooks/useRichText.js.map +1 -0
  92. package/lib/module/hooks/useSelection.d.js +4 -0
  93. package/lib/module/hooks/useSelection.d.js.map +1 -0
  94. package/lib/module/hooks/useSelection.js +35 -0
  95. package/lib/module/hooks/useSelection.js.map +1 -0
  96. package/lib/module/index.d.js +15 -0
  97. package/lib/module/index.d.js.map +1 -0
  98. package/lib/module/index.js +25 -0
  99. package/lib/module/index.js.map +1 -0
  100. package/lib/module/types/index.d.js +4 -0
  101. package/lib/module/types/index.d.js.map +1 -0
  102. package/lib/module/types/index.js +4 -0
  103. package/lib/module/types/index.js.map +1 -0
  104. package/lib/module/utils/formatter.d.js +30 -0
  105. package/lib/module/utils/formatter.d.js.map +1 -0
  106. package/lib/module/utils/formatter.js +217 -0
  107. package/lib/module/utils/formatter.js.map +1 -0
  108. package/lib/module/utils/parser.d.js +4 -0
  109. package/lib/module/utils/parser.d.js.map +1 -0
  110. package/lib/module/utils/parser.js +211 -0
  111. package/lib/module/utils/parser.js.map +1 -0
  112. package/lib/module/utils/styleMapper.d.js +4 -0
  113. package/lib/module/utils/styleMapper.d.js.map +1 -0
  114. package/lib/module/utils/styleMapper.js +82 -0
  115. package/lib/module/utils/styleMapper.js.map +1 -0
  116. package/lib/typescript/src/components/OverlayText.d.ts +11 -0
  117. package/lib/typescript/src/components/OverlayText.d.ts.map +1 -0
  118. package/lib/typescript/src/components/RichTextInput.d.ts +21 -0
  119. package/lib/typescript/src/components/RichTextInput.d.ts.map +1 -0
  120. package/lib/typescript/src/components/Toolbar.d.ts +13 -0
  121. package/lib/typescript/src/components/Toolbar.d.ts.map +1 -0
  122. package/lib/typescript/src/components/ToolbarButton.d.ts +8 -0
  123. package/lib/typescript/src/components/ToolbarButton.d.ts.map +1 -0
  124. package/lib/typescript/src/constants/defaultStyles.d.ts +46 -0
  125. package/lib/typescript/src/constants/defaultStyles.d.ts.map +1 -0
  126. package/lib/typescript/src/context/RichTextContext.d.ts +31 -0
  127. package/lib/typescript/src/context/RichTextContext.d.ts.map +1 -0
  128. package/lib/typescript/src/hooks/useFormatting.d.ts +26 -0
  129. package/lib/typescript/src/hooks/useFormatting.d.ts.map +1 -0
  130. package/lib/typescript/src/hooks/useRichText.d.ts +17 -0
  131. package/lib/typescript/src/hooks/useRichText.d.ts.map +1 -0
  132. package/lib/typescript/src/hooks/useSelection.d.ts +14 -0
  133. package/lib/typescript/src/hooks/useSelection.d.ts.map +1 -0
  134. package/lib/typescript/src/index.d.ts +16 -0
  135. package/lib/typescript/src/index.d.ts.map +1 -0
  136. package/lib/typescript/src/types/index.d.ts +245 -0
  137. package/lib/typescript/src/types/index.d.ts.map +1 -0
  138. package/lib/typescript/src/utils/formatter.d.ts +29 -0
  139. package/lib/typescript/src/utils/formatter.d.ts.map +1 -0
  140. package/lib/typescript/src/utils/parser.d.ts +46 -0
  141. package/lib/typescript/src/utils/parser.d.ts.map +1 -0
  142. package/lib/typescript/src/utils/styleMapper.d.ts +16 -0
  143. package/lib/typescript/src/utils/styleMapper.d.ts.map +1 -0
  144. package/package.json +83 -0
  145. package/src/components/OverlayText.d.ts +10 -0
  146. package/src/components/OverlayText.tsx +46 -0
  147. package/src/components/RichTextInput.d.ts +20 -0
  148. package/src/components/RichTextInput.tsx +174 -0
  149. package/src/components/Toolbar.d.ts +12 -0
  150. package/src/components/Toolbar.tsx +100 -0
  151. package/src/components/ToolbarButton.d.ts +7 -0
  152. package/src/components/ToolbarButton.tsx +65 -0
  153. package/src/constants/defaultStyles.d.ts +45 -0
  154. package/src/constants/defaultStyles.ts +144 -0
  155. package/src/context/RichTextContext.d.ts +30 -0
  156. package/src/context/RichTextContext.tsx +63 -0
  157. package/src/hooks/useFormatting.d.ts +25 -0
  158. package/src/hooks/useFormatting.ts +135 -0
  159. package/src/hooks/useRichText.d.ts +16 -0
  160. package/src/hooks/useRichText.ts +171 -0
  161. package/src/hooks/useSelection.d.ts +13 -0
  162. package/src/hooks/useSelection.ts +40 -0
  163. package/src/index.d.ts +15 -0
  164. package/src/index.ts +68 -0
  165. package/src/types/index.d.ts +244 -0
  166. package/src/types/index.ts +295 -0
  167. package/src/utils/formatter.d.ts +28 -0
  168. package/src/utils/formatter.ts +276 -0
  169. package/src/utils/parser.d.ts +45 -0
  170. package/src/utils/parser.ts +252 -0
  171. package/src/utils/styleMapper.d.ts +15 -0
  172. package/src/utils/styleMapper.ts +92 -0
@@ -0,0 +1,244 @@
1
+ import type { TextStyle, ViewStyle, TextInputProps, ColorValue } from 'react-native';
2
+ /**
3
+ * Supported inline formatting types.
4
+ */
5
+ export type FormatType = 'bold' | 'italic' | 'underline' | 'strikethrough' | 'code';
6
+ /**
7
+ * Heading level presets.
8
+ */
9
+ export type HeadingLevel = 'h1' | 'h2' | 'h3' | 'none';
10
+ /**
11
+ * List type for a line/paragraph.
12
+ */
13
+ export type ListType = 'bullet' | 'ordered' | 'none';
14
+ /**
15
+ * Inline formatting styles attached to a text segment.
16
+ */
17
+ export interface FormatStyle {
18
+ bold?: boolean;
19
+ italic?: boolean;
20
+ underline?: boolean;
21
+ strikethrough?: boolean;
22
+ code?: boolean;
23
+ color?: string;
24
+ backgroundColor?: string;
25
+ fontSize?: number;
26
+ heading?: HeadingLevel;
27
+ }
28
+ /**
29
+ * A segment of text with uniform formatting.
30
+ * The entire rich text content is an ordered array of these segments.
31
+ */
32
+ export interface StyledSegment {
33
+ /** The text content of this segment. */
34
+ text: string;
35
+ /** The formatting styles applied to this segment. */
36
+ styles: FormatStyle;
37
+ }
38
+ /**
39
+ * Represents a text selection range within the input.
40
+ */
41
+ export interface SelectionRange {
42
+ /** Start index (inclusive). */
43
+ start: number;
44
+ /** End index (exclusive). */
45
+ end: number;
46
+ }
47
+ /**
48
+ * The complete state of the rich text input.
49
+ */
50
+ export interface RichTextState {
51
+ /** Ordered array of styled text segments. */
52
+ segments: StyledSegment[];
53
+ /** Current selection range. */
54
+ selection: SelectionRange;
55
+ /** The current active styles that will be applied to newly typed text. */
56
+ activeStyles: FormatStyle;
57
+ }
58
+ /**
59
+ * Actions returned by the useRichText hook for controlling the editor.
60
+ */
61
+ export interface RichTextActions {
62
+ /** Toggle an inline format on the current selection or active styles. */
63
+ toggleFormat: (format: FormatType) => void;
64
+ /** Set a specific style property on the current selection. */
65
+ setStyleProperty: <K extends keyof FormatStyle>(key: K, value: FormatStyle[K]) => void;
66
+ /** Apply a heading level to the current line. */
67
+ setHeading: (level: HeadingLevel) => void;
68
+ /** Set the text color for the current selection. */
69
+ setColor: (color: string) => void;
70
+ /** Set the background color for the current selection. */
71
+ setBackgroundColor: (color: string) => void;
72
+ /** Set the font size for the current selection. */
73
+ setFontSize: (size: number) => void;
74
+ /** Handle text change from TextInput. */
75
+ handleTextChange: (text: string) => void;
76
+ /** Handle selection change from TextInput. */
77
+ handleSelectionChange: (selection: SelectionRange) => void;
78
+ /** Get the full plain text content. */
79
+ getPlainText: () => string;
80
+ /** Export the segments as a serializable JSON array. */
81
+ exportJSON: () => StyledSegment[];
82
+ /** Import segments from a JSON array, replacing current content. */
83
+ importJSON: (segments: StyledSegment[]) => void;
84
+ /** Clear all content. */
85
+ clear: () => void;
86
+ }
87
+ /**
88
+ * Return value of the useRichText hook.
89
+ */
90
+ export interface UseRichTextReturn {
91
+ state: RichTextState;
92
+ actions: RichTextActions;
93
+ }
94
+ /**
95
+ * Theme configuration for the RichTextInput component.
96
+ */
97
+ export interface RichTextTheme {
98
+ /** Style for the outer container. */
99
+ containerStyle?: ViewStyle;
100
+ /** Style for the TextInput. */
101
+ inputStyle?: TextStyle;
102
+ /** Style for the overlay text container. */
103
+ overlayContainerStyle?: ViewStyle;
104
+ /** Base text style applied to all segments before formatting. */
105
+ baseTextStyle?: TextStyle;
106
+ /** Style for the toolbar container. */
107
+ toolbarStyle?: ViewStyle;
108
+ /** Style for toolbar buttons. */
109
+ toolbarButtonStyle?: ViewStyle;
110
+ /** Style for active toolbar buttons. */
111
+ toolbarButtonActiveStyle?: ViewStyle;
112
+ /** Text style for toolbar button labels. */
113
+ toolbarButtonTextStyle?: TextStyle;
114
+ /** Text style for active toolbar button labels. */
115
+ toolbarButtonActiveTextStyle?: TextStyle;
116
+ /** Style for the code format. */
117
+ codeStyle?: TextStyle;
118
+ /** Colors */
119
+ colors?: {
120
+ /** Primary accent color. */
121
+ primary?: string;
122
+ /** Background color of the editor. */
123
+ background?: string;
124
+ /** Text color. */
125
+ text?: string;
126
+ /** Placeholder text color. */
127
+ placeholder?: string;
128
+ /** Toolbar background. */
129
+ toolbarBackground?: string;
130
+ /** Toolbar border color. */
131
+ toolbarBorder?: string;
132
+ /** Cursor / caret color. */
133
+ cursor?: ColorValue;
134
+ };
135
+ }
136
+ /**
137
+ * A toolbar item configuration.
138
+ */
139
+ export interface ToolbarItem {
140
+ /** Unique identifier. */
141
+ id: string;
142
+ /** Display label or icon text. */
143
+ label: string;
144
+ /** The format type this button toggles (for inline formats). */
145
+ format?: FormatType;
146
+ /** The heading level this button sets. */
147
+ heading?: HeadingLevel;
148
+ /** Custom action handler (overrides default behavior). */
149
+ onPress?: () => void;
150
+ /** Whether this item is currently active. */
151
+ active?: boolean;
152
+ /** Custom render function for the button. */
153
+ renderButton?: (props: {
154
+ active: boolean;
155
+ onPress: () => void;
156
+ label: string;
157
+ }) => React.ReactElement;
158
+ }
159
+ /**
160
+ * Props for the OverlayText component.
161
+ */
162
+ export interface OverlayTextProps {
163
+ /** The styled segments to render. */
164
+ segments: StyledSegment[];
165
+ /** Base text style. */
166
+ baseTextStyle?: TextStyle;
167
+ /** Theme overrides. */
168
+ theme?: RichTextTheme;
169
+ }
170
+ /**
171
+ * Props for the ToolbarButton component.
172
+ */
173
+ export interface ToolbarButtonProps {
174
+ /** Button label text. */
175
+ label: string;
176
+ /** Whether the button is currently active. */
177
+ active: boolean;
178
+ /** Press handler. */
179
+ onPress: () => void;
180
+ /** Theme overrides. */
181
+ theme?: RichTextTheme;
182
+ /** Custom render function. */
183
+ renderButton?: ToolbarItem['renderButton'];
184
+ }
185
+ /**
186
+ * Props for the Toolbar component.
187
+ */
188
+ export interface ToolbarProps {
189
+ /** The current rich text actions. */
190
+ actions: RichTextActions;
191
+ /** The current rich text state. */
192
+ state: RichTextState;
193
+ /** Custom toolbar items (overrides defaults). */
194
+ items?: ToolbarItem[];
195
+ /** Theme overrides. */
196
+ theme?: RichTextTheme;
197
+ /** Whether to show the toolbar. */
198
+ visible?: boolean;
199
+ /** Custom render function for the entire toolbar. */
200
+ renderToolbar?: (props: {
201
+ items: ToolbarItem[];
202
+ state: RichTextState;
203
+ actions: RichTextActions;
204
+ }) => React.ReactElement;
205
+ }
206
+ /**
207
+ * Props for the main RichTextInput component.
208
+ */
209
+ export interface RichTextInputProps {
210
+ /** Initial segments to populate the editor with. */
211
+ initialSegments?: StyledSegment[];
212
+ /** Callback when the content changes. */
213
+ onChangeSegments?: (segments: StyledSegment[]) => void;
214
+ /** Callback when the plain text changes. */
215
+ onChangeText?: (text: string) => void;
216
+ /** Placeholder text. */
217
+ placeholder?: string;
218
+ /** Whether the input is editable. */
219
+ editable?: boolean;
220
+ /** Maximum character length. */
221
+ maxLength?: number;
222
+ /** Whether to show the toolbar. */
223
+ showToolbar?: boolean;
224
+ /** Toolbar position relative to the input. */
225
+ toolbarPosition?: 'top' | 'bottom';
226
+ /** Custom toolbar items. */
227
+ toolbarItems?: ToolbarItem[];
228
+ /** Theme configuration. */
229
+ theme?: RichTextTheme;
230
+ /** Whether multiline input is enabled. */
231
+ multiline?: boolean;
232
+ /** Minimum height for the input area. */
233
+ minHeight?: number;
234
+ /** Maximum height for the input area. */
235
+ maxHeight?: number;
236
+ /** Auto-focus the input on mount. */
237
+ autoFocus?: boolean;
238
+ /** Additional TextInput props. */
239
+ textInputProps?: Omit<TextInputProps, 'value' | 'onChangeText' | 'onSelectionChange' | 'multiline' | 'placeholder' | 'editable' | 'maxLength' | 'autoFocus'>;
240
+ /** Custom toolbar render function. */
241
+ renderToolbar?: ToolbarProps['renderToolbar'];
242
+ /** Ref callback to access actions. */
243
+ onReady?: (actions: RichTextActions) => void;
244
+ }
@@ -0,0 +1,295 @@
1
+ import type { TextStyle, ViewStyle, TextInputProps, ColorValue } from 'react-native';
2
+
3
+ // ─── Format Types ────────────────────────────────────────────────────────────
4
+
5
+ /**
6
+ * Supported inline formatting types.
7
+ */
8
+ export type FormatType =
9
+ | 'bold'
10
+ | 'italic'
11
+ | 'underline'
12
+ | 'strikethrough'
13
+ | 'code';
14
+
15
+ /**
16
+ * Heading level presets.
17
+ */
18
+ export type HeadingLevel = 'h1' | 'h2' | 'h3' | 'none';
19
+
20
+ /**
21
+ * List type for a line/paragraph.
22
+ */
23
+ export type ListType = 'bullet' | 'ordered' | 'none';
24
+
25
+ // ─── Style Types ─────────────────────────────────────────────────────────────
26
+
27
+ /**
28
+ * Inline formatting styles attached to a text segment.
29
+ */
30
+ export interface FormatStyle {
31
+ bold?: boolean;
32
+ italic?: boolean;
33
+ underline?: boolean;
34
+ strikethrough?: boolean;
35
+ code?: boolean;
36
+ color?: string;
37
+ backgroundColor?: string;
38
+ fontSize?: number;
39
+ heading?: HeadingLevel;
40
+ }
41
+
42
+ /**
43
+ * A segment of text with uniform formatting.
44
+ * The entire rich text content is an ordered array of these segments.
45
+ */
46
+ export interface StyledSegment {
47
+ /** The text content of this segment. */
48
+ text: string;
49
+ /** The formatting styles applied to this segment. */
50
+ styles: FormatStyle;
51
+ }
52
+
53
+ // ─── Selection ───────────────────────────────────────────────────────────────
54
+
55
+ /**
56
+ * Represents a text selection range within the input.
57
+ */
58
+ export interface SelectionRange {
59
+ /** Start index (inclusive). */
60
+ start: number;
61
+ /** End index (exclusive). */
62
+ end: number;
63
+ }
64
+
65
+ // ─── Rich Text State ─────────────────────────────────────────────────────────
66
+
67
+ /**
68
+ * The complete state of the rich text input.
69
+ */
70
+ export interface RichTextState {
71
+ /** Ordered array of styled text segments. */
72
+ segments: StyledSegment[];
73
+ /** Current selection range. */
74
+ selection: SelectionRange;
75
+ /** The current active styles that will be applied to newly typed text. */
76
+ activeStyles: FormatStyle;
77
+ }
78
+
79
+ // ─── Actions ─────────────────────────────────────────────────────────────────
80
+
81
+ /**
82
+ * Actions returned by the useRichText hook for controlling the editor.
83
+ */
84
+ export interface RichTextActions {
85
+ /** Toggle an inline format on the current selection or active styles. */
86
+ toggleFormat: (format: FormatType) => void;
87
+ /** Set a specific style property on the current selection. */
88
+ setStyleProperty: <K extends keyof FormatStyle>(
89
+ key: K,
90
+ value: FormatStyle[K],
91
+ ) => void;
92
+ /** Apply a heading level to the current line. */
93
+ setHeading: (level: HeadingLevel) => void;
94
+ /** Set the text color for the current selection. */
95
+ setColor: (color: string) => void;
96
+ /** Set the background color for the current selection. */
97
+ setBackgroundColor: (color: string) => void;
98
+ /** Set the font size for the current selection. */
99
+ setFontSize: (size: number) => void;
100
+ /** Handle text change from TextInput. */
101
+ handleTextChange: (text: string) => void;
102
+ /** Handle selection change from TextInput. */
103
+ handleSelectionChange: (selection: SelectionRange) => void;
104
+ /** Get the full plain text content. */
105
+ getPlainText: () => string;
106
+ /** Export the segments as a serializable JSON array. */
107
+ exportJSON: () => StyledSegment[];
108
+ /** Import segments from a JSON array, replacing current content. */
109
+ importJSON: (segments: StyledSegment[]) => void;
110
+ /** Clear all content. */
111
+ clear: () => void;
112
+ }
113
+
114
+ // ─── Hook Return ─────────────────────────────────────────────────────────────
115
+
116
+ /**
117
+ * Return value of the useRichText hook.
118
+ */
119
+ export interface UseRichTextReturn {
120
+ state: RichTextState;
121
+ actions: RichTextActions;
122
+ }
123
+
124
+ // ─── Theme / Customization ───────────────────────────────────────────────────
125
+
126
+ /**
127
+ * Theme configuration for the RichTextInput component.
128
+ */
129
+ export interface RichTextTheme {
130
+ /** Style for the outer container. */
131
+ containerStyle?: ViewStyle;
132
+ /** Style for the TextInput. */
133
+ inputStyle?: TextStyle;
134
+ /** Style for the overlay text container. */
135
+ overlayContainerStyle?: ViewStyle;
136
+ /** Base text style applied to all segments before formatting. */
137
+ baseTextStyle?: TextStyle;
138
+ /** Style for the toolbar container. */
139
+ toolbarStyle?: ViewStyle;
140
+ /** Style for toolbar buttons. */
141
+ toolbarButtonStyle?: ViewStyle;
142
+ /** Style for active toolbar buttons. */
143
+ toolbarButtonActiveStyle?: ViewStyle;
144
+ /** Text style for toolbar button labels. */
145
+ toolbarButtonTextStyle?: TextStyle;
146
+ /** Text style for active toolbar button labels. */
147
+ toolbarButtonActiveTextStyle?: TextStyle;
148
+ /** Style for the code format. */
149
+ codeStyle?: TextStyle;
150
+ /** Colors */
151
+ colors?: {
152
+ /** Primary accent color. */
153
+ primary?: string;
154
+ /** Background color of the editor. */
155
+ background?: string;
156
+ /** Text color. */
157
+ text?: string;
158
+ /** Placeholder text color. */
159
+ placeholder?: string;
160
+ /** Toolbar background. */
161
+ toolbarBackground?: string;
162
+ /** Toolbar border color. */
163
+ toolbarBorder?: string;
164
+ /** Cursor / caret color. */
165
+ cursor?: ColorValue;
166
+ };
167
+ }
168
+
169
+ // ─── Toolbar Types ───────────────────────────────────────────────────────────
170
+
171
+ /**
172
+ * A toolbar item configuration.
173
+ */
174
+ export interface ToolbarItem {
175
+ /** Unique identifier. */
176
+ id: string;
177
+ /** Display label or icon text. */
178
+ label: string;
179
+ /** The format type this button toggles (for inline formats). */
180
+ format?: FormatType;
181
+ /** The heading level this button sets. */
182
+ heading?: HeadingLevel;
183
+ /** Custom action handler (overrides default behavior). */
184
+ onPress?: () => void;
185
+ /** Whether this item is currently active. */
186
+ active?: boolean;
187
+ /** Custom render function for the button. */
188
+ renderButton?: (props: {
189
+ active: boolean;
190
+ onPress: () => void;
191
+ label: string;
192
+ }) => React.ReactElement;
193
+ }
194
+
195
+ // ─── Component Props ─────────────────────────────────────────────────────────
196
+
197
+ /**
198
+ * Props for the OverlayText component.
199
+ */
200
+ export interface OverlayTextProps {
201
+ /** The styled segments to render. */
202
+ segments: StyledSegment[];
203
+ /** Base text style. */
204
+ baseTextStyle?: TextStyle;
205
+ /** Theme overrides. */
206
+ theme?: RichTextTheme;
207
+ }
208
+
209
+ /**
210
+ * Props for the ToolbarButton component.
211
+ */
212
+ export interface ToolbarButtonProps {
213
+ /** Button label text. */
214
+ label: string;
215
+ /** Whether the button is currently active. */
216
+ active: boolean;
217
+ /** Press handler. */
218
+ onPress: () => void;
219
+ /** Theme overrides. */
220
+ theme?: RichTextTheme;
221
+ /** Custom render function. */
222
+ renderButton?: ToolbarItem['renderButton'];
223
+ }
224
+
225
+ /**
226
+ * Props for the Toolbar component.
227
+ */
228
+ export interface ToolbarProps {
229
+ /** The current rich text actions. */
230
+ actions: RichTextActions;
231
+ /** The current rich text state. */
232
+ state: RichTextState;
233
+ /** Custom toolbar items (overrides defaults). */
234
+ items?: ToolbarItem[];
235
+ /** Theme overrides. */
236
+ theme?: RichTextTheme;
237
+ /** Whether to show the toolbar. */
238
+ visible?: boolean;
239
+ /** Custom render function for the entire toolbar. */
240
+ renderToolbar?: (props: {
241
+ items: ToolbarItem[];
242
+ state: RichTextState;
243
+ actions: RichTextActions;
244
+ }) => React.ReactElement;
245
+ }
246
+
247
+ /**
248
+ * Props for the main RichTextInput component.
249
+ */
250
+ export interface RichTextInputProps {
251
+ /** Initial segments to populate the editor with. */
252
+ initialSegments?: StyledSegment[];
253
+ /** Callback when the content changes. */
254
+ onChangeSegments?: (segments: StyledSegment[]) => void;
255
+ /** Callback when the plain text changes. */
256
+ onChangeText?: (text: string) => void;
257
+ /** Placeholder text. */
258
+ placeholder?: string;
259
+ /** Whether the input is editable. */
260
+ editable?: boolean;
261
+ /** Maximum character length. */
262
+ maxLength?: number;
263
+ /** Whether to show the toolbar. */
264
+ showToolbar?: boolean;
265
+ /** Toolbar position relative to the input. */
266
+ toolbarPosition?: 'top' | 'bottom';
267
+ /** Custom toolbar items. */
268
+ toolbarItems?: ToolbarItem[];
269
+ /** Theme configuration. */
270
+ theme?: RichTextTheme;
271
+ /** Whether multiline input is enabled. */
272
+ multiline?: boolean;
273
+ /** Minimum height for the input area. */
274
+ minHeight?: number;
275
+ /** Maximum height for the input area. */
276
+ maxHeight?: number;
277
+ /** Auto-focus the input on mount. */
278
+ autoFocus?: boolean;
279
+ /** Additional TextInput props. */
280
+ textInputProps?: Omit<
281
+ TextInputProps,
282
+ | 'value'
283
+ | 'onChangeText'
284
+ | 'onSelectionChange'
285
+ | 'multiline'
286
+ | 'placeholder'
287
+ | 'editable'
288
+ | 'maxLength'
289
+ | 'autoFocus'
290
+ >;
291
+ /** Custom toolbar render function. */
292
+ renderToolbar?: ToolbarProps['renderToolbar'];
293
+ /** Ref callback to access actions. */
294
+ onReady?: (actions: RichTextActions) => void;
295
+ }
@@ -0,0 +1,28 @@
1
+ import type { StyledSegment, FormatType, FormatStyle, HeadingLevel, SelectionRange } from '@/types';
2
+ /**
3
+ * Toggle an inline format (bold, italic, etc.) on the selected range.
4
+ *
5
+ * If the entire selection already has the format, it is removed.
6
+ * Otherwise, it is applied to the entire selection.
7
+ *
8
+ * Returns the new segments array.
9
+ */
10
+ export declare function toggleFormatOnSelection(segments: StyledSegment[], selection: SelectionRange, format: FormatType): StyledSegment[];
11
+ /**
12
+ * Set a specific style property on the selected range.
13
+ */
14
+ export declare function setStyleOnSelection<K extends keyof FormatStyle>(segments: StyledSegment[], selection: SelectionRange, key: K, value: FormatStyle[K]): StyledSegment[];
15
+ /**
16
+ * Apply a heading level to the line containing the cursor/selection.
17
+ */
18
+ export declare function setHeadingOnLine(segments: StyledSegment[], selection: SelectionRange, level: HeadingLevel): StyledSegment[];
19
+ /**
20
+ * Checks whether the given format is active across the entire selection.
21
+ */
22
+ export declare function isFormatActiveInSelection(segments: StyledSegment[], selection: SelectionRange, format: FormatType): boolean;
23
+ /**
24
+ * Gets the format style that is common across the entire selection.
25
+ * For properties where segments disagree, the value is undefined.
26
+ */
27
+ export declare function getSelectionStyle(segments: StyledSegment[], selection: SelectionRange): FormatStyle;
28
+ export { createSegment } from '@/utils/parser';