jodit-react 5.0.7 → 5.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jodit-react",
3
- "version": "5.0.7",
3
+ "version": "5.0.9",
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/)",
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useRef, forwardRef, useLayoutEffect } from 'react';
1
+ import React, { useEffect, useRef, forwardRef } from 'react';
2
2
  import type { IJodit } from 'jodit/types/types/jodit';
3
3
  import type { Jodit as JoditBaseConstructor } from 'jodit/types/index';
4
4
  import type { Config as BaseConfig } from 'jodit/config';
@@ -46,16 +46,6 @@ const JoditEditor = forwardRef<IJodit, Props>(
46
46
  const textAreaRef = useRef<HTMLTextAreaElement | null>(null);
47
47
  const joditRef = useRef<IJodit | null>(null);
48
48
 
49
- useLayoutEffect(() => {
50
- if (ref) {
51
- if (typeof ref === 'function') {
52
- ref(joditRef.current);
53
- } else {
54
- ref.current = joditRef.current;
55
- }
56
- }
57
- }, [textAreaRef, ref]);
58
-
59
49
  useEffect(() => {
60
50
  const element = textAreaRef.current!;
61
51
  const jodit = JoditConstructor.make(element, config);
@@ -76,6 +66,16 @@ const JoditEditor = forwardRef<IJodit, Props>(
76
66
  };
77
67
  }, [JoditConstructor, config, editorRef]);
78
68
 
69
+ useEffect(() => {
70
+ if (ref) {
71
+ if (typeof ref === 'function') {
72
+ ref(joditRef.current);
73
+ } else {
74
+ ref.current = joditRef.current;
75
+ }
76
+ }
77
+ }, [textAreaRef, ref, joditRef]);
78
+
79
79
  const preClassName = usePrevious(className ?? '');
80
80
 
81
81
  useEffect(() => {
@@ -0,0 +1,46 @@
1
+ import React from 'react';
2
+ import { describe, it } from '@jest/globals';
3
+ import { render, act } from '@testing-library/react';
4
+ import '@testing-library/jest-dom';
5
+ import JoditEditor from '../src';
6
+ import type { IJodit } from 'jodit/types/types/jodit';
7
+
8
+ describe('Ref Test', () => {
9
+ describe('Ref as function', () => {
10
+ it('should be instance of imperative Jodit', () => {
11
+ const ref = React.createRef<IJodit>();
12
+
13
+ const App = () => (
14
+ <JoditEditor
15
+ ref={newRef => {
16
+ ref.current = newRef;
17
+ }}
18
+ />
19
+ );
20
+
21
+ const elm = render(<App />);
22
+
23
+ act(() => {
24
+ elm.rerender(<App />);
25
+ });
26
+
27
+ expect(ref.current?.isJodit).toBe(true);
28
+ });
29
+ });
30
+
31
+ describe('Ref as object', () => {
32
+ it('should be instance of imperative Jodit', () => {
33
+ const ref = React.createRef<IJodit>();
34
+
35
+ const App = () => <JoditEditor ref={ref} />;
36
+
37
+ const elm = render(<App />);
38
+
39
+ act(() => {
40
+ elm.rerender(<App />);
41
+ });
42
+
43
+ expect(ref.current?.isJodit).toBe(true);
44
+ });
45
+ });
46
+ });
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { describe, it } from '@jest/globals';
3
+ import { render } from '@testing-library/react';
4
+ import '@testing-library/jest-dom';
5
+ import JoditEditor from '../src';
6
+
7
+ describe('Theme Test', () => {
8
+ it('should render with theme classname', () => {
9
+ const { container } = render(
10
+ <JoditEditor config={{ theme: 'summer' }} />
11
+ );
12
+ expect(
13
+ container
14
+ .querySelector('.jodit-container')!
15
+ .classList.contains('jodit_theme_summer')
16
+ ).toBe(true);
17
+ });
18
+ });