@chaitrabhairappa/react-native-rich-text-editor 1.0.2 → 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 (3) hide show
  1. package/package.json +3 -4
  2. package/src/index.tsx +0 -199
  3. package/src/types.ts +0 -125
package/package.json CHANGED
@@ -1,14 +1,13 @@
1
1
  {
2
2
  "name": "@chaitrabhairappa/react-native-rich-text-editor",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "A powerful native rich text editor for React Native with support for text formatting, lists, and more",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
7
7
  "types": "lib/typescript/src/index.d.ts",
8
- "react-native": "src/index.tsx",
9
- "source": "src/index.tsx",
8
+ "react-native": "lib/module/index.js",
9
+ "source": "lib/module/index.js",
10
10
  "files": [
11
- "src",
12
11
  "lib",
13
12
  "android",
14
13
  "!android/build",
package/src/index.tsx DELETED
@@ -1,199 +0,0 @@
1
- import React, { forwardRef, useImperativeHandle, useRef, useCallback, useState } from 'react';
2
- import { requireNativeComponent, UIManager, findNodeHandle, StyleSheet } from 'react-native';
3
- import type {
4
- Block,
5
- TextAlignment,
6
- ContentChangeEvent,
7
- SelectionChangeEvent,
8
- RichTextEditorProps,
9
- RichTextEditorRef,
10
- } from './types';
11
-
12
- const COMPONENT_NAME = 'RichTextEditorView';
13
-
14
- interface SizeChangeEvent {
15
- nativeEvent: {
16
- height: number;
17
- };
18
- }
19
-
20
- interface NativeComponentProps extends Omit<RichTextEditorProps, 'onFocus' | 'onBlur' | 'readOnly' | 'initialContent' | 'toolbarOptions'> {
21
- editable?: boolean;
22
- initialContent?: Block[];
23
- toolbarOptions?: string[];
24
- onEditorFocus?: () => void;
25
- onEditorBlur?: () => void;
26
- onSizeChange?: (event: SizeChangeEvent) => void;
27
- }
28
-
29
- const RichTextEditorViewNative = requireNativeComponent<NativeComponentProps>(COMPONENT_NAME);
30
-
31
- const RichTextEditor = forwardRef<RichTextEditorRef, RichTextEditorProps>(
32
- (props, ref) => {
33
- const nativeRef = useRef(null);
34
- const [height, setHeight] = useState<number>(44);
35
-
36
- const handleSizeChange = useCallback((event: SizeChangeEvent) => {
37
- const newHeight = event.nativeEvent?.height;
38
- if (newHeight && newHeight > 0) {
39
- setHeight(newHeight);
40
- }
41
- }, []);
42
-
43
- const dispatchCommand = useCallback((command: string, args: unknown[] = []) => {
44
- const handle = findNodeHandle(nativeRef.current);
45
- if (handle) {
46
- const commands = UIManager.getViewManagerConfig(COMPONENT_NAME)?.Commands;
47
- const commandId = commands?.[command];
48
- if (commandId !== undefined) {
49
- UIManager.dispatchViewManagerCommand(handle, commandId, args);
50
- }
51
- }
52
- }, []);
53
-
54
- useImperativeHandle(ref, () => ({
55
- setContent: (blocks: Block[]) => {
56
- dispatchCommand('setContent', [blocks]);
57
- },
58
- getText: async (): Promise<string> => {
59
- return new Promise((resolve) => {
60
- resolve('');
61
- });
62
- },
63
- getBlocks: async (): Promise<Block[]> => {
64
- return new Promise((resolve) => {
65
- resolve([]);
66
- });
67
- },
68
- clear: () => {
69
- dispatchCommand('clear');
70
- },
71
- focus: () => {
72
- dispatchCommand('focus');
73
- },
74
- blur: () => {
75
- dispatchCommand('blur');
76
- },
77
- toggleBold: () => {
78
- dispatchCommand('toggleBold');
79
- },
80
- toggleItalic: () => {
81
- dispatchCommand('toggleItalic');
82
- },
83
- toggleUnderline: () => {
84
- dispatchCommand('toggleUnderline');
85
- },
86
- toggleStrikethrough: () => {
87
- dispatchCommand('toggleStrikethrough');
88
- },
89
- toggleCode: () => {
90
- dispatchCommand('toggleCode');
91
- },
92
- toggleHighlight: (color?: string) => {
93
- dispatchCommand('toggleHighlight', color ? [color] : []);
94
- },
95
- setHeading: () => {
96
- dispatchCommand('setHeading');
97
- },
98
- setBulletList: () => {
99
- dispatchCommand('setBulletList');
100
- },
101
- setNumberedList: () => {
102
- dispatchCommand('setNumberedList');
103
- },
104
- setQuote: () => {
105
- dispatchCommand('setQuote');
106
- },
107
- setChecklist: () => {
108
- dispatchCommand('setChecklist');
109
- },
110
- setParagraph: () => {
111
- dispatchCommand('setParagraph');
112
- },
113
- insertLink: (url: string, text: string) => {
114
- dispatchCommand('insertLink', [url, text]);
115
- },
116
- undo: () => {
117
- dispatchCommand('undo');
118
- },
119
- redo: () => {
120
- dispatchCommand('redo');
121
- },
122
- clearFormatting: () => {
123
- dispatchCommand('clearFormatting');
124
- },
125
- indent: () => {
126
- dispatchCommand('indent');
127
- },
128
- outdent: () => {
129
- dispatchCommand('outdent');
130
- },
131
- setAlignment: (alignment: TextAlignment) => {
132
- dispatchCommand('setAlignment', [alignment]);
133
- },
134
- toggleChecklistItem: () => {
135
- dispatchCommand('toggleChecklistItem');
136
- },
137
- }));
138
-
139
- const handleContentChange = useCallback(
140
- (event: ContentChangeEvent) => {
141
- props.onContentChange?.(event);
142
- },
143
- [props.onContentChange]
144
- );
145
-
146
- const handleSelectionChange = useCallback(
147
- (event: SelectionChangeEvent) => {
148
- props.onSelectionChange?.(event);
149
- },
150
- [props.onSelectionChange]
151
- );
152
-
153
- const handleFocus = useCallback(() => {
154
- props.onFocus?.();
155
- }, [props.onFocus]);
156
-
157
- const handleBlur = useCallback(() => {
158
- props.onBlur?.();
159
- }, [props.onBlur]);
160
-
161
- const combinedStyle = StyleSheet.flatten([props.style, { height }]);
162
-
163
- return (
164
- <RichTextEditorViewNative
165
- ref={nativeRef}
166
- style={combinedStyle}
167
- placeholder={props.placeholder}
168
- initialContent={props.initialContent}
169
- editable={props.readOnly !== undefined ? !props.readOnly : true}
170
- maxHeight={props.maxHeight}
171
- showToolbar={props.readOnly ? false : (props.showToolbar ?? true)}
172
- toolbarOptions={props.toolbarOptions}
173
- variant={props.variant ?? 'outlined'}
174
- onContentChange={handleContentChange}
175
- onSelectionChange={handleSelectionChange}
176
- onEditorFocus={handleFocus}
177
- onEditorBlur={handleBlur}
178
- onSizeChange={handleSizeChange}
179
- />
180
- );
181
- }
182
- );
183
-
184
- RichTextEditor.displayName = 'RichTextEditor';
185
-
186
- export default RichTextEditor;
187
- export { DEFAULT_TOOLBAR_OPTIONS } from './types';
188
- export type {
189
- Block,
190
- BlockType,
191
- StyleRange,
192
- TextAlignment,
193
- EditorVariant,
194
- ContentChangeEvent,
195
- SelectionChangeEvent,
196
- RichTextEditorRef,
197
- RichTextEditorProps,
198
- ToolbarOption,
199
- } from './types';
package/src/types.ts DELETED
@@ -1,125 +0,0 @@
1
- import type { StyleProp, ViewStyle } from 'react-native';
2
-
3
- export interface StyleRange {
4
- style: 'bold' | 'italic' | 'underline' | 'strikethrough' | 'link' | 'code' | 'highlight';
5
- start: number;
6
- end: number;
7
- url?: string;
8
- highlightColor?: string;
9
- }
10
-
11
- export type BlockType = 'paragraph' | 'bullet' | 'numbered' | 'heading' | 'quote' | 'checklist';
12
- export type TextAlignment = 'left' | 'center' | 'right';
13
- export type EditorVariant = 'outlined' | 'flat';
14
-
15
- export interface Block {
16
- type: BlockType;
17
- text: string;
18
- styles: StyleRange[];
19
- alignment?: TextAlignment;
20
- checked?: boolean;
21
- indentLevel?: number;
22
- }
23
-
24
- export interface ContentChangeEvent {
25
- nativeEvent: {
26
- text: string;
27
- blocks: Block[];
28
- };
29
- }
30
-
31
- export interface SelectionChangeEvent {
32
- nativeEvent: {
33
- start: number;
34
- end: number;
35
- };
36
- }
37
-
38
- export type ToolbarOption =
39
- | 'bold'
40
- | 'italic'
41
- | 'strikethrough'
42
- | 'underline'
43
- | 'code'
44
- | 'highlight'
45
- | 'heading'
46
- | 'bullet'
47
- | 'numbered'
48
- | 'quote'
49
- | 'checklist'
50
- | 'link'
51
- | 'undo'
52
- | 'redo'
53
- | 'clearFormatting'
54
- | 'indent'
55
- | 'outdent'
56
- | 'alignLeft'
57
- | 'alignCenter'
58
- | 'alignRight';
59
-
60
- export const DEFAULT_TOOLBAR_OPTIONS: ToolbarOption[] = [
61
- 'bold',
62
- 'italic',
63
- 'underline',
64
- 'strikethrough',
65
- 'code',
66
- 'highlight',
67
- 'heading',
68
- 'bullet',
69
- 'numbered',
70
- 'quote',
71
- 'checklist',
72
- 'link',
73
- 'undo',
74
- 'redo',
75
- 'clearFormatting',
76
- 'indent',
77
- 'outdent',
78
- 'alignLeft',
79
- 'alignCenter',
80
- 'alignRight',
81
- ];
82
-
83
- export interface RichTextEditorProps {
84
- style?: StyleProp<ViewStyle>;
85
- placeholder?: string;
86
- initialContent?: Block[];
87
- readOnly?: boolean;
88
- maxHeight?: number;
89
- showToolbar?: boolean;
90
- toolbarOptions?: ToolbarOption[];
91
- variant?: EditorVariant;
92
- onContentChange?: (event: ContentChangeEvent) => void;
93
- onSelectionChange?: (event: SelectionChangeEvent) => void;
94
- onFocus?: () => void;
95
- onBlur?: () => void;
96
- }
97
-
98
- export interface RichTextEditorRef {
99
- setContent: (blocks: Block[]) => void;
100
- getText: () => Promise<string>;
101
- getBlocks: () => Promise<Block[]>;
102
- clear: () => void;
103
- focus: () => void;
104
- blur: () => void;
105
- toggleBold: () => void;
106
- toggleItalic: () => void;
107
- toggleUnderline: () => void;
108
- toggleStrikethrough: () => void;
109
- toggleCode: () => void;
110
- toggleHighlight: (color?: string) => void;
111
- setHeading: () => void;
112
- setBulletList: () => void;
113
- setNumberedList: () => void;
114
- setQuote: () => void;
115
- setChecklist: () => void;
116
- setParagraph: () => void;
117
- insertLink: (url: string, text: string) => void;
118
- undo: () => void;
119
- redo: () => void;
120
- clearFormatting: () => void;
121
- indent: () => void;
122
- outdent: () => void;
123
- setAlignment: (alignment: TextAlignment) => void;
124
- toggleChecklistItem: () => void;
125
- }