react-native-richify 1.0.3 → 1.0.5
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/RenderedOutput.js +168 -0
- package/lib/commonjs/components/RenderedOutput.js.map +1 -0
- package/lib/commonjs/components/RichTextInput.js +196 -52
- package/lib/commonjs/components/RichTextInput.js.map +1 -1
- package/lib/commonjs/components/Toolbar.js +41 -2
- package/lib/commonjs/components/Toolbar.js.map +1 -1
- package/lib/commonjs/constants/defaultStyles.js +81 -2
- package/lib/commonjs/constants/defaultStyles.js.map +1 -1
- package/lib/commonjs/hooks/useFormatting.js +46 -2
- package/lib/commonjs/hooks/useFormatting.js.map +1 -1
- package/lib/commonjs/hooks/useRichText.js +130 -12
- package/lib/commonjs/hooks/useRichText.js.map +1 -1
- package/lib/commonjs/index.d.js +19 -0
- package/lib/commonjs/index.d.js.map +1 -1
- package/lib/commonjs/index.js +19 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/formatter.js +48 -12
- package/lib/commonjs/utils/formatter.js.map +1 -1
- package/lib/commonjs/utils/parser.js +1 -1
- package/lib/commonjs/utils/parser.js.map +1 -1
- package/lib/commonjs/utils/serializer.d.js +6 -0
- package/lib/commonjs/utils/serializer.d.js.map +1 -0
- package/lib/commonjs/utils/serializer.js +259 -0
- package/lib/commonjs/utils/serializer.js.map +1 -0
- package/lib/commonjs/utils/styleMapper.js +11 -0
- package/lib/commonjs/utils/styleMapper.js.map +1 -1
- package/lib/module/components/RenderedOutput.js +163 -0
- package/lib/module/components/RenderedOutput.js.map +1 -0
- package/lib/module/components/RichTextInput.js +198 -55
- package/lib/module/components/RichTextInput.js.map +1 -1
- package/lib/module/components/Toolbar.js +41 -2
- package/lib/module/components/Toolbar.js.map +1 -1
- package/lib/module/constants/defaultStyles.js +81 -2
- package/lib/module/constants/defaultStyles.js.map +1 -1
- package/lib/module/hooks/useFormatting.js +47 -3
- package/lib/module/hooks/useFormatting.js.map +1 -1
- package/lib/module/hooks/useRichText.js +130 -12
- package/lib/module/hooks/useRichText.js.map +1 -1
- package/lib/module/index.d.js +1 -0
- package/lib/module/index.d.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/formatter.js +46 -12
- package/lib/module/utils/formatter.js.map +1 -1
- package/lib/module/utils/parser.js +1 -1
- package/lib/module/utils/parser.js.map +1 -1
- package/lib/module/utils/serializer.d.js +4 -0
- package/lib/module/utils/serializer.d.js.map +1 -0
- package/lib/module/utils/serializer.js +253 -0
- package/lib/module/utils/serializer.js.map +1 -0
- package/lib/module/utils/styleMapper.js +11 -0
- package/lib/module/utils/styleMapper.js.map +1 -1
- package/lib/typescript/src/components/RenderedOutput.d.ts +9 -0
- package/lib/typescript/src/components/RenderedOutput.d.ts.map +1 -0
- package/lib/typescript/src/components/RichTextInput.d.ts +2 -13
- package/lib/typescript/src/components/RichTextInput.d.ts.map +1 -1
- package/lib/typescript/src/components/Toolbar.d.ts.map +1 -1
- package/lib/typescript/src/constants/defaultStyles.d.ts +3 -0
- package/lib/typescript/src/constants/defaultStyles.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useFormatting.d.ts +4 -1
- package/lib/typescript/src/hooks/useFormatting.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRichText.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +112 -1
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/formatter.d.ts +9 -1
- package/lib/typescript/src/utils/formatter.d.ts.map +1 -1
- package/lib/typescript/src/utils/parser.d.ts.map +1 -1
- package/lib/typescript/src/utils/serializer.d.ts +14 -0
- package/lib/typescript/src/utils/serializer.d.ts.map +1 -0
- package/lib/typescript/src/utils/styleMapper.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/RenderedOutput.tsx +231 -0
- package/src/components/RichTextInput.d.ts +3 -14
- package/src/components/RichTextInput.tsx +291 -56
- package/src/components/Toolbar.tsx +54 -2
- package/src/constants/defaultStyles.d.ts +3 -0
- package/src/constants/defaultStyles.ts +47 -1
- package/src/hooks/useFormatting.ts +89 -2
- package/src/hooks/useRichText.ts +193 -11
- package/src/index.d.ts +2 -1
- package/src/index.ts +10 -0
- package/src/types/index.d.ts +112 -1
- package/src/types/index.ts +123 -1
- package/src/utils/formatter.ts +60 -10
- package/src/utils/parser.ts +6 -1
- package/src/utils/serializer.d.ts +13 -0
- package/src/utils/serializer.ts +365 -0
- package/src/utils/styleMapper.ts +21 -0
|
@@ -11,6 +11,18 @@ export type HeadingLevel = 'h1' | 'h2' | 'h3' | 'none';
|
|
|
11
11
|
* List type for a line/paragraph.
|
|
12
12
|
*/
|
|
13
13
|
export type ListType = 'bullet' | 'ordered' | 'none';
|
|
14
|
+
/**
|
|
15
|
+
* Paragraph alignment presets.
|
|
16
|
+
*/
|
|
17
|
+
export type TextAlign = 'left' | 'center' | 'right';
|
|
18
|
+
/**
|
|
19
|
+
* Serialized output formats supported by the editor.
|
|
20
|
+
*/
|
|
21
|
+
export type OutputFormat = 'markdown' | 'html';
|
|
22
|
+
/**
|
|
23
|
+
* Output preview modes supported by the editor.
|
|
24
|
+
*/
|
|
25
|
+
export type OutputPreviewMode = 'literal' | 'rendered';
|
|
14
26
|
/**
|
|
15
27
|
* Inline formatting styles attached to a text segment.
|
|
16
28
|
*/
|
|
@@ -24,6 +36,11 @@ export interface FormatStyle {
|
|
|
24
36
|
backgroundColor?: string;
|
|
25
37
|
fontSize?: number;
|
|
26
38
|
heading?: HeadingLevel;
|
|
39
|
+
listType?: ListType;
|
|
40
|
+
textAlign?: TextAlign;
|
|
41
|
+
link?: string;
|
|
42
|
+
imageSrc?: string;
|
|
43
|
+
imageAlt?: string;
|
|
27
44
|
}
|
|
28
45
|
/**
|
|
29
46
|
* A segment of text with uniform formatting.
|
|
@@ -65,6 +82,17 @@ export interface RichTextActions {
|
|
|
65
82
|
setStyleProperty: <K extends keyof FormatStyle>(key: K, value: FormatStyle[K]) => void;
|
|
66
83
|
/** Apply a heading level to the current line. */
|
|
67
84
|
setHeading: (level: HeadingLevel) => void;
|
|
85
|
+
/** Apply a list style to the current line. */
|
|
86
|
+
setListType: (type: ListType) => void;
|
|
87
|
+
/** Apply paragraph alignment to the current line. */
|
|
88
|
+
setTextAlign: (align: TextAlign) => void;
|
|
89
|
+
/** Apply or clear a hyperlink on the current selection. */
|
|
90
|
+
setLink: (url?: string) => void;
|
|
91
|
+
/** Insert an image placeholder into the document. */
|
|
92
|
+
insertImage: (source: string, options?: {
|
|
93
|
+
alt?: string;
|
|
94
|
+
placeholder?: string;
|
|
95
|
+
}) => void;
|
|
68
96
|
/** Set the text color for the current selection. */
|
|
69
97
|
setColor: (color: string) => void;
|
|
70
98
|
/** Set the background color for the current selection. */
|
|
@@ -79,6 +107,8 @@ export interface RichTextActions {
|
|
|
79
107
|
isFormatActive: (format: FormatType) => boolean;
|
|
80
108
|
/** Get the effective shared style at the current cursor/selection. */
|
|
81
109
|
getSelectionStyle: () => FormatStyle;
|
|
110
|
+
/** Serialize the current content as markdown or HTML. */
|
|
111
|
+
getOutput: (format?: OutputFormat) => string;
|
|
82
112
|
/** Get the full plain text content. */
|
|
83
113
|
getPlainText: () => string;
|
|
84
114
|
/** Export the segments as a serializable JSON array. */
|
|
@@ -103,10 +133,18 @@ export interface RichTextTheme {
|
|
|
103
133
|
containerStyle?: ViewStyle;
|
|
104
134
|
/** Style for the TextInput. */
|
|
105
135
|
inputStyle?: TextStyle;
|
|
106
|
-
/** Style for the overlay text container. */
|
|
136
|
+
/** Style for the legacy overlay text container. */
|
|
107
137
|
overlayContainerStyle?: ViewStyle;
|
|
108
138
|
/** Base text style applied to all segments before formatting. */
|
|
109
139
|
baseTextStyle?: TextStyle;
|
|
140
|
+
/** Style for the serialized output container. */
|
|
141
|
+
outputContainerStyle?: ViewStyle;
|
|
142
|
+
/** Label style for the serialized output header. */
|
|
143
|
+
outputLabelStyle?: TextStyle;
|
|
144
|
+
/** Style for the serialized output text. */
|
|
145
|
+
outputTextStyle?: TextStyle;
|
|
146
|
+
/** Style for the rendered output preview content. */
|
|
147
|
+
renderedOutputStyle?: ViewStyle;
|
|
110
148
|
/** Style for the toolbar container. */
|
|
111
149
|
toolbarStyle?: ViewStyle;
|
|
112
150
|
/** Style for toolbar buttons. */
|
|
@@ -133,6 +171,8 @@ export interface RichTextTheme {
|
|
|
133
171
|
toolbarBackground?: string;
|
|
134
172
|
/** Toolbar border color. */
|
|
135
173
|
toolbarBorder?: string;
|
|
174
|
+
/** Default link color. */
|
|
175
|
+
link?: string;
|
|
136
176
|
/** Cursor / caret color. */
|
|
137
177
|
cursor?: ColorValue;
|
|
138
178
|
};
|
|
@@ -149,6 +189,16 @@ export interface ToolbarItem {
|
|
|
149
189
|
format?: FormatType;
|
|
150
190
|
/** The heading level this button sets. */
|
|
151
191
|
heading?: HeadingLevel;
|
|
192
|
+
/** The list type this button sets. */
|
|
193
|
+
listType?: ListType;
|
|
194
|
+
/** The alignment this button sets. */
|
|
195
|
+
textAlign?: TextAlign;
|
|
196
|
+
/** The output format this button toggles to. */
|
|
197
|
+
outputFormat?: OutputFormat;
|
|
198
|
+
/** The output preview mode this button toggles to. */
|
|
199
|
+
outputPreviewMode?: OutputPreviewMode;
|
|
200
|
+
/** Special toolbar action. */
|
|
201
|
+
actionType?: 'link' | 'image';
|
|
152
202
|
/** Custom action handler (overrides default behavior). */
|
|
153
203
|
onPress?: () => void;
|
|
154
204
|
/** Whether this item is currently active. */
|
|
@@ -171,6 +221,33 @@ export interface ToolbarRenderProps {
|
|
|
171
221
|
items: ToolbarItem[];
|
|
172
222
|
state: RichTextState;
|
|
173
223
|
actions: RichTextActions;
|
|
224
|
+
outputFormat: OutputFormat;
|
|
225
|
+
outputPreviewMode: OutputPreviewMode;
|
|
226
|
+
onOutputFormatChange: (format: OutputFormat) => void;
|
|
227
|
+
onOutputPreviewModeChange: (mode: OutputPreviewMode) => void;
|
|
228
|
+
onRequestLink?: () => void;
|
|
229
|
+
onRequestImage?: () => void;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Payload passed when the built-in link button requests a URL.
|
|
233
|
+
*/
|
|
234
|
+
export interface LinkRequestPayload {
|
|
235
|
+
/** Selected plain text at the time of the request. */
|
|
236
|
+
selectedText: string;
|
|
237
|
+
/** Existing URL on the selection, when present. */
|
|
238
|
+
currentUrl?: string;
|
|
239
|
+
/** Apply or clear the URL on the current selection. */
|
|
240
|
+
applyLink: (url?: string) => void;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Payload passed when the built-in image button requests an image source.
|
|
244
|
+
*/
|
|
245
|
+
export interface ImageRequestPayload {
|
|
246
|
+
/** Insert an image placeholder into the document. */
|
|
247
|
+
insertImage: (source: string, options?: {
|
|
248
|
+
alt?: string;
|
|
249
|
+
placeholder?: string;
|
|
250
|
+
}) => void;
|
|
174
251
|
}
|
|
175
252
|
/**
|
|
176
253
|
* Props for the OverlayText component.
|
|
@@ -212,6 +289,18 @@ export interface ToolbarProps {
|
|
|
212
289
|
theme?: RichTextTheme;
|
|
213
290
|
/** Whether to show the toolbar. */
|
|
214
291
|
visible?: boolean;
|
|
292
|
+
/** Currently selected serialized output format. */
|
|
293
|
+
outputFormat?: OutputFormat;
|
|
294
|
+
/** Currently selected preview mode. */
|
|
295
|
+
outputPreviewMode?: OutputPreviewMode;
|
|
296
|
+
/** Called when the output format changes from the toolbar. */
|
|
297
|
+
onOutputFormatChange?: (format: OutputFormat) => void;
|
|
298
|
+
/** Called when the preview mode changes from the toolbar. */
|
|
299
|
+
onOutputPreviewModeChange?: (mode: OutputPreviewMode) => void;
|
|
300
|
+
/** Called when the link button is pressed. */
|
|
301
|
+
onRequestLink?: () => void;
|
|
302
|
+
/** Called when the image button is pressed. */
|
|
303
|
+
onRequestImage?: () => void;
|
|
215
304
|
/** Custom render function for the entire toolbar. */
|
|
216
305
|
renderToolbar?: (props: ToolbarRenderProps) => React.ReactElement | null;
|
|
217
306
|
}
|
|
@@ -239,6 +328,28 @@ export interface RichTextInputProps {
|
|
|
239
328
|
toolbarItems?: ToolbarItem[];
|
|
240
329
|
/** Theme configuration. */
|
|
241
330
|
theme?: RichTextTheme;
|
|
331
|
+
/** Whether to show the serialized output preview below the input. */
|
|
332
|
+
showOutputPreview?: boolean;
|
|
333
|
+
/** Controlled format used for the serialized output preview. */
|
|
334
|
+
outputFormat?: OutputFormat;
|
|
335
|
+
/** Initial format used for the serialized output preview. */
|
|
336
|
+
defaultOutputFormat?: OutputFormat;
|
|
337
|
+
/** Controlled preview mode for the output panel. */
|
|
338
|
+
outputPreviewMode?: OutputPreviewMode;
|
|
339
|
+
/** Initial preview mode for the output panel. */
|
|
340
|
+
defaultOutputPreviewMode?: OutputPreviewMode;
|
|
341
|
+
/** Maximum height for the output preview panel. */
|
|
342
|
+
maxOutputHeight?: number;
|
|
343
|
+
/** Callback when the serialized output changes. */
|
|
344
|
+
onChangeOutput?: (output: string, format: OutputFormat) => void;
|
|
345
|
+
/** Callback when the output format changes. */
|
|
346
|
+
onChangeOutputFormat?: (format: OutputFormat) => void;
|
|
347
|
+
/** Callback when the output preview mode changes. */
|
|
348
|
+
onChangeOutputPreviewMode?: (mode: OutputPreviewMode) => void;
|
|
349
|
+
/** Invoked when the built-in link button needs a URL. */
|
|
350
|
+
onRequestLink?: (payload: LinkRequestPayload) => void;
|
|
351
|
+
/** Invoked when the built-in image button needs an image source. */
|
|
352
|
+
onRequestImage?: (payload: ImageRequestPayload) => void;
|
|
242
353
|
/** Whether multiline input is enabled. */
|
|
243
354
|
multiline?: boolean;
|
|
244
355
|
/** Minimum height for the input area. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EA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1,4 +1,4 @@
|
|
|
1
|
-
import type { StyledSegment, FormatType, FormatStyle, HeadingLevel, SelectionRange } from '../types';
|
|
1
|
+
import type { StyledSegment, FormatType, FormatStyle, HeadingLevel, ListType, SelectionRange, TextAlign } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Toggle an inline format (bold, italic, etc.) on the selected range.
|
|
4
4
|
*
|
|
@@ -16,6 +16,14 @@ export declare function setStyleOnSelection<K extends keyof FormatStyle>(segment
|
|
|
16
16
|
* Apply a heading level to the line containing the cursor/selection.
|
|
17
17
|
*/
|
|
18
18
|
export declare function setHeadingOnLine(segments: StyledSegment[], selection: SelectionRange, level: HeadingLevel): StyledSegment[];
|
|
19
|
+
/**
|
|
20
|
+
* Apply a list type to the lines containing the cursor/selection.
|
|
21
|
+
*/
|
|
22
|
+
export declare function setListTypeOnLine(segments: StyledSegment[], selection: SelectionRange, listType: ListType): StyledSegment[];
|
|
23
|
+
/**
|
|
24
|
+
* Apply text alignment to the lines containing the cursor/selection.
|
|
25
|
+
*/
|
|
26
|
+
export declare function setTextAlignOnLine(segments: StyledSegment[], selection: SelectionRange, textAlign: TextAlign): StyledSegment[];
|
|
19
27
|
/**
|
|
20
28
|
* Checks whether the given format is active across the entire selection.
|
|
21
29
|
*/
|
|
@@ -1 +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,
|
|
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,QAAQ,EACR,cAAc,EACd,SAAS,EACV,MAAM,UAAU,CAAC;AAQlB;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,a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,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,CAiBtE;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,14 @@
|
|
|
1
|
+
import type { OutputFormat, StyledSegment } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Serialize styled segments as Markdown or HTML.
|
|
4
|
+
*/
|
|
5
|
+
export declare function serializeSegments(segments: StyledSegment[], format?: OutputFormat): string;
|
|
6
|
+
/**
|
|
7
|
+
* Convenience wrapper for Markdown output.
|
|
8
|
+
*/
|
|
9
|
+
export declare function segmentsToMarkdown(segments: StyledSegment[]): string;
|
|
10
|
+
/**
|
|
11
|
+
* Convenience wrapper for HTML output.
|
|
12
|
+
*/
|
|
13
|
+
export declare function segmentsToHTML(segments: StyledSegment[]): string;
|
|
14
|
+
//# sourceMappingURL=serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../../../../src/utils/serializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,YAAY,EACZ,aAAa,EAEd,MAAM,UAAU,CAAC;AAIlB;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,aAAa,EAAE,EACzB,MAAM,GAAE,YAAyB,GAChC,MAAM,CAyBR;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,MAAM,CAEpE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,MAAM,CAEhE"}
|
|
@@ -1 +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,
|
|
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,CA2EX;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.
|
|
3
|
+
"version": "1.0.5",
|
|
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",
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { Image, StyleSheet, Text, View } from 'react-native';
|
|
3
|
+
import type { FormatStyle, RichTextTheme, StyledSegment } from '../types';
|
|
4
|
+
import { DEFAULT_THEME } from '../constants/defaultStyles';
|
|
5
|
+
import { segmentToTextStyle } from '../utils/styleMapper';
|
|
6
|
+
|
|
7
|
+
interface RenderedOutputProps {
|
|
8
|
+
segments: StyledSegment[];
|
|
9
|
+
theme?: RichTextTheme;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type LineFragment = Pick<StyledSegment, 'text' | 'styles'>;
|
|
13
|
+
|
|
14
|
+
export const RenderedOutput: React.FC<RenderedOutputProps> = React.memo(
|
|
15
|
+
({ segments, theme }) => {
|
|
16
|
+
const resolvedTheme = theme ?? DEFAULT_THEME;
|
|
17
|
+
const lines = useMemo(() => splitSegmentsByLine(segments), [segments]);
|
|
18
|
+
let orderedIndex = 0;
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<View
|
|
22
|
+
style={[
|
|
23
|
+
styles.container,
|
|
24
|
+
resolvedTheme.renderedOutputStyle ?? DEFAULT_THEME.renderedOutputStyle,
|
|
25
|
+
]}
|
|
26
|
+
>
|
|
27
|
+
{lines.map((line, lineIndex) => {
|
|
28
|
+
const listType = getLineStyle(line, 'listType');
|
|
29
|
+
const textAlign = getLineStyle(line, 'textAlign');
|
|
30
|
+
const marker =
|
|
31
|
+
listType === 'bullet'
|
|
32
|
+
? '\u2022'
|
|
33
|
+
: listType === 'ordered'
|
|
34
|
+
? `${orderedIndex + 1}.`
|
|
35
|
+
: undefined;
|
|
36
|
+
|
|
37
|
+
orderedIndex = listType === 'ordered' ? orderedIndex + 1 : 0;
|
|
38
|
+
|
|
39
|
+
const textFragments = line.filter(
|
|
40
|
+
(fragment) => !fragment.styles.imageSrc && fragment.text.length > 0,
|
|
41
|
+
);
|
|
42
|
+
const imageFragments = line.filter((fragment) => !!fragment.styles.imageSrc);
|
|
43
|
+
const contentAlignStyle =
|
|
44
|
+
textAlign === 'center'
|
|
45
|
+
? styles.alignCenter
|
|
46
|
+
: textAlign === 'right'
|
|
47
|
+
? styles.alignRight
|
|
48
|
+
: styles.alignLeft;
|
|
49
|
+
|
|
50
|
+
if (textFragments.length === 0 && imageFragments.length === 0) {
|
|
51
|
+
return (
|
|
52
|
+
<View
|
|
53
|
+
key={`line-${lineIndex}`}
|
|
54
|
+
style={[styles.emptyLine, contentAlignStyle]}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const textNode =
|
|
60
|
+
textFragments.length > 0 ? (
|
|
61
|
+
<Text
|
|
62
|
+
style={[
|
|
63
|
+
resolvedTheme.baseTextStyle ?? DEFAULT_THEME.baseTextStyle,
|
|
64
|
+
textAlign ? { textAlign } : undefined,
|
|
65
|
+
]}
|
|
66
|
+
>
|
|
67
|
+
{textFragments.map((fragment, fragmentIndex) => (
|
|
68
|
+
<Text
|
|
69
|
+
key={`text-${lineIndex}-${fragmentIndex}`}
|
|
70
|
+
style={segmentToTextStyle(fragment as StyledSegment, resolvedTheme)}
|
|
71
|
+
>
|
|
72
|
+
{fragment.text}
|
|
73
|
+
</Text>
|
|
74
|
+
))}
|
|
75
|
+
</Text>
|
|
76
|
+
) : null;
|
|
77
|
+
|
|
78
|
+
const imageNodes = imageFragments.map((fragment, fragmentIndex) => (
|
|
79
|
+
<View key={`image-${lineIndex}-${fragmentIndex}`} style={styles.imageBlock}>
|
|
80
|
+
<Image
|
|
81
|
+
source={{ uri: fragment.styles.imageSrc }}
|
|
82
|
+
style={styles.image}
|
|
83
|
+
resizeMode="contain"
|
|
84
|
+
/>
|
|
85
|
+
<Text
|
|
86
|
+
style={[
|
|
87
|
+
styles.imageCaption,
|
|
88
|
+
resolvedTheme.baseTextStyle ?? DEFAULT_THEME.baseTextStyle,
|
|
89
|
+
textAlign ? { textAlign } : undefined,
|
|
90
|
+
]}
|
|
91
|
+
>
|
|
92
|
+
{fragment.styles.imageAlt ?? extractImageAlt(fragment.text)}
|
|
93
|
+
</Text>
|
|
94
|
+
</View>
|
|
95
|
+
));
|
|
96
|
+
|
|
97
|
+
const content = (
|
|
98
|
+
<View style={[styles.lineContent, contentAlignStyle]}>
|
|
99
|
+
{textNode}
|
|
100
|
+
{imageNodes}
|
|
101
|
+
</View>
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
if (!marker) {
|
|
105
|
+
return (
|
|
106
|
+
<View key={`line-${lineIndex}`} style={styles.line}>
|
|
107
|
+
{content}
|
|
108
|
+
</View>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<View key={`line-${lineIndex}`} style={styles.listLine}>
|
|
114
|
+
<Text
|
|
115
|
+
style={[
|
|
116
|
+
styles.listMarker,
|
|
117
|
+
resolvedTheme.baseTextStyle ?? DEFAULT_THEME.baseTextStyle,
|
|
118
|
+
]}
|
|
119
|
+
>
|
|
120
|
+
{marker}
|
|
121
|
+
</Text>
|
|
122
|
+
<View style={styles.listContent}>{content}</View>
|
|
123
|
+
</View>
|
|
124
|
+
);
|
|
125
|
+
})}
|
|
126
|
+
</View>
|
|
127
|
+
);
|
|
128
|
+
},
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
RenderedOutput.displayName = 'RenderedOutput';
|
|
132
|
+
|
|
133
|
+
function splitSegmentsByLine(segments: StyledSegment[]): LineFragment[][] {
|
|
134
|
+
const lines: LineFragment[][] = [[]];
|
|
135
|
+
|
|
136
|
+
for (const segment of segments) {
|
|
137
|
+
const parts = segment.text.split('\n');
|
|
138
|
+
|
|
139
|
+
parts.forEach((part, index) => {
|
|
140
|
+
if (part.length > 0 || segment.styles.imageSrc) {
|
|
141
|
+
lines[lines.length - 1]?.push({
|
|
142
|
+
text: part,
|
|
143
|
+
styles: { ...segment.styles },
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (index < parts.length - 1) {
|
|
148
|
+
lines.push([]);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return lines;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function getLineStyle<K extends keyof FormatStyle>(
|
|
157
|
+
line: LineFragment[],
|
|
158
|
+
key: K,
|
|
159
|
+
): FormatStyle[K] {
|
|
160
|
+
for (const fragment of line) {
|
|
161
|
+
const value = fragment.styles[key];
|
|
162
|
+
if (value !== undefined) {
|
|
163
|
+
return value;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function extractImageAlt(text: string): string {
|
|
171
|
+
const normalized = text
|
|
172
|
+
.replace(/^\[Image:\s*/i, '')
|
|
173
|
+
.replace(/^\[Image\]/i, '')
|
|
174
|
+
.replace(/\]$/, '')
|
|
175
|
+
.trim();
|
|
176
|
+
|
|
177
|
+
return normalized.length > 0 ? normalized : 'image';
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const styles = StyleSheet.create({
|
|
181
|
+
container: {
|
|
182
|
+
gap: 10,
|
|
183
|
+
},
|
|
184
|
+
line: {
|
|
185
|
+
width: '100%',
|
|
186
|
+
},
|
|
187
|
+
lineContent: {
|
|
188
|
+
width: '100%',
|
|
189
|
+
gap: 8,
|
|
190
|
+
},
|
|
191
|
+
listLine: {
|
|
192
|
+
width: '100%',
|
|
193
|
+
flexDirection: 'row',
|
|
194
|
+
alignItems: 'flex-start',
|
|
195
|
+
gap: 8,
|
|
196
|
+
},
|
|
197
|
+
listMarker: {
|
|
198
|
+
minWidth: 20,
|
|
199
|
+
paddingTop: 1,
|
|
200
|
+
},
|
|
201
|
+
listContent: {
|
|
202
|
+
flex: 1,
|
|
203
|
+
},
|
|
204
|
+
alignLeft: {
|
|
205
|
+
alignItems: 'flex-start',
|
|
206
|
+
},
|
|
207
|
+
alignCenter: {
|
|
208
|
+
alignItems: 'center',
|
|
209
|
+
},
|
|
210
|
+
alignRight: {
|
|
211
|
+
alignItems: 'flex-end',
|
|
212
|
+
},
|
|
213
|
+
emptyLine: {
|
|
214
|
+
minHeight: 20,
|
|
215
|
+
width: '100%',
|
|
216
|
+
},
|
|
217
|
+
imageBlock: {
|
|
218
|
+
width: '100%',
|
|
219
|
+
gap: 6,
|
|
220
|
+
},
|
|
221
|
+
image: {
|
|
222
|
+
width: '100%',
|
|
223
|
+
height: 160,
|
|
224
|
+
borderRadius: 10,
|
|
225
|
+
backgroundColor: '#E5E7EB',
|
|
226
|
+
},
|
|
227
|
+
imageCaption: {
|
|
228
|
+
fontSize: 13,
|
|
229
|
+
opacity: 0.8,
|
|
230
|
+
},
|
|
231
|
+
});
|
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { RichTextInputProps } from '../types';
|
|
3
3
|
/**
|
|
4
|
-
* RichTextInput
|
|
4
|
+
* RichTextInput — The main rich text editor component.
|
|
5
5
|
*
|
|
6
|
-
* Uses the
|
|
7
|
-
*
|
|
8
|
-
* - A styled `<Text>` layer behind it renders the formatted content
|
|
9
|
-
* - Both share identical font metrics for pixel-perfect alignment
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```tsx
|
|
13
|
-
* <RichTextInput
|
|
14
|
-
* placeholder="Start typing..."
|
|
15
|
-
* showToolbar
|
|
16
|
-
* onChangeSegments={(segments) => console.log(segments)}
|
|
17
|
-
* />
|
|
18
|
-
* ```
|
|
6
|
+
* Uses a plain `TextInput` for editing and renders the serialized rich output
|
|
7
|
+
* below it as Markdown or HTML.
|
|
19
8
|
*/
|
|
20
9
|
export declare const RichTextInput: React.FC<RichTextInputProps>;
|