react-native-richify 1.0.1 → 1.0.2

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 (148) 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 +45 -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 +160 -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 +99 -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 +136 -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 +41 -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 +155 -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 +95 -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 +132 -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 +245 -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/utils/formatter.d.ts +2 -2
  144. package/src/utils/formatter.ts +4 -4
  145. package/src/utils/parser.d.ts +1 -1
  146. package/src/utils/parser.ts +2 -2
  147. package/src/utils/styleMapper.d.ts +1 -1
  148. package/src/utils/styleMapper.ts +2 -2
@@ -0,0 +1,245 @@
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
+ }
245
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAIrF;;GAEG;AACH,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,QAAQ,GACR,WAAW,GACX,eAAe,GACf,MAAM,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAIrD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,MAAM,EAAE,WAAW,CAAC;CACrB;AAID;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,6BAA6B;IAC7B,GAAG,EAAE,MAAM,CAAC;CACb;AAID;;GAE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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';
29
+ //# sourceMappingURL=formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../../../src/utils/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EACV,WAAW,EACX,YAAY,EACZ,cAAc,EACf,MAAM,UAAU,CAAC;AAUlB;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,aAAa,EAAE,EACzB,SAAS,EAAE,cAAc,EACzB,MAAM,EAAE,UAAU,GACjB,aAAa,EAAE,CAgBjB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,WAAW,EAC7D,QAAQ,EAAE,aAAa,EAAE,EACzB,SAAS,EAAE,cAAc,EACzB,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GACpB,aAAa,EAAE,CAOjB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,aAAa,EAAE,EACzB,SAAS,EAAE,cAAc,EACzB,KAAK,EAAE,YAAY,GAClB,aAAa,EAAE,CAWjB;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,aAAa,EAAE,EACzB,SAAS,EAAE,cAAc,EACzB,MAAM,EAAE,UAAU,GACjB,OAAO,CAQT;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,aAAa,EAAE,EACzB,SAAS,EAAE,cAAc,GACxB,WAAW,CAwCb;AAgID,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { StyledSegment, FormatStyle } from '../types';
2
+ /**
3
+ * Creates a new segment with the given text and optional styles.
4
+ */
5
+ export declare function createSegment(text: string, styles?: FormatStyle): StyledSegment;
6
+ /**
7
+ * Computes the total character length across all segments.
8
+ */
9
+ export declare function getTotalLength(segments: StyledSegment[]): number;
10
+ /**
11
+ * Converts an array of segments to plain text.
12
+ */
13
+ export declare function segmentsToPlainText(segments: StyledSegment[]): string;
14
+ /**
15
+ * Finds which segment and character offset a global position corresponds to.
16
+ * Returns { segmentIndex, offsetInSegment }.
17
+ */
18
+ export declare function findPositionInSegments(segments: StyledSegment[], globalPosition: number): {
19
+ segmentIndex: number;
20
+ offsetInSegment: number;
21
+ };
22
+ /**
23
+ * Splits a segment at the given offset, returning [before, after].
24
+ * If offset is 0 or at end, one side will have empty text.
25
+ */
26
+ export declare function splitSegment(segment: StyledSegment, offset: number): [StyledSegment, StyledSegment];
27
+ /**
28
+ * Checks if two FormatStyle objects are deeply equal.
29
+ */
30
+ export declare function areStylesEqual(a: FormatStyle, b: FormatStyle): boolean;
31
+ /**
32
+ * Merges adjacent segments that have identical styles.
33
+ * Returns a new array (does not mutate input).
34
+ */
35
+ export declare function mergeAdjacentSegments(segments: StyledSegment[]): StyledSegment[];
36
+ /**
37
+ * Given the old segments and new plain text (from TextInput onChange),
38
+ * reconcile the segments to preserve formatting while reflecting the text change.
39
+ *
40
+ * Strategy:
41
+ * 1. Find the diff region between old plain text and new plain text
42
+ * 2. Replace that region in the segment array
43
+ * 3. New text inserted at the diff point inherits the `activeStyles`
44
+ */
45
+ export declare function reconcileTextChange(oldSegments: StyledSegment[], newText: string, activeStyles: FormatStyle): StyledSegment[];
46
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../../src/utils/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG3D;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,WAAuC,GAC9C,aAAa,CAEf;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,MAAM,CAEhE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,MAAM,CAErE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,aAAa,EAAE,EACzB,cAAc,EAAE,MAAM,GACrB;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAiBnD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,MAAM,GACb,CAAC,aAAa,EAAE,aAAa,CAAC,CAIhC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAYtE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,aAAa,EAAE,GACxB,aAAa,EAAE,CA8BjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,aAAa,EAAE,EAC5B,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,WAAW,GACxB,aAAa,EAAE,CAqHjB"}
@@ -0,0 +1,16 @@
1
+ import type { TextStyle } from 'react-native';
2
+ import type { FormatStyle, RichTextTheme, StyledSegment } from '../types';
3
+ /**
4
+ * Maps a FormatStyle to a React Native TextStyle.
5
+ * Applies formatting properties based on the segment's style.
6
+ */
7
+ export declare function formatStyleToTextStyle(formatStyle: FormatStyle, theme?: RichTextTheme): TextStyle;
8
+ /**
9
+ * Maps an entire segment to its computed TextStyle (base + format).
10
+ */
11
+ export declare function segmentToTextStyle(segment: StyledSegment, theme?: RichTextTheme): TextStyle;
12
+ /**
13
+ * Batch-maps an array of segments to an array of TextStyles.
14
+ */
15
+ export declare function segmentsToTextStyles(segments: StyledSegment[], theme?: RichTextTheme): TextStyle[];
16
+ //# sourceMappingURL=styleMapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styleMapper.d.ts","sourceRoot":"","sources":["../../../../src/utils/styleMapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG1E;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,WAAW,EACxB,KAAK,CAAC,EAAE,aAAa,GACpB,SAAS,CAsDX;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,aAAa,EACtB,KAAK,CAAC,EAAE,aAAa,GACpB,SAAS,CAQX;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,aAAa,EAAE,EACzB,KAAK,CAAC,EAAE,aAAa,GACpB,SAAS,EAAE,CAEb"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-richify",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A production-grade, fully customizable React Native Rich Text Input using the Overlay Technique — no WebView required.",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
@@ -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.