@kaizen/components 2.0.6 → 2.0.7
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/dist/cjs/src/RichTextEditor/utils/core/hooks/useRichTextEditor.cjs +17 -20
- package/dist/esm/src/RichTextEditor/utils/core/hooks/useRichTextEditor.mjs +18 -21
- package/locales/nl.json +1 -1
- package/package.json +1 -1
- package/src/RichTextEditor/utils/core/hooks/useRichTextEditor.spec.tsx +11 -0
- package/src/RichTextEditor/utils/core/hooks/useRichTextEditor.ts +17 -21
|
@@ -48,33 +48,30 @@ attributes, options) {
|
|
|
48
48
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
49
49
|
[editableStatusRef]);
|
|
50
50
|
var editorRef = React.useCallback(function (node) {
|
|
51
|
-
if (node
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return editableStatusRef.current;
|
|
58
|
-
},
|
|
59
|
-
attributes: attributes
|
|
60
|
-
});
|
|
61
|
-
destroyEditorRef.current = instance.destroy;
|
|
62
|
-
dispatchTransactionRef.current = instance.dispatchTransaction;
|
|
51
|
+
if (node === null) {
|
|
52
|
+
if (destroyEditorRef.current) {
|
|
53
|
+
destroyEditorRef.current();
|
|
54
|
+
destroyEditorRef.current = undefined;
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
63
57
|
}
|
|
58
|
+
var instance = createRichTextEditor.createRichTextEditor({
|
|
59
|
+
node: node,
|
|
60
|
+
initialEditorState: editorState,
|
|
61
|
+
onChange: setEditorState,
|
|
62
|
+
isEditable: function () {
|
|
63
|
+
return editableStatusRef.current;
|
|
64
|
+
},
|
|
65
|
+
attributes: attributes
|
|
66
|
+
});
|
|
67
|
+
destroyEditorRef.current = instance.destroy;
|
|
68
|
+
dispatchTransactionRef.current = instance.dispatchTransaction;
|
|
64
69
|
},
|
|
65
70
|
// Including editorState in the dependencies here will cause an endless
|
|
66
71
|
// loop as the initialization changes its value
|
|
67
72
|
// @todo: Fix if possible - avoiding breaking in eslint upgrade
|
|
68
73
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
69
74
|
[setEditorState, editableStatusRef]);
|
|
70
|
-
// Tear down ProseMirror when the consuming component is unmounted
|
|
71
|
-
React.useEffect(function () {
|
|
72
|
-
return function () {
|
|
73
|
-
if (destroyEditorRef.current) {
|
|
74
|
-
destroyEditorRef.current();
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}, [destroyEditorRef]);
|
|
78
75
|
return [editorRef, editorState, dispatchTransaction, setEditableStatus];
|
|
79
76
|
};
|
|
80
77
|
exports.useRichTextEditor = useRichTextEditor;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __assign } from 'tslib';
|
|
2
|
-
import { useState, useRef, useCallback
|
|
2
|
+
import { useState, useRef, useCallback } from 'react';
|
|
3
3
|
import { createRichTextEditor } from '../createRichTextEditor.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -46,33 +46,30 @@ attributes, options) {
|
|
|
46
46
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
47
47
|
[editableStatusRef]);
|
|
48
48
|
var editorRef = useCallback(function (node) {
|
|
49
|
-
if (node
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return editableStatusRef.current;
|
|
56
|
-
},
|
|
57
|
-
attributes: attributes
|
|
58
|
-
});
|
|
59
|
-
destroyEditorRef.current = instance.destroy;
|
|
60
|
-
dispatchTransactionRef.current = instance.dispatchTransaction;
|
|
49
|
+
if (node === null) {
|
|
50
|
+
if (destroyEditorRef.current) {
|
|
51
|
+
destroyEditorRef.current();
|
|
52
|
+
destroyEditorRef.current = undefined;
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
61
55
|
}
|
|
56
|
+
var instance = createRichTextEditor({
|
|
57
|
+
node: node,
|
|
58
|
+
initialEditorState: editorState,
|
|
59
|
+
onChange: setEditorState,
|
|
60
|
+
isEditable: function () {
|
|
61
|
+
return editableStatusRef.current;
|
|
62
|
+
},
|
|
63
|
+
attributes: attributes
|
|
64
|
+
});
|
|
65
|
+
destroyEditorRef.current = instance.destroy;
|
|
66
|
+
dispatchTransactionRef.current = instance.dispatchTransaction;
|
|
62
67
|
},
|
|
63
68
|
// Including editorState in the dependencies here will cause an endless
|
|
64
69
|
// loop as the initialization changes its value
|
|
65
70
|
// @todo: Fix if possible - avoiding breaking in eslint upgrade
|
|
66
71
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
67
72
|
[setEditorState, editableStatusRef]);
|
|
68
|
-
// Tear down ProseMirror when the consuming component is unmounted
|
|
69
|
-
useEffect(function () {
|
|
70
|
-
return function () {
|
|
71
|
-
if (destroyEditorRef.current) {
|
|
72
|
-
destroyEditorRef.current();
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}, [destroyEditorRef]);
|
|
76
73
|
return [editorRef, editorState, dispatchTransaction, setEditableStatus];
|
|
77
74
|
};
|
|
78
75
|
export { useRichTextEditor };
|
package/locales/nl.json
CHANGED
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
},
|
|
116
116
|
"kz.rte.toolbar.aria_label" : {
|
|
117
117
|
"description" : "Label for the text formatting toolbar in a Rich Text Editor",
|
|
118
|
-
"message" : "
|
|
118
|
+
"message" : "Tekstopmaak"
|
|
119
119
|
},
|
|
120
120
|
"kz.rte.underline" : {
|
|
121
121
|
"description" : "Label for the \"Underline\" button in a text editor",
|
package/package.json
CHANGED
|
@@ -150,4 +150,15 @@ describe('useRichTextEditor()', () => {
|
|
|
150
150
|
expect(editor.children[0]).toHaveAttribute('contenteditable', 'true')
|
|
151
151
|
})
|
|
152
152
|
})
|
|
153
|
+
|
|
154
|
+
it('is removed from DOM when unmounted', async () => {
|
|
155
|
+
const { unmount } = render(<Scenario />)
|
|
156
|
+
|
|
157
|
+
const editor = screen.getByTestId('testid--editor')
|
|
158
|
+
expect(editor).toBeInTheDocument()
|
|
159
|
+
|
|
160
|
+
unmount()
|
|
161
|
+
|
|
162
|
+
expect(screen.queryByTestId('testid--editor')).not.toBeInTheDocument()
|
|
163
|
+
})
|
|
153
164
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback,
|
|
1
|
+
import { useCallback, useRef, useState } from 'react'
|
|
2
2
|
import { type EditorState } from 'prosemirror-state'
|
|
3
3
|
import { createRichTextEditor } from '../createRichTextEditor'
|
|
4
4
|
import { type CommandOrTransaction } from '../types'
|
|
@@ -71,17 +71,23 @@ export const useRichTextEditor = (
|
|
|
71
71
|
|
|
72
72
|
const editorRef = useCallback(
|
|
73
73
|
(node: HTMLElement) => {
|
|
74
|
-
if (node
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
attributes,
|
|
81
|
-
})
|
|
82
|
-
destroyEditorRef.current = instance.destroy
|
|
83
|
-
dispatchTransactionRef.current = instance.dispatchTransaction
|
|
74
|
+
if (node === null) {
|
|
75
|
+
if (destroyEditorRef.current) {
|
|
76
|
+
destroyEditorRef.current()
|
|
77
|
+
destroyEditorRef.current = undefined
|
|
78
|
+
}
|
|
79
|
+
return
|
|
84
80
|
}
|
|
81
|
+
|
|
82
|
+
const instance = createRichTextEditor({
|
|
83
|
+
node,
|
|
84
|
+
initialEditorState: editorState,
|
|
85
|
+
onChange: setEditorState,
|
|
86
|
+
isEditable: () => editableStatusRef.current,
|
|
87
|
+
attributes,
|
|
88
|
+
})
|
|
89
|
+
destroyEditorRef.current = instance.destroy
|
|
90
|
+
dispatchTransactionRef.current = instance.dispatchTransaction
|
|
85
91
|
},
|
|
86
92
|
|
|
87
93
|
// Including editorState in the dependencies here will cause an endless
|
|
@@ -91,15 +97,5 @@ export const useRichTextEditor = (
|
|
|
91
97
|
[setEditorState, editableStatusRef],
|
|
92
98
|
)
|
|
93
99
|
|
|
94
|
-
// Tear down ProseMirror when the consuming component is unmounted
|
|
95
|
-
useEffect(
|
|
96
|
-
() => () => {
|
|
97
|
-
if (destroyEditorRef.current) {
|
|
98
|
-
destroyEditorRef.current()
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
[destroyEditorRef],
|
|
102
|
-
)
|
|
103
|
-
|
|
104
100
|
return [editorRef, editorState, dispatchTransaction, setEditableStatus]
|
|
105
101
|
}
|