jodit-react 1.1.22 → 1.2.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/examples/app.js CHANGED
@@ -3,8 +3,8 @@ import './app.css';
3
3
  import React from 'react';
4
4
  import ReactDOM from 'react-dom';
5
5
 
6
- import 'jodit';
6
+ import "jodit";
7
7
  import 'jodit/build/jodit.min.css';
8
- import From from "./components/From";
8
+ import Form from './components/Form';
9
9
 
10
- ReactDOM.render(<From/>, document.getElementById('editor'));
10
+ ReactDOM.render(<Form />, document.getElementById('editor'));
@@ -0,0 +1,5 @@
1
+ .simple-textarea {
2
+ display: block;
3
+ width: 100%;
4
+ min-height: 100px;
5
+ }
@@ -0,0 +1,117 @@
1
+ import React, { useCallback, useState } from 'react';
2
+
3
+ import JoditEditor from '../../src/';
4
+ import './Form.css';
5
+
6
+ const Form = () => {
7
+ const [isSource, setSource] = useState(false);
8
+
9
+ const [config, setConfig] = useState({
10
+ readonly: false,
11
+ toolbar: true
12
+ });
13
+
14
+ const [textAreaValue, setTextAreaValue] = useState('Test');
15
+
16
+ const [inputValue, setInputValue] = useState('');
17
+
18
+ const [spin, setSpin] = useState(1);
19
+
20
+ const toggleToolbar = useCallback(
21
+ () =>
22
+ setConfig(config => ({
23
+ ...config,
24
+ toolbar: !config.toolbar
25
+ })),
26
+ []
27
+ );
28
+
29
+ const toggleReadOnly = useCallback(
30
+ () =>
31
+ setConfig(config => ({
32
+ ...config,
33
+ readonly: !config.readonly
34
+ })),
35
+ []
36
+ );
37
+
38
+ const handleBlurAreaChange = useCallback((textAreaValue, event) => {
39
+ console.log('handleBlurAreaChange', textAreaValue, event);
40
+ }, []);
41
+
42
+ const handleWYSIWYGChange = useCallback(newTextAreaValue => {
43
+ console.log('handleWYSIWYGChange', newTextAreaValue);
44
+
45
+ setTextAreaValue(newTextAreaValue);
46
+ setInputValue(newTextAreaValue);
47
+
48
+ return setTextAreaValue(() => newTextAreaValue);
49
+ }, []);
50
+
51
+ const handleNativeTextAreaChange = useCallback(e => {
52
+ console.log('handleNativeTextAreaChange', e.target.value);
53
+ setTextAreaValue(e.target.value);
54
+ setInputValue(e.target.value);
55
+ }, []);
56
+
57
+ const handleInputChange = useCallback(e => {
58
+ const { value } = e.target;
59
+ setInputValue(() => value);
60
+ handleWYSIWYGChange(value);
61
+ }, []);
62
+
63
+ const handleSpin = useCallback(() => setSpin(spin => ++spin), []);
64
+
65
+ const onSourceChange = useCallback(e => {
66
+ setSource(e.target.checked);
67
+ }, []);
68
+
69
+ return (
70
+ <div>
71
+ <label>
72
+ <input
73
+ type="checkbox"
74
+ onChange={onSourceChange}
75
+ checked={isSource}
76
+ />{' '}
77
+ Source
78
+ </label>
79
+
80
+ {!isSource ? (
81
+ <JoditEditor
82
+ config={config}
83
+ onChange={handleWYSIWYGChange}
84
+ onBlur={handleBlurAreaChange}
85
+ value={textAreaValue}
86
+ />
87
+ ) : (
88
+ <textarea
89
+ className={'simple-textarea'}
90
+ onChange={handleNativeTextAreaChange}
91
+ value={textAreaValue}
92
+ />
93
+ )}
94
+
95
+ <input
96
+ onChange={handleInputChange}
97
+ placeholder={'enter some text'}
98
+ type={'text'}
99
+ value={inputValue}
100
+ />
101
+
102
+ <button onClick={toggleReadOnly} type={'button'}>
103
+ {'Toggle Read-Only'}
104
+ </button>
105
+
106
+ <button onClick={toggleToolbar} type={'button'}>
107
+ {'Toggle Toolbar'}
108
+ </button>
109
+
110
+ <button type={'button'} onClick={handleSpin}>
111
+ {`Spin ${spin}`}
112
+ </button>
113
+ </div>
114
+ );
115
+ };
116
+
117
+ export default Form;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jodit-react",
3
- "version": "1.1.22",
3
+ "version": "1.2.1",
4
4
  "description": "Jodit is awesome and usefully wysiwyg editor with filebrowser",
