jodit-react 5.2.41 → 5.3.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/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 +54 -35
- 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
|
@@ -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
|
+
};
|