react-native-richify 1.0.1 → 1.0.3

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 (159) hide show
  1. package/lib/commonjs/components/OverlayText.d.js +6 -0
  2. package/lib/commonjs/components/OverlayText.d.js.map +1 -0
  3. package/lib/commonjs/components/OverlayText.js +51 -0
  4. package/lib/commonjs/components/OverlayText.js.map +1 -0
  5. package/lib/commonjs/components/RichTextInput.d.js +6 -0
  6. package/lib/commonjs/components/RichTextInput.d.js.map +1 -0
  7. package/lib/commonjs/components/RichTextInput.js +163 -0
  8. package/lib/commonjs/components/RichTextInput.js.map +1 -0
  9. package/lib/commonjs/components/Toolbar.d.js +6 -0
  10. package/lib/commonjs/components/Toolbar.d.js.map +1 -0
  11. package/lib/commonjs/components/Toolbar.js +96 -0
  12. package/lib/commonjs/components/Toolbar.js.map +1 -0
  13. package/lib/commonjs/components/ToolbarButton.d.js +6 -0
  14. package/lib/commonjs/components/ToolbarButton.d.js.map +1 -0
  15. package/lib/commonjs/components/ToolbarButton.js +63 -0
  16. package/lib/commonjs/components/ToolbarButton.js.map +1 -0
  17. package/lib/commonjs/constants/defaultStyles.d.js +6 -0
  18. package/lib/commonjs/constants/defaultStyles.d.js.map +1 -0
  19. package/lib/commonjs/constants/defaultStyles.js +172 -0
  20. package/lib/commonjs/constants/defaultStyles.js.map +1 -0
  21. package/lib/commonjs/context/RichTextContext.d.js +6 -0
  22. package/lib/commonjs/context/RichTextContext.d.js.map +1 -0
  23. package/lib/commonjs/context/RichTextContext.js +61 -0
  24. package/lib/commonjs/context/RichTextContext.js.map +1 -0
  25. package/lib/commonjs/hooks/useFormatting.d.js +6 -0
  26. package/lib/commonjs/hooks/useFormatting.d.js.map +1 -0
  27. package/lib/commonjs/hooks/useFormatting.js +82 -0
  28. package/lib/commonjs/hooks/useFormatting.js.map +1 -0
  29. package/lib/commonjs/hooks/useRichText.d.js +6 -0
  30. package/lib/commonjs/hooks/useRichText.d.js.map +1 -0
  31. package/lib/commonjs/hooks/useRichText.js +142 -0
  32. package/lib/commonjs/hooks/useRichText.js.map +1 -0
  33. package/lib/commonjs/hooks/useSelection.d.js +6 -0
  34. package/lib/commonjs/hooks/useSelection.d.js.map +1 -0
  35. package/lib/commonjs/hooks/useSelection.js +39 -0
  36. package/lib/commonjs/hooks/useSelection.js.map +1 -0
  37. package/lib/commonjs/index.d.js +186 -0
  38. package/lib/commonjs/index.d.js.map +1 -0
  39. package/lib/commonjs/index.js +186 -0
  40. package/lib/commonjs/index.js.map +1 -0
  41. package/lib/commonjs/package.json +1 -0
  42. package/lib/commonjs/types/index.d.js +6 -0
  43. package/lib/commonjs/types/index.d.js.map +1 -0
  44. package/lib/commonjs/types/index.js +6 -0
  45. package/lib/commonjs/types/index.js.map +1 -0
  46. package/lib/commonjs/utils/formatter.d.js +13 -0
  47. package/lib/commonjs/utils/formatter.d.js.map +1 -0
  48. package/lib/commonjs/utils/formatter.js +229 -0
  49. package/lib/commonjs/utils/formatter.js.map +1 -0
  50. package/lib/commonjs/utils/parser.d.js +6 -0
  51. package/lib/commonjs/utils/parser.d.js.map +1 -0
  52. package/lib/commonjs/utils/parser.js +221 -0
  53. package/lib/commonjs/utils/parser.js.map +1 -0
  54. package/lib/commonjs/utils/styleMapper.d.js +6 -0
  55. package/lib/commonjs/utils/styleMapper.d.js.map +1 -0
  56. package/lib/commonjs/utils/styleMapper.js +87 -0
  57. package/lib/commonjs/utils/styleMapper.js.map +1 -0
  58. package/lib/module/components/OverlayText.d.js +4 -0
  59. package/lib/module/components/OverlayText.d.js.map +1 -0
  60. package/lib/module/components/OverlayText.js +47 -0
  61. package/lib/module/components/OverlayText.js.map +1 -0
  62. package/lib/module/components/RichTextInput.d.js +4 -0
  63. package/lib/module/components/RichTextInput.d.js.map +1 -0
  64. package/lib/module/components/RichTextInput.js +158 -0
  65. package/lib/module/components/RichTextInput.js.map +1 -0
  66. package/lib/module/components/Toolbar.d.js +4 -0
  67. package/lib/module/components/Toolbar.d.js.map +1 -0
  68. package/lib/module/components/Toolbar.js +92 -0
  69. package/lib/module/components/Toolbar.js.map +1 -0
  70. package/lib/module/components/ToolbarButton.d.js +4 -0
  71. package/lib/module/components/ToolbarButton.d.js.map +1 -0
  72. package/lib/module/components/ToolbarButton.js +59 -0
  73. package/lib/module/components/ToolbarButton.js.map +1 -0
  74. package/lib/module/constants/defaultStyles.d.js +4 -0
  75. package/lib/module/constants/defaultStyles.d.js.map +1 -0
  76. package/lib/module/constants/defaultStyles.js +168 -0
  77. package/lib/module/constants/defaultStyles.js.map +1 -0
  78. package/lib/module/context/RichTextContext.d.js +4 -0
  79. package/lib/module/context/RichTextContext.d.js.map +1 -0
  80. package/lib/module/context/RichTextContext.js +55 -0
  81. package/lib/module/context/RichTextContext.js.map +1 -0
  82. package/lib/module/hooks/useFormatting.d.js +11 -0
  83. package/lib/module/hooks/useFormatting.d.js.map +1 -0
  84. package/lib/module/hooks/useFormatting.js +78 -0
  85. package/lib/module/hooks/useFormatting.js.map +1 -0
  86. package/lib/module/hooks/useRichText.d.js +4 -0
  87. package/lib/module/hooks/useRichText.d.js.map +1 -0
  88. package/lib/module/hooks/useRichText.js +138 -0
  89. package/lib/module/hooks/useRichText.js.map +1 -0
  90. package/lib/module/hooks/useSelection.d.js +4 -0
  91. package/lib/module/hooks/useSelection.d.js.map +1 -0
  92. package/lib/module/hooks/useSelection.js +35 -0
  93. package/lib/module/hooks/useSelection.js.map +1 -0
  94. package/lib/module/index.d.js +15 -0
  95. package/lib/module/index.d.js.map +1 -0
  96. package/lib/module/index.js +25 -0
  97. package/lib/module/index.js.map +1 -0
  98. package/lib/module/types/index.d.js +4 -0
  99. package/lib/module/types/index.d.js.map +1 -0
  100. package/lib/module/types/index.js +4 -0
  101. package/lib/module/types/index.js.map +1 -0
  102. package/lib/module/utils/formatter.d.js +30 -0
  103. package/lib/module/utils/formatter.d.js.map +1 -0
  104. package/lib/module/utils/formatter.js +217 -0
  105. package/lib/module/utils/formatter.js.map +1 -0
  106. package/lib/module/utils/parser.d.js +4 -0
  107. package/lib/module/utils/parser.d.js.map +1 -0
  108. package/lib/module/utils/parser.js +211 -0
  109. package/lib/module/utils/parser.js.map +1 -0
  110. package/lib/module/utils/styleMapper.d.js +4 -0
  111. package/lib/module/utils/styleMapper.d.js.map +1 -0
  112. package/lib/module/utils/styleMapper.js +82 -0
  113. package/lib/module/utils/styleMapper.js.map +1 -0
  114. package/lib/typescript/src/components/OverlayText.d.ts +11 -0
  115. package/lib/typescript/src/components/OverlayText.d.ts.map +1 -0
  116. package/lib/typescript/src/components/RichTextInput.d.ts +21 -0
  117. package/lib/typescript/src/components/RichTextInput.d.ts.map +1 -0
  118. package/lib/typescript/src/components/Toolbar.d.ts +13 -0
  119. package/lib/typescript/src/components/Toolbar.d.ts.map +1 -0
  120. package/lib/typescript/src/components/ToolbarButton.d.ts +8 -0
  121. package/lib/typescript/src/components/ToolbarButton.d.ts.map +1 -0
  122. package/lib/typescript/src/constants/defaultStyles.d.ts +46 -0
  123. package/lib/typescript/src/constants/defaultStyles.d.ts.map +1 -0
  124. package/lib/typescript/src/context/RichTextContext.d.ts +31 -0
  125. package/lib/typescript/src/context/RichTextContext.d.ts.map +1 -0
  126. package/lib/typescript/src/hooks/useFormatting.d.ts +26 -0
  127. package/lib/typescript/src/hooks/useFormatting.d.ts.map +1 -0
  128. package/lib/typescript/src/hooks/useRichText.d.ts +17 -0
  129. package/lib/typescript/src/hooks/useRichText.d.ts.map +1 -0
  130. package/lib/typescript/src/hooks/useSelection.d.ts +14 -0
  131. package/lib/typescript/src/hooks/useSelection.d.ts.map +1 -0
  132. package/lib/typescript/src/index.d.ts +16 -0
  133. package/lib/typescript/src/index.d.ts.map +1 -0
  134. package/lib/typescript/src/types/index.d.ts +257 -0
  135. package/lib/typescript/src/types/index.d.ts.map +1 -0
  136. package/lib/typescript/src/utils/formatter.d.ts +29 -0
  137. package/lib/typescript/src/utils/formatter.d.ts.map +1 -0
  138. package/lib/typescript/src/utils/parser.d.ts +46 -0
  139. package/lib/typescript/src/utils/parser.d.ts.map +1 -0
  140. package/lib/typescript/src/utils/styleMapper.d.ts +16 -0
  141. package/lib/typescript/src/utils/styleMapper.d.ts.map +1 -0
  142. package/package.json +1 -1
  143. package/src/components/OverlayText.tsx +11 -3
  144. package/src/components/RichTextInput.tsx +11 -5
  145. package/src/components/Toolbar.d.ts +1 -1
  146. package/src/components/Toolbar.tsx +5 -5
  147. package/src/components/ToolbarButton.d.ts +1 -1
  148. package/src/constants/defaultStyles.d.ts +1 -1
  149. package/src/hooks/useRichText.ts +11 -4
  150. package/src/index.d.ts +1 -1
  151. package/src/index.ts +2 -0
  152. package/src/types/index.d.ts +22 -10
  153. package/src/types/index.ts +24 -10
  154. package/src/utils/formatter.d.ts +2 -2
  155. package/src/utils/formatter.ts +4 -4
  156. package/src/utils/parser.d.ts +1 -1
  157. package/src/utils/parser.ts +2 -2
  158. package/src/utils/styleMapper.d.ts +1 -1
  159. package/src/utils/styleMapper.ts +2 -2
