@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.
@@ -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 !== null) {
52
- var instance = createRichTextEditor.createRichTextEditor({
53
- node: node,
54
- initialEditorState: editorState,
55
- onChange: setEditorState,
56
- isEditable: function () {
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, useEffect } from 'react';
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 !== null) {
50
- var instance = createRichTextEditor({
51
- node: node,
52
- initialEditorState: editorState,
53
- onChange: setEditorState,
54
- isEditable: function () {
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" : "Text formatting"
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaizen/components",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "Kaizen component library",
5
5
  "author": "Geoffrey Chong <geoff.chong@cultureamp.com>",
6
6
  "homepage": "https://cultureamp.design",
@@ -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, useEffect, useRef, useState } from 'react'
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 !== null) {
75
- const instance = createRichTextEditor({
76
- node,
77
- initialEditorState: editorState,
78
- onChange: setEditorState,
79
- isEditable: () => editableStatusRef.current,
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
  }