5
5
  "main": "build/jodit-react.js",
6
6
  "author": "Chupurnov <chupurnov@gmail.com> (https://xdsoft.net/)s",
@@ -24,6 +24,7 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "@babel/core": "^7.16.0",
27
+ "@babel/eslint-parser": "^7.17.0",
27
28
  "@babel/preset-env": "^7.16.0",
28
29
  "@babel/preset-react": "^7.16.0",
29
30
  "@types/react": "^16.14.2",
@@ -32,6 +33,13 @@
32
33
  "babel-loader": "^8.2.2",
33
34
  "babel-plugin-transform-class-properties": "^6.24.1",
34
35
  "css-loader": "^3.6.0",
36
+ "eslint": "^8.9.0",
37
+ "eslint-config-prettier": "^8.4.0",
38
+ "eslint-plugin-prettier": "^4.0.0",
39
+ "eslint-plugin-react": "^7.28.0",
40
+ "husky": "^7.0.4",
41
+ "lint-staged": "^12.3.4",
42
+ "prettier": "^2.5.1",
35
43
  "react": "^16.14.0",
36
44
  "react-dom": "^16.14.0",
37
45
  "style-loader": "^0.20.3",
@@ -42,6 +50,7 @@
42
50
  "scripts": {
43
51
  "newversion": "npm update && rm -rf build/ && npm run build && npm version patch --no-git-tag-version && npm run github && npm publish ./",
44
52
  "demo": "cd examples && export NODE_ENV=development && webpack-dev-server --config ./webpack.config.js --mode development --port 4000 --hot --inline",
53
+ "start": "npm run demo",
45
54
  "build": "export NODE_ENV=production && webpack --mode production",
46
55
  "github": "git add --all && git commit -m \"New version $npm_package_version. Read more https://github.com/jodit/jodit-react/releases/tag/$npm_package_version \" && git tag $npm_package_version && git push --tags origin HEAD:master"
47
56
  },
@@ -53,5 +62,16 @@
53
62
  "bugs": {
54
63
  "url": "https://github.com/jodit/jodit-react/issues"
55
64
  },
65
+ "husky": {
66
+ "hooks": {
67
+ "pre-commit": "lint-staged"
68
+ }
69
+ },
70
+ "lint-staged": {
71
+ "**/*.js": [
72
+ "eslint ./ --fix",
73
+ "git add"
74
+ ]
75
+ },
56
76
  "homepage": "https://xdsoft.net/jodit/"
57
77
  }
@@ -1,64 +1,76 @@
1
- import React, { useEffect, useRef, forwardRef, useLayoutEffect } from 'react'
2
- import { func, number, object, string } from 'prop-types'
3
- import { Jodit } from './include.jodit'
1
+ import React, { useEffect, useRef, forwardRef, useLayoutEffect } from 'react';
2
+ import { func, number, object, string } from 'prop-types';
3
+ import { Jodit } from './include.jodit';
4
+ const { isFunction } = Jodit.modules.Helpers;
4
5
 
