rn-rich-text-editor 0.0.1

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/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # React Native Rich Editor
2
+
3
+ A rich text editor component for React Native using WebView.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install rn-rich-text-editor
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```tsx
14
+ import { RichEditor, RichToolbar, actions } from 'rn-rich-text-editor';
15
+
16
+ function App() {
17
+ return (
18
+ <>
19
+ <RichEditor ref={editorRef} onMessage={handleMessage} />
20
+ <RichToolbar editorRef={editorRef} />
21
+ </>
22
+ );
23
+ }
24
+ ```
25
+
26
+ ## API
27
+
28
+ ### RichEditor
29
+
30
+ Main editor component.
31
+
32
+ **Props:**
33
+ - `onMessage?: (event: any) => void` - Callback for editor messages
34
+
35
+ **Ref Methods:**
36
+ - `sendAction(type: string)` - Send action to editor
37
+
38
+ ### RichToolbar
39
+
40
+ Toolbar component for editor actions.
41
+
42
+ **Props:**
43
+ - `editorRef: RefObject` - Reference to RichEditor instance
44
+
45
+ ### Actions
46
+
47
+ Predefined editor actions.
48
+
49
+ ## License
50
+
51
+ MIT
@@ -0,0 +1 @@
1
+ export declare const RichEditor: any;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.RichEditor = void 0;
37
+ const react_1 = __importStar(require("react"));
38
+ const react_native_webview_1 = require("react-native-webview");
39
+ const createHTML_1 = require("./editor/createHTML");
40
+ exports.RichEditor = (0, react_1.forwardRef)((props, ref) => {
41
+ const webRef = (0, react_1.useRef)(null);
42
+ (0, react_1.useImperativeHandle)(ref, () => ({
43
+ sendAction(type) {
44
+ var _a;
45
+ (_a = webRef.current) === null || _a === void 0 ? void 0 : _a.postMessage(JSON.stringify({ type }));
46
+ }
47
+ }));
48
+ return (react_1.default.createElement(react_native_webview_1.WebView, { ref: webRef, originWhitelist: ['*'], javaScriptEnabled: true, scrollEnabled: false, source: (0, createHTML_1.createHTML)(), onMessage: props.onMessage }));
49
+ });
@@ -0,0 +1 @@
1
+ export declare function RichToolbar({ editor }: any): any;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RichToolbar = RichToolbar;
7
+ const react_1 = __importDefault(require("react"));
8
+ const react_native_1 = require("react-native");
9
+ const actions_1 = require("./actions");
10
+ function RichToolbar({ editor }) {
11
+ return (react_1.default.createElement(react_native_1.View, { style: { flexDirection: 'row', padding: 8 } }, Object.values(actions_1.actions).map(action => (react_1.default.createElement(react_native_1.TouchableOpacity, { key: action, onPress: () => { var _a; return (_a = editor === null || editor === void 0 ? void 0 : editor.current) === null || _a === void 0 ? void 0 : _a.sendAction(action); } },
12
+ react_1.default.createElement(react_native_1.Text, { style: { marginHorizontal: 10 } }, action))))));
13
+ }
@@ -0,0 +1,9 @@
1
+ export declare const actions: {
2
+ readonly setBold: "bold";
3
+ readonly setItalic: "italic";
4
+ readonly setUnderline: "underline";
5
+ readonly checkboxList: "checkboxList";
6
+ readonly insertLink: "link";
7
+ readonly keyboard: "keyboard";
8
+ readonly init: "init";
9
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.actions = void 0;
4
+ exports.actions = {
5
+ setBold: 'bold',
6
+ setItalic: 'italic',
7
+ setUnderline: 'underline',
8
+ checkboxList: 'checkboxList',
9
+ insertLink: 'link',
10
+ keyboard: 'keyboard',
11
+ init: 'init'
12
+ };
@@ -0,0 +1 @@
1
+ export declare function getContentCSS(): string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getContentCSS = getContentCSS;
4
+ function getContentCSS() {
5
+ return `
6
+ <style>
7
+ img, video {
8
+ max-width: 100%;
9
+ display: block;
10
+ margin: 12px auto;
11
+ }
12
+ blockquote {
13
+ border-left: 4px solid #ddd;
14
+ padding-left: 12px;
15
+ margin: 12px 0;
16
+ }
17
+ pre {
18
+ background: #f4f4f4;
19
+ padding: 10px;
20
+ border-radius: 6px;
21
+ font-family: monospace;
22
+ }
23
+ </style>
24
+ `;
25
+ }
@@ -0,0 +1,3 @@
1
+ export declare function createHTML(): {
2
+ html: string;
3
+ };
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createHTML = createHTML;
4
+ const contentCSS_1 = require("./contentCSS");
5
+ function createHTML() {
6
+ return {
7
+ html: `
8
+ <!DOCTYPE html>
9
+ <html>
10
+ <head>
11
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
12
+ <style>
13
+ body { margin:0; font-family: system-ui; }
14
+ #editor {
15
+ padding: 12px;
16
+ min-height: 100%;
17
+ outline: none;
18
+ }
19
+ [placeholder]:empty::before {
20
+ content: attr(placeholder);
21
+ color: #999;
22
+ }
23
+ </style>
24
+ ${(0, contentCSS_1.getContentCSS)()}
25
+ </head>
26
+ <body>
27
+ <div id="editor" contenteditable="true" placeholder="Start typing..."></div>
28
+
29
+ <script>
30
+ const editor = document.getElementById('editor');
31
+
32
+ function post(type, data) {
33
+ window.ReactNativeWebView.postMessage(
34
+ JSON.stringify({ type, data })
35
+ );
36
+ }
37
+
38
+ editor.addEventListener('input', () => {
39
+ post('CONTENT_CHANGE', editor.innerHTML);
40
+ post('OFFSET_HEIGHT', editor.scrollHeight);
41
+ });
42
+
43
+ document.addEventListener('selectionchange', () => {
44
+ post('SELECTION_CHANGE', {
45
+ bold: document.queryCommandState('bold'),
46
+ italic: document.queryCommandState('italic'),
47
+ underline: document.queryCommandState('underline')
48
+ });
49
+ });
50
+
51
+ window.addEventListener('message', e => {
52
+ const msg = JSON.parse(e.data);
53
+ if (msg.type === 'bold') document.execCommand('bold');
54
+ if (msg.type === 'italic') document.execCommand('italic');
55
+ if (msg.type === 'underline') document.execCommand('underline');
56
+ });
57
+ </script>
58
+ </body>
59
+ </html>
60
+ `
61
+ };
62
+ }
@@ -0,0 +1,5 @@
1
+ export { RichEditor } from './RichEditor';
2
+ export { RichToolbar } from './RichToolbar';
3
+ export { actions } from './actions';
4
+ export { createHTML } from './editor/createHTML';
5
+ export { getContentCSS } from './editor/contentCSS';
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getContentCSS = exports.createHTML = exports.actions = exports.RichToolbar = exports.RichEditor = void 0;
4
+ var RichEditor_1 = require("./RichEditor");
5
+ Object.defineProperty(exports, "RichEditor", { enumerable: true, get: function () { return RichEditor_1.RichEditor; } });
6
+ var RichToolbar_1 = require("./RichToolbar");
7
+ Object.defineProperty(exports, "RichToolbar", { enumerable: true, get: function () { return RichToolbar_1.RichToolbar; } });
8
+ var actions_1 = require("./actions");
9
+ Object.defineProperty(exports, "actions", { enumerable: true, get: function () { return actions_1.actions; } });
10
+ var createHTML_1 = require("./editor/createHTML");
11
+ Object.defineProperty(exports, "createHTML", { enumerable: true, get: function () { return createHTML_1.createHTML; } });
12
+ var contentCSS_1 = require("./editor/contentCSS");
13
+ Object.defineProperty(exports, "getContentCSS", { enumerable: true, get: function () { return contentCSS_1.getContentCSS; } });
@@ -0,0 +1,7 @@
1
+ export declare const messages: {
2
+ readonly CONTENT_CHANGE: "CONTENT_CHANGE";
3
+ readonly SELECTION_CHANGE: "SELECTION_CHANGE";
4
+ readonly CONTENT_FOCUSED: "CONTENT_FOCUSED";
5
+ readonly CONTENT_BLUR: "CONTENT_BLUR";
6
+ readonly OFFSET_HEIGHT: "OFFSET_HEIGHT";
7
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.messages = void 0;
4
+ exports.messages = {
5
+ CONTENT_CHANGE: 'CONTENT_CHANGE',
6
+ SELECTION_CHANGE: 'SELECTION_CHANGE',
7
+ CONTENT_FOCUSED: 'CONTENT_FOCUSED',
8
+ CONTENT_BLUR: 'CONTENT_BLUR',
9
+ OFFSET_HEIGHT: 'OFFSET_HEIGHT'
10
+ };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "rn-rich-text-editor",
3
+ "version": "0.0.1",
4
+ "description": "A rich text editor component for React Native",
5
+ "keywords": [
6
+ "react-native",
7
+ "rich-editor",
8
+ "text-editor",
9
+ "webview"
10
+ ],
11
+ "author": "",
12
+ "license": "MIT",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/vishaal2002/rn-rich-text-editor.git"
16
+ },
17
+ "main": "dist/index.js",
18
+ "types": "dist/index.d.ts",
19
+ "files": [
20
+ "dist",
21
+ "package.json"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "watch": "tsc -w"
26
+ },
27
+ "peerDependencies": {
28
+ "react": "*",
29
+ "react-native": "*",
30
+ "react-native-webview": "*"
31
+ },
32
+ "devDependencies": {
33
+ "typescript": "^5.9.3"
34
+ }
35
+ }