@@ -101,6 +101,10 @@ export interface RichTextActions {
101
101
  handleTextChange: (text: string) => void;
102
102
  /** Handle selection change from TextInput. */
103
103
  handleSelectionChange: (selection: SelectionRange) => void;
104
+ /** Check whether a format is active at the current cursor/selection. */
105
+ isFormatActive: (format: FormatType) => boolean;
106
+ /** Get the effective shared style at the current cursor/selection. */
107
+ getSelectionStyle: () => FormatStyle;
104
108
  /** Get the full plain text content. */
105
109
  getPlainText: () => string;
106
110
  /** Export the segments as a serializable JSON array. */
@@ -185,11 +189,25 @@ export interface ToolbarItem {
185
189
  /** Whether this item is currently active. */
186
190
  active?: boolean;
187
191
  /** Custom render function for the button. */
188
- renderButton?: (props: {
189
- active: boolean;
190
- onPress: () => void;
191
- label: string;
192
- }) => React.ReactElement;
192
+ renderButton?: (props: ToolbarButtonRenderProps) => React.ReactElement | null;
193
+ }
194
+
195
+ /**
196
+ * Props passed to a custom toolbar button renderer.
197
+ */
198
+ export interface ToolbarButtonRenderProps {
199
+ active: boolean;
200
+ onPress: () => void;
201
+ label: string;
202
+ }
203
+
204
+ /**
205
+ * Props passed to a custom toolbar renderer.
206
+ */
207
+ export interface ToolbarRenderProps {
208
+ items: ToolbarItem[];
209
+ state: RichTextState;
210
+ actions: RichTextActions;
193
211
  }
194
212
 
195
213
  // ─── Component Props ─────────────────────────────────────────────────────────
@@ -237,11 +255,7 @@ export interface ToolbarProps {
237
255
  /** Whether to show the toolbar. */
238
256
  visible?: boolean;
239
257
  /** Custom render function for the entire toolbar. */
240
- renderToolbar?: (props: {
241
- items: ToolbarItem[];
242
- state: RichTextState;
243
- actions: RichTextActions;
244
- }) => React.ReactElement;
258
+ renderToolbar?: (props: ToolbarRenderProps) => React.ReactElement | null;
245
259
  }
246
260
 
247
261
  /**
@@ -1,4 +1,4 @@
1
- import type { StyledSegment, FormatType, FormatStyle, HeadingLevel, SelectionRange } from '@/types';
1
+ import type { StyledSegment, FormatType, FormatStyle, HeadingLevel, SelectionRange } from '../types';
2
2
  /**
3
3
  * Toggle an inline format (bold, italic, etc.) on the selected range.
4
4
  *
@@ -25,4 +25,4 @@ export declare function isFormatActiveInSelection(segments: StyledSegment[], sel
25
25
  * For properties where segments disagree, the value is undefined.
26
26
  */
27
27
  export declare function getSelectionStyle(segments: StyledSegment[], selection: SelectionRange): FormatStyle;
28
- export { createSegment } from '@/utils/parser';
28
+ export { createSegment } from '../utils/parser';
@@ -4,15 +4,15 @@ import type {
4
4
  FormatStyle,
5
5
  HeadingLevel,
6
6
  SelectionRange,
7
- } from '@/types';
7
+ } from '../types';
8
8
  import {
9
9
  createSegment,
10
10
  findPositionInSegments,
11
11
  splitSegment,
12
12
  mergeAdjacentSegments,
13
13
  segmentsToPlainText,
14
- } from '@/utils/parser';
15
- import { HEADING_FONT_SIZES } from '@/constants/defaultStyles';
14
+ } from '../utils/parser';
15
+ import { HEADING_FONT_SIZES } from '../constants/defaultStyles';
16
16
 
