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.
- package/lib/commonjs/components/OverlayText.d.js +6 -0
- package/lib/commonjs/components/OverlayText.d.js.map +1 -0
- package/lib/commonjs/components/OverlayText.js +51 -0
- package/lib/commonjs/components/OverlayText.js.map +1 -0
- package/lib/commonjs/components/RichTextInput.d.js +6 -0
- package/lib/commonjs/components/RichTextInput.d.js.map +1 -0
- package/lib/commonjs/components/RichTextInput.js +163 -0
- package/lib/commonjs/components/RichTextInput.js.map +1 -0
- package/lib/commonjs/components/Toolbar.d.js +6 -0
- package/lib/commonjs/components/Toolbar.d.js.map +1 -0
- package/lib/commonjs/components/Toolbar.js +96 -0
- package/lib/commonjs/components/Toolbar.js.map +1 -0
- package/lib/commonjs/components/ToolbarButton.d.js +6 -0
- package/lib/commonjs/components/ToolbarButton.d.js.map +1 -0
- package/lib/commonjs/components/ToolbarButton.js +63 -0
- package/lib/commonjs/components/ToolbarButton.js.map +1 -0
- package/lib/commonjs/constants/defaultStyles.d.js +6 -0
- package/lib/commonjs/constants/defaultStyles.d.js.map +1 -0
- package/lib/commonjs/constants/defaultStyles.js +172 -0
- package/lib/commonjs/constants/defaultStyles.js.map +1 -0
- package/lib/commonjs/context/RichTextContext.d.js +6 -0
- package/lib/commonjs/context/RichTextContext.d.js.map +1 -0
- package/lib/commonjs/context/RichTextContext.js +61 -0
- package/lib/commonjs/context/RichTextContext.js.map +1 -0
- package/lib/commonjs/hooks/useFormatting.d.js +6 -0
- package/lib/commonjs/hooks/useFormatting.d.js.map +1 -0
- package/lib/commonjs/hooks/useFormatting.js +82 -0
- package/lib/commonjs/hooks/useFormatting.js.map +1 -0
- package/lib/commonjs/hooks/useRichText.d.js +6 -0
- package/lib/commonjs/hooks/useRichText.d.js.map +1 -0
- package/lib/commonjs/hooks/useRichText.js +142 -0
- package/lib/commonjs/hooks/useRichText.js.map +1 -0
- package/lib/commonjs/hooks/useSelection.d.js +6 -0
- package/lib/commonjs/hooks/useSelection.d.js.map +1 -0
- package/lib/commonjs/hooks/useSelection.js +39 -0
- package/lib/commonjs/hooks/useSelection.js.map +1 -0
- package/lib/commonjs/index.d.js +186 -0
- package/lib/commonjs/index.d.js.map +1 -0
- package/lib/commonjs/index.js +186 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types/index.d.js +6 -0
- package/lib/commonjs/types/index.d.js.map +1 -0
- package/lib/commonjs/types/index.js +6 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/utils/formatter.d.js +13 -0
- package/lib/commonjs/utils/formatter.d.js.map +1 -0
- package/lib/commonjs/utils/formatter.js +229 -0
- package/lib/commonjs/utils/formatter.js.map +1 -0
- package/lib/commonjs/utils/parser.d.js +6 -0
- package/lib/commonjs/utils/parser.d.js.map +1 -0
- package/lib/commonjs/utils/parser.js +221 -0
- package/lib/commonjs/utils/parser.js.map +1 -0
- package/lib/commonjs/utils/styleMapper.d.js +6 -0
- package/lib/commonjs/utils/styleMapper.d.js.map +1 -0
- package/lib/commonjs/utils/styleMapper.js +87 -0
- package/lib/commonjs/utils/styleMapper.js.map +1 -0
- package/lib/module/components/OverlayText.d.js +4 -0
- package/lib/module/components/OverlayText.d.js.map +1 -0
- package/lib/module/components/OverlayText.js +47 -0
- package/lib/module/components/OverlayText.js.map +1 -0
- package/lib/module/components/RichTextInput.d.js +4 -0
- package/lib/module/components/RichTextInput.d.js.map +1 -0
- package/lib/module/components/RichTextInput.js +158 -0
- package/lib/module/components/RichTextInput.js.map +1 -0
- package/lib/module/components/Toolbar.d.js +4 -0
- package/lib/module/components/Toolbar.d.js.map +1 -0
- package/lib/module/components/Toolbar.js +92 -0
- package/lib/module/components/Toolbar.js.map +1 -0
- package/lib/module/components/ToolbarButton.d.js +4 -0
- package/lib/module/components/ToolbarButton.d.js.map +1 -0
- package/lib/module/components/ToolbarButton.js +59 -0
- package/lib/module/components/ToolbarButton.js.map +1 -0
- package/lib/module/constants/defaultStyles.d.js +4 -0
- package/lib/module/constants/defaultStyles.d.js.map +1 -0
- package/lib/module/constants/defaultStyles.js +168 -0
- package/lib/module/constants/defaultStyles.js.map +1 -0
- package/lib/module/context/RichTextContext.d.js +4 -0
- package/lib/module/context/RichTextContext.d.js.map +1 -0
- package/lib/module/context/RichTextContext.js +55 -0
- package/lib/module/context/RichTextContext.js.map +1 -0
- package/lib/module/hooks/useFormatting.d.js +11 -0
- package/lib/module/hooks/useFormatting.d.js.map +1 -0
- package/lib/module/hooks/useFormatting.js +78 -0
- package/lib/module/hooks/useFormatting.js.map +1 -0
- package/lib/module/hooks/useRichText.d.js +4 -0
- package/lib/module/hooks/useRichText.d.js.map +1 -0
- package/lib/module/hooks/useRichText.js +138 -0
- package/lib/module/hooks/useRichText.js.map +1 -0
- package/lib/module/hooks/useSelection.d.js +4 -0
- package/lib/module/hooks/useSelection.d.js.map +1 -0
- package/lib/module/hooks/useSelection.js +35 -0
- package/lib/module/hooks/useSelection.js.map +1 -0
- package/lib/module/index.d.js +15 -0
- package/lib/module/index.d.js.map +1 -0
- package/lib/module/index.js +25 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/types/index.d.js +4 -0
- package/lib/module/types/index.d.js.map +1 -0
- package/lib/module/types/index.js +4 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/utils/formatter.d.js +30 -0
- package/lib/module/utils/formatter.d.js.map +1 -0
- package/lib/module/utils/formatter.js +217 -0
- package/lib/module/utils/formatter.js.map +1 -0
- package/lib/module/utils/parser.d.js +4 -0
- package/lib/module/utils/parser.d.js.map +1 -0
- package/lib/module/utils/parser.js +211 -0
- package/lib/module/utils/parser.js.map +1 -0
- package/lib/module/utils/styleMapper.d.js +4 -0
- package/lib/module/utils/styleMapper.d.js.map +1 -0
- package/lib/module/utils/styleMapper.js +82 -0
- package/lib/module/utils/styleMapper.js.map +1 -0
- package/lib/typescript/src/components/OverlayText.d.ts +11 -0
- package/lib/typescript/src/components/OverlayText.d.ts.map +1 -0
- package/lib/typescript/src/components/RichTextInput.d.ts +21 -0
- package/lib/typescript/src/components/RichTextInput.d.ts.map +1 -0
- package/lib/typescript/src/components/Toolbar.d.ts +13 -0
- package/lib/typescript/src/components/Toolbar.d.ts.map +1 -0
- package/lib/typescript/src/components/ToolbarButton.d.ts +8 -0
- package/lib/typescript/src/components/ToolbarButton.d.ts.map +1 -0
- package/lib/typescript/src/constants/defaultStyles.d.ts +46 -0
- package/lib/typescript/src/constants/defaultStyles.d.ts.map +1 -0
- package/lib/typescript/src/context/RichTextContext.d.ts +31 -0
- package/lib/typescript/src/context/RichTextContext.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useFormatting.d.ts +26 -0
- package/lib/typescript/src/hooks/useFormatting.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRichText.d.ts +17 -0
- package/lib/typescript/src/hooks/useRichText.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useSelection.d.ts +14 -0
- package/lib/typescript/src/hooks/useSelection.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +16 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +257 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/formatter.d.ts +29 -0
- package/lib/typescript/src/utils/formatter.d.ts.map +1 -0
- package/lib/typescript/src/utils/parser.d.ts +46 -0
- package/lib/typescript/src/utils/parser.d.ts.map +1 -0
- package/lib/typescript/src/utils/styleMapper.d.ts +16 -0
- package/lib/typescript/src/utils/styleMapper.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/OverlayText.tsx +11 -3
- package/src/components/RichTextInput.tsx +11 -5
- package/src/components/Toolbar.d.ts +1 -1
- package/src/components/Toolbar.tsx +5 -5
- package/src/components/ToolbarButton.d.ts +1 -1
- package/src/constants/defaultStyles.d.ts +1 -1
- package/src/hooks/useRichText.ts +11 -4
- package/src/index.d.ts +1 -1
- package/src/index.ts +2 -0
- package/src/types/index.d.ts +22 -10
- package/src/types/index.ts +24 -10
- package/src/utils/formatter.d.ts +2 -2
- package/src/utils/formatter.ts +4 -4
- package/src/utils/parser.d.ts +1 -1
- package/src/utils/parser.ts +2 -2
- package/src/utils/styleMapper.d.ts +1 -1
- package/src/utils/styleMapper.ts +2 -2
package/src/types/index.ts
CHANGED
|
@@ -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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
/**
|
package/src/utils/formatter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StyledSegment, FormatType, FormatStyle, HeadingLevel, SelectionRange } from '
|
|
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 '
|
|
28
|
+
export { createSegment } from '../utils/parser';
|
package/src/utils/formatter.ts
CHANGED
|
@@ -4,15 +4,15 @@ import type {
|
|
|
4
4
|
FormatStyle,
|
|
5
5
|
HeadingLevel,
|
|
6
6
|
SelectionRange,
|
|
7
|
-
} from '
|
|
7
|
+
} from '../types';
|
|
8
8
|
import {
|
|
9
9
|
createSegment,
|
|
10
10
|
findPositionInSegments,
|
|
11
11
|
splitSegment,
|
|
12
12
|
mergeAdjacentSegments,
|
|
13
13
|
segmentsToPlainText,
|
|
14
|
-
} from '
|
|
15
|
-
import { HEADING_FONT_SIZES } from '
|
|
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 '
|
|
276
|
+
export { createSegment } from '../utils/parser';
|
package/src/utils/parser.d.ts
CHANGED
package/src/utils/parser.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { StyledSegment, FormatStyle } from '
|
|
2
|
-
import { EMPTY_FORMAT_STYLE } from '
|
|
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 '
|
|
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.
|
package/src/utils/styleMapper.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TextStyle } from 'react-native';
|
|
2
|
-
import type { FormatStyle, RichTextTheme, StyledSegment } from '
|
|
3
|
-
import { DEFAULT_THEME, HEADING_FONT_SIZES } from '
|
|
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.
|