5
- const JoditEditor = forwardRef(({
6
- config,
7
- id,
8
- name,
9
- onBlur,
10
- onChange,
11
- tabIndex,
12
- value,
13
- editorRef
14
- }, ref) => {
15
- const textArea = useRef()
6
+ const JoditEditor = forwardRef(
7
+ (
8
+ { config, id, name, onBlur, onChange, tabIndex, value, editorRef },
9
+ ref
10
+ ) => {
11
+ const textArea = useRef();
16
12
 
17
- useLayoutEffect(() => {
18
- if (ref) {
19
- if (typeof ref === 'function') {
20
- ref(textArea.current)
21
- } else {
22
- ref.current = textArea.current
13
+ useLayoutEffect(() => {
14
+ if (ref) {
15
+ if (isFunction(ref)) {
16
+ ref(textArea.current);
17
+ } else {
18
+ ref.current = textArea.current;
19
+ }
23
20
  }
24
- }
25
- }, [textArea])
21
+ }, [textArea]);
26
22
 
27
- useEffect(() => {
28
- const element = textArea.current
29
- textArea.current = Jodit.make(element, config)
30
- textArea.current.workplace.tabIndex = tabIndex || -1
23
+ useEffect(() => {
24
+ const element = textArea.current;
25
+ textArea.current = Jodit.make(element, config);
26
+ textArea.current.workplace.tabIndex = tabIndex || -1;
31
27
 
32
- // adding event handlers
33
- textArea.current.events.on('blur', (e) => onBlur && onBlur(textArea.current.value, e))
34
- textArea.current.events.on('change', value => onChange && onChange(value))
28
+ // adding event handlers
29
+ textArea.current.events.on(
30
+ 'blur',
31
+ e => onBlur && onBlur(textArea.current.value, e)
32
+ );
33
+ textArea.current.events.on(
34
+ 'change',
35
+ value => onChange && onChange(value)
36
+ );
35
37
 
36
- if (id) element.id = id
37
- if (name) element.name = name
38
+ if (id) {
39
+ element.id = id;
40
+ }
38
41
 
39
- if (typeof editorRef === 'function') {
40
- editorRef(textArea.current)
41
- }
42
+ if (name) {
43
+ element.name = name;
44
+ }
42
45
 
43
- return () => {
44
- if(textArea?.current){
45
- textArea.current.destruct()
46
+ if (isFunction(editorRef)) {
47
+ editorRef(textArea.current);
46
48
  }
47
49
 
48
- textArea.current = element
49
- }
50
- }, [config])
50
+ return () => {
51
+ if (textArea?.current) {
52
+ textArea.current.destruct();
53
+ }
54
+
55
+ textArea.current = element;
56
+ };
57
+ }, [config]);
58
+
59
+ useEffect(() => {
60
+ if (textArea?.current?.value !== value) {
61
+ textArea.current.value = value;
62
+ }
63
+ }, [value]);
51
64
 
52
- useEffect(() => {
53
- if (textArea?.current?.value !== value) {
54
- textArea.current.value = value
55
- }
56
- }, [value])
65
+ return (
66
+ <div className={'jodit-react-container'}>
67
+ <textarea ref={textArea} />
68
+ </div>
69
+ );
70
+ }
71
+ );
57
72
 
58
- return (
59
- <textarea ref={textArea} />
60
- )
61
- })
73
+ JoditEditor.displayName = 'JoditEditor';
62
74
 
63
75
  JoditEditor.propTypes = {
64
76
  config: object,
@@ -68,7 +80,7 @@ JoditEditor.propTypes = {
68
80
  onChange: func,
69
81
  editorRef: func,
70
82
  tabIndex: number,
71
- value: string,
72
- }
83
+ value: string
84
+ };
73
85
 
74
- export default JoditEditor
86
+ export default JoditEditor;
@@ -1,4 +1,4 @@
1
- import { Jodit } from 'jodit'
2
- import 'jodit/build/jodit.min.css'
1
+ import { Jodit } from 'jodit';
2
+ import 'jodit/build/jodit.min.css';
3
3
 
4
- export {Jodit};
4
+ export { Jodit };
package/src/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import JoditEditor from './JoditEditor';
2
-
3
- export default JoditEditor;
1
+ import JoditEditor from './JoditEditor';
2
+
3
+ export default JoditEditor;
package/.editorconfig DELETED
@@ -1,15 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- charset = utf-8
5
- end_of_line = lf
6
- indent_size = 2
7
- indent_style = tab
8
- trim_trailing_whitespace = true
9
- insert_final_newline = true
10
-
11
- [{LICENSE,.gitattributes,.gitignore,.npmignore,.eslintignore}]
12
- indent_style = space
13
-
14
- [*.{json,yml,md,yaspellerrc,bowerrc,babelrc,snakeskinrc,eslintrc,tsconfig,pzlrrc}]
15
- indent_style = space
@@ -1,88 +0,0 @@
1
- import React, {useState} from 'react';
2
-
3
- import JoditEditor from "../../src/";
4
-
5
- const From = () => {
6
- const [config, setConfig] = useState({
7
- readonly: false,
8
- toolbar: true,
9
- })
10
-
11
- const [textAreaValue, setTextAreaValue] = useState('Test')
12
-
13
- const [inputValue, setInputValue] = useState('')
14
-
15
- const [spin, setSpin] = useState(1)
16
-
17
- const toggleToolbar = () => (
18
- setConfig(config => ({
19
- ...config,
20
- toolbar: !config.toolbar,
21
- }))
22
- )
23
-
24
- const toggleReadOnly = () => (
25
- setConfig(config => ({
26
- ...config,
27
- readonly: !config.readonly,
28
- }))
29
- )
30
-
31
- const handleBlurAreaChange = (textAreaValue, event) => {
32
- console.log('handleBlurAreaChange', textAreaValue, event)
33
- };
34
-
35
- const handleTextAreaChange = newTextAreaValue => {
36
- console.log('handleTextAreaChange', newTextAreaValue)
37
-
38
- return (
39
- setTextAreaValue(() => newTextAreaValue)
40
- )
41
- }
42
-
43
- const handleInputChange = e => {
44
- const {value} = e.target
45
- setInputValue(() => value)
46
- handleTextAreaChange(value)
47
- }
48
-
49
- const handleSpin = () => setSpin(spin => ++spin)
50
-
51
- return (
52
- <div>
53
- <JoditEditor
54
- config={config}
55
- onChange={handleTextAreaChange}
56
- onBlur={handleBlurAreaChange}
57
- value={textAreaValue}
58
- />
59
-
60
- <input
61
- onChange={handleInputChange}
62
- placeholder={"enter some text"}
63
- type={"text"}
64
- value={inputValue}
65
- />
66
-
67
- <button
68
- onClick={toggleReadOnly}
69
- type={"button"}>
70
- {'Toggle Read-Only'}
71
- </button>
72
-
73
- <button
74
- onClick={toggleToolbar}
75
- type={"button"}>
76
- {'Toggle Toolbar'}
77
- </button>
78
-
79
- <button
80
- type={"button"}
81
- onClick={handleSpin}>
82
- {`Spin ${spin}`}
83
- </button>
84
- </div>
85
- )
86
- }
87
-
88
- export default From
@@ -1,40 +0,0 @@
1
- var path = require('path');
2
-
3
- module.exports = {
4
- entry: './app.js',
5
- devtool: "eval",
6
- module: {
7
- rules: [
8
- {
9
- test: /\.js$/,
10
- use: [
11
- {
12
- loader: 'babel-loader',
13
- options: {
14
- presets: [
15
- "@babel/preset-env",
16
- "@babel/preset-react"
17
- ]
18
- }
19
- }
20
- ]
21
- },
22
- {
23
- test: /\.css$/,
24
- use: [
25
- 'style-loader',
26
- 'css-loader'
27
- ],
28
- },
29
- ]
30
- },
31
-
32
- output: {
33
- path: path.join(__dirname, '/build/'),
34
- filename: 'app.js'
35
- },
36
-
37
- devServer: {
38
- contentBase: './'
39
- }
40
- };
package/webpack.config.js DELETED
@@ -1,71 +0,0 @@
1
- const webpack = require("webpack");
2
- const path = require('path');
3
-
4
- module.exports = (env, argv, dir = process.cwd()) => {
5
- const debug = !argv || !argv.mode || !argv.mode.match(/production/);
6
-
7
- return {
8
- context: dir,
9
-
10
- entry: './src/index.js',
11
- devtool: debug ? 'inline-source-map' : false,
12
-
13
- module: {
14
- rules: [
15
- {
16
- test: /\.js$/,
17
- use: {
18
- loader: 'babel-loader',
19
- options: require(path.join(dir, './babel.config.json'))
20
- }
21
- },
22
- {
23
- test: /\.css$/,
24
- use: [
25
- 'style-loader',
26
- 'css-loader'
27
- ],
28
- },
29
- ]
30
- },
31
-
32
- resolve: {
33
- alias: {
34
- "jodit-react": path.join(__dirname, './src')
35
- },
36
- },
37
-
38
- output: {
39
- path: path.join(dir, './build/'),
40
- filename: 'jodit-react.js',
41
- library: 'JoditEditor',
42
- libraryTarget: 'umd'
43
- },
44
-
45
- plugins: [
46
- new webpack.DefinePlugin({
47
- 'process.env': {
48
- NODE_ENV: JSON.stringify(debug ? 'development' : 'production'),
49
- },
50
- }),
51
- new webpack.optimize.ModuleConcatenationPlugin(),
52
- ],
53
-
54
- externals: {
55
- jodit: 'jodit',
56
- Jodit: 'Jodit',
57
- react: {
58
- root: 'React',
59
- commonjs2: 'react',
60
- commonjs: 'react',
61
- amd: 'react'
62
- },
63
- 'react-dom': {
64
- root: 'ReactDOM',
65
- commonjs2: 'react-dom',
66
- commonjs: 'react-dom',
67
- amd: 'react-dom'
68
- }
69
- }
70
- }
71
- };