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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 It can be easy
3
+ Copyright (c) 2026 Jodit WYSIWYG Editor
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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
- const editor = useRef(null);
46
- const [content, setContent] = useState('');
47
-
48
- const config = useMemo(() => ({
49
- readonly: false, // all options from https://xdsoft.net/jodit/docs/,
50
- placeholder: placeholder || 'Start typings...'
51
- }),
52
- [placeholder]
53
- );
54
-
55
- return (
56
- <JoditEditor
57
- ref={editor}
58
- value={content}
59
- config={config}
60
- tabIndex={1} // tabIndex of textarea
61
- onBlur={newContent => setContent(newContent)} // preferred to use only this option to update the content for performance reasons
62
- onChange={newContent => {}}
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
- jodit.e.on(
80
- 'paste',
81
- e => {
82
- if (confirm('Change pasted content?')) {
83
- jodit.e.stopPropagation('paste');
84
- jodit.s.insertHTML(
85
- Jodit.modules.Helpers.getDataTransfer(e)
86
- .getData(Jodit.constants.TEXT_HTML)
87
- .replace(/a/g, 'b')
88
- );
89
- return false;
90
- }
91
- },
92
- { top: true }
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
+ };