17
17
  /**
18
18
  * Toggle an inline format (bold, italic, etc.) on the selected range.
@@ -273,4 +273,4 @@ function getLineRange(
273
273
  }
274
274
 
275
275
  // Re-export for convenience
276
- export { createSegment } from '@/utils/parser';
276
+ export { createSegment } from '../utils/parser';
@@ -1,4 +1,4 @@
1
- import type { StyledSegment, FormatStyle } from '@/types';
1
+ import type { StyledSegment, FormatStyle } from '../types';
2
2
  /**
3
3
  * Creates a new segment with the given text and optional styles.
4
4
  */
@@ -1,5 +1,5 @@
1
- import type { StyledSegment, FormatStyle } from '@/types';
2
- import { EMPTY_FORMAT_STYLE } from '@/constants/defaultStyles';
1
+ import type { StyledSegment, FormatStyle } from '../types';
2
+ import { EMPTY_FORMAT_STYLE } from '../constants/defaultStyles';
3
3
 
4
4
  /**
5
5
  * Creates a new segment with the given text and optional styles.
@@ -1,5 +1,5 @@
1
1
  import type { TextStyle } from 'react-native';
2
- import type { FormatStyle, RichTextTheme, StyledSegment } from '@/types';
2
+ import type { FormatStyle, RichTextTheme, StyledSegment } from '../types';
3
3
  /**
4
4
  * Maps a FormatStyle to a React Native TextStyle.
5
5
  * Applies formatting properties based on the segment's style.
@@ -1,6 +1,6 @@
1
1
  import type { TextStyle } from 'react-native';
2
- import type { FormatStyle, RichTextTheme, StyledSegment } from '@/types';
3
- import { DEFAULT_THEME, HEADING_FONT_SIZES } from '@/constants/defaultStyles';
2
+ import type { FormatStyle, RichTextTheme, StyledSegment } from '../types';
3
+ import { DEFAULT_THEME, HEADING_FONT_SIZES } from '../constants/defaultStyles';
4
4
 
5
5
  /**
6
6
  * Maps a FormatStyle to a React Native TextStyle.