@licium/react-editor 3.2.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/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # TOAST UI Editor for React
2
+
3
+ > This is a [React](https://reactjs.org/) component wrapping [TOAST UI Editor](https://github.com/nhn/tui.editor/tree/master/apps/editor).
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@toast-ui/react-editor.svg)](https://www.npmjs.com/package/@toast-ui/react-editor)
6
+
7
+ ## 🚩 Table of Contents
8
+
9
+ - [Collect Statistics on the Use of Open Source](#collect-statistics-on-the-use-of-open-source)
10
+ - [Install](#-install)
11
+ - [Usage](#-usage)
12
+
13
+ ## Collect Statistics on the Use of Open Source
14
+
15
+ React Wrapper of TOAST UI Editor applies Google Analytics (GA) to collect statistics on the use of open source, in order to identify how widely TOAST UI Editor is used throughout the world. It also serves as important index to determine the future course of projects. location.hostname (e.g. ui.toast.com) is to be collected and the sole purpose is nothing but to measure statistics on the usage. To disable GA, use the `usageStatistics` props like the example below.
16
+
17
+ ```js
18
+ <Editor
19
+ ...
20
+ usageStatistics={false}
21
+ />
22
+ ```
23
+
24
+ ## 💾 Install
25
+
26
+ ### Using npm
27
+
28
+ ```sh
29
+ npm install --save @toast-ui/react-editor
30
+ ```
31
+
32
+ ## 📝 Usage
33
+
34
+ ### Import
35
+
36
+ You can use TOAST UI Editor for React as a ECMAScript module or a CommonJS module. As this module does not contain CSS files, you should import `toastui-editor.css` from `@toast-ui/editor` in the script.
37
+
38
+ - ES Modules
39
+
40
+ ```js
41
+ import '@toast-ui/editor/dist/toastui-editor.css';
42
+
43
+ import { Editor } from '@toast-ui/react-editor';
44
+ ```
45
+
46
+ - CommonJS
47
+
48
+ ```js
49
+ require('@toast-ui/editor/dist/toastui-editor.css');
50
+
51
+ const { Editor } = require('@toast-ui/react-editor');
52
+ ```
53
+
54
+ ### Props
55
+
56
+ [All the options of the TOAST UI Editor](https://nhn.github.io/tui.editor/latest/ToastUIEditor) are supported in the form of props.
57
+
58
+ ```js
59
+ import '@toast-ui/editor/dist/toastui-editor.css';
60
+
61
+ import { Editor } from '@toast-ui/react-editor';
62
+
63
+ const MyComponent = () => (
64
+ <Editor
65
+ initialValue="hello react editor world!"
66
+ previewStyle="vertical"
67
+ height="600px"
68
+ initialEditType="markdown"
69
+ useCommandShortcut={true}
70
+ />
71
+ );
72
+ ```
73
+
74
+ ### Instance Methods
75
+
76
+ For using [instance methods of TOAST UI Editor](https://nhn.github.io/tui.editor/latest/ToastUIEditor#addHook), first thing to do is creating Refs of wrapper component using [`createRef()`](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs). But the wrapper component does not provide a way to call instance methods of TOAST UI Editor directly. Instead, you can call `getInstance()` method of the wrapper component to get the instance, and call the methods on it.
77
+
78
+ ```js
79
+ import '@toast-ui/editor/dist/toastui-editor.css';
80
+
81
+ import { Editor } from '@toast-ui/react-editor';
82
+
83
+ class MyComponent extends React.Component {
84
+ editorRef = React.createRef();
85
+
86
+ handleClick = () => {
87
+ this.editorRef.current.getInstance().exec('bold');
88
+ };
89
+
90
+ render() {
91
+ return (
92
+ <>
93
+ <Editor
94
+ previewStyle="vertical"
95
+ height="400px"
96
+ initialEditType="markdown"
97
+ initialValue="hello"
98
+ ref={this.editorRef}
99
+ />
100
+ <button onClick={this.handleClick}>make bold</button>
101
+ </>
102
+ );
103
+ }
104
+ }
105
+ ```
106
+
107
+ #### Getting the Root Element
108
+
109
+ An instance of the wrapper component also provides a handy method for getting the root element. If you want to manipulate the root element directly, you can call `getRootElement` to get the element.
110
+
111
+ ```js
112
+ import '@toast-ui/editor/dist/toastui-editor.css';
113
+
114
+ import { Editor } from '@toast-ui/react-editor';
115
+
116
+ class MyComponent extends React.Component {
117
+ editorRef = React.createRef();
118
+
119
+ handleClickButton = () => {
120
+ this.editorRef.current.getRootElement().classList.add('my-editor-root');
121
+ };
122
+
123
+ render() {
124
+ return (
125
+ <>
126
+ <Editor
127
+ previewStyle="vertical"
128
+ height="400px"
129
+ initialEditType="markdown"
130
+ initialValue="hello"
131
+ ref={this.editorRef}
132
+ />
133
+ <button onClick={this.handleClickButton}>Click!</button>
134
+ </>
135
+ );
136
+ }
137
+ }
138
+ ```
139
+
140
+ ### Events
141
+
142
+ [All the events of TOAST UI Editor](https://nhn.github.io/tui.editor/latest/ToastUIEditor#focus) are supported in the form of `on[EventName]` props. The first letter of each event name should be capitalized. For example, for using `focus` event you can use `onFocus` prop like the example below.
143
+
144
+ ```js
145
+ import '@toast-ui/editor/dist/toastui-editor.css';
146
+
147
+ import { Editor } from '@toast-ui/react-editor';
148
+
149
+ class MyComponent extends React.Component {
150
+ handleFocus = () => {
151
+ console.log('focus!!');
152
+ };
153
+
154
+ render() {
155
+ return (
156
+ <Editor
157
+ previewStyle="vertical"
158
+ height="400px"
159
+ initialEditType="markdown"
160
+ initialValue="hello"
161
+ ref={this.editorRef}
162
+ onFocus={this.handleFocus}
163
+ />
164
+ );
165
+ }
166
+ }
167
+ ```
@@ -0,0 +1,164 @@
1
+ /**
2
+ * TOAST UI Editor : React Wrapper
3
+ * @version 3.2.3 | Fri Jan 02 2026
4
+ * @author NHN Cloud FE Development Lab <dl_javascript@nhn.com>
5
+ * @license MIT
6
+ */
7
+
8
+ import React from 'react';
9
+ import Editor from '@toast-ui/editor';
10
+ import Viewer from '@toast-ui/editor/dist/toastui-editor-viewer';
11
+
12
+ /*! *****************************************************************************
13
+ Copyright (c) Microsoft Corporation.
14
+
15
+ Permission to use, copy, modify, and/or distribute this software for any
16
+ purpose with or without fee is hereby granted.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
21
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24
+ PERFORMANCE OF THIS SOFTWARE.
25
+ ***************************************************************************** */
26
+ /* global Reflect, Promise */
27
+
28
+ var extendStatics = function(d, b) {
29
+ extendStatics = Object.setPrototypeOf ||
30
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
31
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
32
+ return extendStatics(d, b);
33
+ };
34
+
35
+ function __extends(d, b) {
36
+ if (typeof b !== "function" && b !== null)
37
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
38
+ extendStatics(d, b);
39
+ function __() { this.constructor = d; }
40
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
41
+ }
42
+
43
+ var __assign = function() {
44
+ __assign = Object.assign || function __assign(t) {
45
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
46
+ s = arguments[i];
47
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
48
+ }
49
+ return t;
50
+ };
51
+ return __assign.apply(this, arguments);
52
+ };
53
+
54
+ var default_1 = /** @class */ (function (_super) {
55
+ __extends(default_1, _super);
56
+ function default_1() {
57
+ var _this = _super !== null && _super.apply(this, arguments) || this;
58
+ _this.rootEl = React.createRef();
59
+ return _this;
60
+ }
61
+ default_1.prototype.getRootElement = function () {
62
+ return this.rootEl.current;
63
+ };
64
+ default_1.prototype.getInstance = function () {
65
+ return this.editorInst;
66
+ };
67
+ default_1.prototype.getBindingEventNames = function () {
68
+ var _this = this;
69
+ return Object.keys(this.props)
70
+ .filter(function (key) { return /^on[A-Z][a-zA-Z]+/.test(key); })
71
+ .filter(function (key) { return _this.props[key]; });
72
+ };
73
+ default_1.prototype.bindEventHandlers = function (props) {
74
+ var _this = this;
75
+ this.getBindingEventNames().forEach(function (key) {
76
+ var eventName = key[2].toLowerCase() + key.slice(3);
77
+ _this.editorInst.off(eventName);
78
+ _this.editorInst.on(eventName, props[key]);
79
+ });
80
+ };
81
+ default_1.prototype.getInitEvents = function () {
82
+ var _this = this;
83
+ return this.getBindingEventNames().reduce(function (acc, key) {
84
+ var eventName = (key[2].toLowerCase() + key.slice(3));
85
+ acc[eventName] = _this.props[key];
86
+ return acc;
87
+ }, {});
88
+ };
89
+ default_1.prototype.componentDidMount = function () {
90
+ this.editorInst = new Editor(__assign(__assign({ el: this.rootEl.current }, this.props), { events: this.getInitEvents() }));
91
+ };
92
+ default_1.prototype.shouldComponentUpdate = function (nextProps) {
93
+ var instance = this.getInstance();
94
+ var height = nextProps.height, previewStyle = nextProps.previewStyle;
95
+ if (height && this.props.height !== height) {
96
+ instance.setHeight(height);
97
+ }
98
+ if (previewStyle && this.props.previewStyle !== previewStyle) {
99
+ instance.changePreviewStyle(previewStyle);
100
+ }
101
+ this.bindEventHandlers(nextProps);
102
+ return false;
103
+ };
104
+ default_1.prototype.componentWillUnmount = function () {
105
+ this.editorInst.destroy();
106
+ };
107
+ default_1.prototype.render = function () {
108
+ return React.createElement("div", { ref: this.rootEl });
109
+ };
110
+ return default_1;
111
+ }(React.Component));
112
+
113
+ var ViewerComponent = /** @class */ (function (_super) {
114
+ __extends(ViewerComponent, _super);
115
+ function ViewerComponent() {
116
+ var _this = _super !== null && _super.apply(this, arguments) || this;
117
+ _this.rootEl = React.createRef();
118
+ return _this;
119
+ }
120
+ ViewerComponent.prototype.getRootElement = function () {
121
+ return this.rootEl.current;
122
+ };
123
+ ViewerComponent.prototype.getInstance = function () {
124
+ return this.viewerInst;
125
+ };
126
+ ViewerComponent.prototype.getBindingEventNames = function () {
127
+ var _this = this;
128
+ return Object.keys(this.props)
129
+ .filter(function (key) { return /^on[A-Z][a-zA-Z]+/.test(key); })
130
+ .filter(function (key) { return _this.props[key]; });
131
+ };
132
+ ViewerComponent.prototype.bindEventHandlers = function (props) {
133
+ var _this = this;
134
+ this.getBindingEventNames().forEach(function (key) {
135
+ var eventName = key[2].toLowerCase() + key.slice(3);
136
+ _this.viewerInst.off(eventName);
137
+ _this.viewerInst.on(eventName, props[key]);
138
+ });
139
+ };
140
+ ViewerComponent.prototype.getInitEvents = function () {
141
+ var _this = this;
142
+ return this.getBindingEventNames().reduce(function (acc, key) {
143
+ var eventName = (key[2].toLowerCase() + key.slice(3));
144
+ acc[eventName] = _this.props[key];
145
+ return acc;
146
+ }, {});
147
+ };
148
+ ViewerComponent.prototype.componentDidMount = function () {
149
+ this.viewerInst = new Viewer(__assign(__assign({ el: this.rootEl.current }, this.props), { events: this.getInitEvents() }));
150
+ };
151
+ ViewerComponent.prototype.shouldComponentUpdate = function (nextProps) {
152
+ this.bindEventHandlers(nextProps);
153
+ return false;
154
+ };
155
+ ViewerComponent.prototype.componentWillUnmount = function () {
156
+ this.viewerInst.destroy();
157
+ };
158
+ ViewerComponent.prototype.render = function () {
159
+ return React.createElement("div", { ref: this.rootEl });
160
+ };
161
+ return ViewerComponent;
162
+ }(React.Component));
163
+
164
+ export { default_1 as Editor, ViewerComponent as Viewer };
@@ -0,0 +1,2 @@
1
+ /*! For license information please see toastui-react-editor.js.LICENSE.txt */
2
+ !function(){"use strict";var t={n:function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,{a:n}),n},d:function(e,n){for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{Editor:function(){return a},Viewer:function(){return d}});var n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)};function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var o=function(){return o=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},o.apply(this,arguments)};Object.create,Object.create;var i=require("react"),s=t.n(i),u=require("@toast-ui/editor"),p=t.n(u),c=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.rootEl=s().createRef(),e}return r(e,t),e.prototype.getRootElement=function(){return this.rootEl.current},e.prototype.getInstance=function(){return this.editorInst},e.prototype.getBindingEventNames=function(){var t=this;return Object.keys(this.props).filter((function(t){return/^on[A-Z][a-zA-Z]+/.test(t)})).filter((function(e){return t.props[e]}))},e.prototype.bindEventHandlers=function(t){var e=this;this.getBindingEventNames().forEach((function(n){var r=n[2].toLowerCase()+n.slice(3);e.editorInst.off(r),e.editorInst.on(r,t[n])}))},e.prototype.getInitEvents=function(){var t=this;return this.getBindingEventNames().reduce((function(e,n){return e[n[2].toLowerCase()+n.slice(3)]=t.props[n],e}),{})},e.prototype.componentDidMount=function(){this.editorInst=new(p())(o(o({el:this.rootEl.current},this.props),{events:this.getInitEvents()}))},e.prototype.shouldComponentUpdate=function(t){var e=this.getInstance(),n=t.height,r=t.previewStyle;return n&&this.props.height!==n&&e.setHeight(n),r&&this.props.previewStyle!==r&&e.changePreviewStyle(r),this.bindEventHandlers(t),!1},e.prototype.componentWillUnmount=function(){this.editorInst.destroy()},e.prototype.render=function(){return s().createElement("div",{ref:this.rootEl})},e}(s().Component),a=c,f=require("@toast-ui/editor/dist/toastui-editor-viewer"),l=t.n(f),h=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.rootEl=s().createRef(),e}return r(e,t),e.prototype.getRootElement=function(){return this.rootEl.current},e.prototype.getInstance=function(){return this.viewerInst},e.prototype.getBindingEventNames=function(){var t=this;return Object.keys(this.props).filter((function(t){return/^on[A-Z][a-zA-Z]+/.test(t)})).filter((function(e){return t.props[e]}))},e.prototype.bindEventHandlers=function(t){var e=this;this.getBindingEventNames().forEach((function(n){var r=n[2].toLowerCase()+n.slice(3);e.viewerInst.off(r),e.viewerInst.on(r,t[n])}))},e.prototype.getInitEvents=function(){var t=this;return this.getBindingEventNames().reduce((function(e,n){return e[n[2].toLowerCase()+n.slice(3)]=t.props[n],e}),{})},e.prototype.componentDidMount=function(){this.viewerInst=new(l())(o(o({el:this.rootEl.current},this.props),{events:this.getInitEvents()}))},e.prototype.shouldComponentUpdate=function(t){return this.bindEventHandlers(t),!1},e.prototype.componentWillUnmount=function(){this.viewerInst.destroy()},e.prototype.render=function(){return s().createElement("div",{ref:this.rootEl})},e}(s().Component),d=h;module.exports=e}();
@@ -0,0 +1,21 @@
1
+ /*!
2
+ * TOAST UI Editor : React Wrapper
3
+ * @version 3.2.3 | Fri Jan 02 2026
4
+ * @author NHN Cloud FE Development Lab <dl_javascript@nhn.com>
5
+ * @license MIT
6
+ */
7
+
8
+ /*! *****************************************************************************
9
+ Copyright (c) Microsoft Corporation.
10
+
11
+ Permission to use, copy, modify, and/or distribute this software for any
12
+ purpose with or without fee is hereby granted.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
+ PERFORMANCE OF THIS SOFTWARE.
21
+ ***************************************************************************** */
package/index.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { Component } from 'react';
2
+ import ToastuiEditor, { EditorOptions, ViewerOptions, EventMap } from '@licium/editor';
3
+ import ToastuiEditorViewer from '@licium/editor/dist/toastui-editor-viewer';
4
+
5
+ export interface EventMapping {
6
+ onLoad: EventMap['load'];
7
+ onChange: EventMap['change'];
8
+ onCaretChange: EventMap['caretChange'];
9
+ onFocus: EventMap['focus'];
10
+ onBlur: EventMap['blur'];
11
+ onKeydown: EventMap['keydown'];
12
+ onKeyup: EventMap['keyup'];
13
+ onBeforePreviewRender: EventMap['beforePreviewRender'];
14
+ onBeforeConvertWysiwygToMarkdown: EventMap['beforeConvertWysiwygToMarkdown'];
15
+ }
16
+
17
+ export type EventNames = keyof EventMapping;
18
+
19
+ export type EditorProps = Omit<EditorOptions, 'el'> & Partial<EventMapping>;
20
+ export type ViewerProps = Omit<ViewerOptions, 'el'> & Partial<EventMapping>;
21
+
22
+ export class Editor extends Component<EditorProps> {
23
+ getInstance(): ToastuiEditor;
24
+
25
+ getRootElement(): HTMLElement;
26
+ }
27
+
28
+ export class Viewer extends Component<ViewerProps> {
29
+ getInstance(): ToastuiEditorViewer;
30
+
31
+ getRootElement(): HTMLElement;
32
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@licium/react-editor",
3
+ "version": "3.2.3",
4
+ "description": "TOAST UI Editor for React",
5
+ "files": [
6
+ "dist",
7
+ "index.d.ts"
8
+ ],
9
+ "main": "dist/toastui-react-editor.js",
10
+ "module": "dist/esm/index.js",
11
+ "scripts": {
12
+ "test:types": "tsc",
13
+ "lint": "eslint .",
14
+ "serve": "snowpack dev",
15
+ "build": "webpack build && rollup -c"
16
+ },
17
+ "homepage": "https://ui.toast.com",
18
+ "bugs": {
19
+ "url": "https://github.com/nhn/tui.editor/issues"
20
+ },
21
+ "author": "NHN Cloud FE Development Lab <dl_javascript@nhn.com>",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/nhn/tui.editor.git",
25
+ "directory": "apps/react-editor"
26
+ },
27
+ "license": "MIT",
28
+ "browserslist": "last 2 versions, ie 11",
29
+ "peerDependencies": {
30
+ "react": "^17.0.1"
31
+ },
32
+ "devDependencies": {
33
+ "@types/react": "^17.0.3",
34
+ "react": "^17.0.1",
35
+ "react-dom": "^17.0.1"
36
+ },
37
+ "dependencies": {
38
+ "@licium/editor": "^3.2.2"
39
+ },
40
+ "gitHead": "cbc7cab7b3f081a1aaf1d338b8138512ace132b9"
41
+ }