jodit-react 5.2.41 → 5.3.14
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/LICENSE +1 -1
- package/README.md +46 -37
- package/build/esm/index.d.mts +24 -0
- package/build/esm/index.mjs +125 -0
- package/build/react-jodit.js +2 -0
- package/build/types/JoditEditor.js +1 -0
- package/build/types/include.jodit.d.ts +1 -1
- package/package.json +56 -36
- package/.nvmrc +0 -1
- package/CHANGELOG.md +0 -98
- package/SECURITY.md +0 -10
- package/build/jodit-react.js +0 -2
- package/examples/app.css +0 -185
- package/examples/app.tsx +0 -17
- package/examples/components/Form.css +0 -5
- package/examples/components/Form.tsx +0 -148
- package/examples/index.html +0 -66
- package/index.d.ts +0 -4
- package/src/JoditEditor.tsx +0 -165
- package/src/include.jodit.ts +0 -7
- package/src/index.ts +0 -5
- package/tsconfig.json +0 -20
- /package/build/{jodit-react.js.LICENSE.txt → react-jodit.js.LICENSE.txt} +0 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -42,26 +42,27 @@ import React, { useState, useRef, useMemo } from 'react';
|
|
|
42
42
|
import JoditEditor from 'jodit-react';
|
|
43
43
|
|
|
44
44
|
const Example = ({ placeholder }) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
45
|
+
const editor = useRef(null);
|
|
46
|
+
const [content, setContent] = useState('');
|
|
47
|
+
|
|
48
|
+
const config = useMemo(
|
|
49
|
+
() => ({
|
|
50
|
+
readonly: false, // all options from https://xdsoft.net/jodit/docs/,
|
|
51
|
+
placeholder: placeholder || 'Start typings...'
|
|
52
|
+
}),
|
|
53
|
+
[placeholder]
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<JoditEditor
|
|
58
|
+
ref={editor}
|
|
59
|
+
value={content}
|
|
60
|
+
config={config}
|
|
61
|
+
tabIndex={1} // tabIndex of textarea
|
|
62
|
+
onBlur={newContent => setContent(newContent)} // preferred to use only this option to update the content for performance reasons
|
|
63
|
+
onChange={newContent => {}}
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
65
66
|
};
|
|
66
67
|
```
|
|
67
68
|
|
|
@@ -76,21 +77,21 @@ import JoditEditor, { Jodit } from 'jodit-react';
|
|
|
76
77
|
* @param {Jodit} jodit
|
|
77
78
|
*/
|
|
78
79
|
function preparePaste(jodit) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
80
|
+
jodit.e.on(
|
|
81
|
+
'paste',
|
|
82
|
+
e => {
|
|
83
|
+
if (confirm('Change pasted content?')) {
|
|
84
|
+
jodit.e.stopPropagation('paste');
|
|
85
|
+
jodit.s.insertHTML(
|
|
86
|
+
Jodit.modules.Helpers.getDataTransfer(e)
|
|
87
|
+
.getData(Jodit.constants.TEXT_HTML)
|
|
88
|
+
.replace(/a/g, 'b')
|
|
89
|
+
);
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{ top: true }
|
|
94
|
+
);
|
|
94
95
|
}
|
|
95
96
|
Jodit.plugins.add('preparePaste', preparePaste);
|
|
96
97
|
|
|
@@ -107,16 +108,24 @@ You can connect any Jodit constructor and set it as the `JoditConstructor` prope
|
|
|
107
108
|
```jsx
|
|
108
109
|
import React from 'react';
|
|
109
110
|
import JoditEditor from 'jodit-react';
|
|
110
|
-
import {Jodit} from 'jodit-pro';
|
|
111
|
+
import { Jodit } from 'jodit-pro';
|
|
111
112
|
import 'jodit-pro/es5/jodit.min.css';
|
|
112
113
|
// ...
|
|
113
114
|
|
|
114
115
|
function App() {
|
|
115
116
|
return <JoditEditor JoditConstructor={Jodit} />;
|
|
116
117
|
}
|
|
117
|
-
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
+
### Import and use Jodit-react inside your Next.js application
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
import dynamic from 'next/dynamic';
|
|
124
|
+
|
|
125
|
+
const JoditEditor = dynamic(() => import('jodit-react'), {
|
|
126
|
+
ssr: false
|
|
127
|
+
});
|
|
128
|
+
```
|
|
120
129
|
|
|
121
130
|
## License
|
|
122
131
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IJodit } from 'jodit/esm/types/jodit';
|
|
3
|
+
import { Jodit as Jodit$2 } from 'jodit/esm/index';
|
|
4
|
+
import { Config } from 'jodit/esm/config';
|
|
5
|
+
import { Jodit as Jodit$1 } from 'jodit/esm/jodit';
|
|
6
|
+
import { DeepPartial } from 'jodit/esm/types';
|
|
7
|
+
|
|
8
|
+
declare const Jodit: typeof Jodit$1;
|
|
9
|
+
|
|
10
|
+
interface Props<T extends typeof Jodit$2 = typeof Jodit> {
|
|
11
|
+
JoditConstructor?: T;
|
|
12
|
+
config?: DeepPartial<Config>;
|
|
13
|
+
className?: string;
|
|
14
|
+
id?: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
onBlur?: (value: string, event: MouseEvent) => void;
|
|
17
|
+
onChange?: (value: string) => void;
|
|
18
|
+
tabIndex?: number;
|
|
19
|
+
value?: string;
|
|
20
|
+
editorRef?: (editor: IJodit) => void;
|
|
21
|
+
}
|
|
22
|
+
declare const JoditEditor: React.ForwardRefExoticComponent<Props<typeof Jodit$2> & React.RefAttributes<IJodit>>;
|
|
23
|
+
|
|
24
|
+
export { Jodit, JoditEditor as default };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// src/JoditEditor.tsx
|
|
2
|
+
import { useEffect, useRef, forwardRef } from "react";
|
|
3
|
+
|
|
4
|
+
// src/include.jodit.ts
|
|
5
|
+
import { Jodit as JoditES5 } from "jodit/esm/index";
|
|
6
|
+
import "jodit/es2021/jodit.min.css";
|
|
7
|
+
import "jodit/esm/plugins/all";
|
|
8
|
+
var Jodit = JoditES5;
|
|
9
|
+
|
|
10
|
+
// src/JoditEditor.tsx
|
|
11
|
+
import { jsx } from "react/jsx-runtime";
|
|
12
|
+
function usePrevious(value) {
|
|
13
|
+
const ref = useRef("");
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
ref.current = value;
|
|
16
|
+
}, [value]);
|
|
17
|
+
return ref.current;
|
|
18
|
+
}
|
|
19
|
+
var JoditEditor = forwardRef(
|
|
20
|
+
({
|
|
21
|
+
JoditConstructor = Jodit,
|
|
22
|
+
className,
|
|
23
|
+
config,
|
|
24
|
+
id,
|
|
25
|
+
name,
|
|
26
|
+
onBlur,
|
|
27
|
+
onChange,
|
|
28
|
+
tabIndex,
|
|
29
|
+
value,
|
|
30
|
+
editorRef
|
|
31
|
+
}, ref) => {
|
|
32
|
+
const textAreaRef = useRef(null);
|
|
33
|
+
const joditRef = useRef(null);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const element = textAreaRef.current;
|
|
36
|
+
const jodit = JoditConstructor.make(element, config);
|
|
37
|
+
joditRef.current = jodit;
|
|
38
|
+
if (typeof editorRef === "function") {
|
|
39
|
+
editorRef(jodit);
|
|
40
|
+
}
|
|
41
|
+
return () => {
|
|
42
|
+
if (jodit.isReady) {
|
|
43
|
+
jodit.destruct();
|
|
44
|
+
} else {
|
|
45
|
+
jodit.waitForReady().then((joditInstance) => joditInstance.destruct());
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}, [JoditConstructor, config, editorRef]);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (ref) {
|
|
51
|
+
if (typeof ref === "function") {
|
|
52
|
+
ref(joditRef.current);
|
|
53
|
+
} else {
|
|
54
|
+
ref.current = joditRef.current;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, [textAreaRef, ref, joditRef]);
|
|
58
|
+
const preClassName = usePrevious(className != null ? className : "");
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
const classList = (_b = (_a = joditRef.current) == null ? void 0 : _a.container) == null ? void 0 : _b.classList;
|
|
62
|
+
if (preClassName !== className && typeof preClassName === "string") {
|
|
63
|
+
preClassName.split(/\s+/).filter(Boolean).forEach((cl) => classList == null ? void 0 : classList.remove(cl));
|
|
64
|
+
}
|
|
65
|
+
if (className && typeof className === "string") {
|
|
66
|
+
className.split(/\s+/).filter(Boolean).forEach((cl) => classList == null ? void 0 : classList.add(cl));
|
|
67
|
+
}
|
|
68
|
+
}, [className, preClassName]);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
var _a;
|
|
71
|
+
if ((_a = joditRef.current) == null ? void 0 : _a.workplace) {
|
|
72
|
+
joditRef.current.workplace.tabIndex = tabIndex || -1;
|
|
73
|
+
}
|
|
74
|
+
}, [tabIndex]);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const jodit = joditRef.current;
|
|
77
|
+
if (!(jodit == null ? void 0 : jodit.events) || !(onBlur || onChange)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const onBlurHandler = (event) => {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
return onBlur && onBlur((_b = (_a = joditRef == null ? void 0 : joditRef.current) == null ? void 0 : _a.value) != null ? _b : "", event);
|
|
83
|
+
};
|
|
84
|
+
const onChangeHandler = (value2) => onChange && onChange(value2);
|
|
85
|
+
jodit.events.on("blur", onBlurHandler).on("change", onChangeHandler);
|
|
86
|
+
return () => {
|
|
87
|
+
var _a;
|
|
88
|
+
(_a = jodit.events) == null ? void 0 : _a.off("blur", onBlurHandler).off("change", onChangeHandler);
|
|
89
|
+
};
|
|
90
|
+
}, [onBlur, onChange]);
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
const jodit = joditRef.current;
|
|
93
|
+
const updateValue = () => {
|
|
94
|
+
if (jodit && value !== void 0 && jodit.value !== value) {
|
|
95
|
+
jodit.value = value;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
if (jodit) {
|
|
99
|
+
if (jodit.isReady) {
|
|
100
|
+
updateValue();
|
|
101
|
+
} else {
|
|
102
|
+
jodit.waitForReady().then(updateValue);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}, [value]);
|
|
106
|
+
return /* @__PURE__ */ jsx("div", { className: "jodit-react-container", children: /* @__PURE__ */ jsx(
|
|
107
|
+
"textarea",
|
|
108
|
+
{
|
|
109
|
+
defaultValue: value,
|
|
110
|
+
name,
|
|
111
|
+
id,
|
|
112
|
+
ref: textAreaRef
|
|
113
|
+
}
|
|
114
|
+
) });
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
JoditEditor.displayName = "JoditEditor";
|
|
118
|
+
var JoditEditor_default = JoditEditor;
|
|
119
|
+
|
|
120
|
+
// src/index.ts
|
|
121
|
+
var index_default = JoditEditor_default;
|
|
122
|
+
export {
|
|
123
|
+
Jodit,
|
|
124
|
+
index_default as default
|
|
125
|
+
};
|