@tiptap/react 2.0.0-beta.20 → 2.0.0-beta.201

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.
Files changed (34) hide show
  1. package/README.md +2 -2
  2. package/dist/packages/react/src/BubbleMenu.d.ts +7 -3
  3. package/dist/packages/react/src/Editor.d.ts +1 -1
  4. package/dist/packages/react/src/EditorContent.d.ts +2 -2
  5. package/dist/packages/react/src/FloatingMenu.d.ts +6 -3
  6. package/dist/packages/react/src/NodeViewContent.d.ts +1 -1
  7. package/dist/packages/react/src/NodeViewWrapper.d.ts +1 -1
  8. package/dist/packages/react/src/ReactNodeViewRenderer.d.ts +12 -6
  9. package/dist/packages/react/src/ReactRenderer.d.ts +12 -9
  10. package/dist/packages/react/src/index.d.ts +6 -6
  11. package/dist/packages/react/src/useEditor.d.ts +2 -1
  12. package/dist/packages/react/src/useReactNodeView.d.ts +1 -0
  13. package/dist/tiptap-react.cjs.js +224 -151
  14. package/dist/tiptap-react.cjs.js.map +1 -1
  15. package/dist/tiptap-react.esm.js +224 -149
  16. package/dist/tiptap-react.esm.js.map +1 -1
  17. package/dist/tiptap-react.umd.js +226 -153
  18. package/dist/tiptap-react.umd.js.map +1 -1
  19. package/package.json +18 -12
  20. package/src/BubbleMenu.tsx +33 -17
  21. package/src/Editor.ts +2 -1
  22. package/src/EditorContent.tsx +9 -7
  23. package/src/FloatingMenu.tsx +37 -14
  24. package/src/NodeViewContent.tsx +10 -3
  25. package/src/NodeViewWrapper.tsx +11 -8
  26. package/src/ReactNodeViewRenderer.tsx +75 -31
  27. package/src/ReactRenderer.tsx +58 -25
  28. package/src/index.ts +6 -6
  29. package/src/useEditor.ts +16 -4
  30. package/src/useReactNodeView.ts +1 -0
  31. package/CHANGELOG.md +0 -178
  32. package/LICENSE.md +0 -21
  33. package/dist/tiptap-react.bundle.umd.min.js +0 -54
  34. package/dist/tiptap-react.bundle.umd.min.js.map +0 -1
@@ -1,6 +1,8 @@
1
+ import { Editor } from '@tiptap/core'
1
2
  import React from 'react'
2
- import { AnyObject } from '@tiptap/core'
3
- import { Editor } from './Editor'
3
+ import { flushSync } from 'react-dom'
4
+
5
+ import { Editor as ExtendedEditor } from './Editor'
4
6
 
5
7
  function isClassComponent(Component: any) {
6
8
  return !!(
@@ -10,34 +12,57 @@ function isClassComponent(Component: any) {
10
12
  )
11
13
  }
12
14
 
15
+ function isForwardRefComponent(Component: any) {
16
+ return !!(
17
+ typeof Component === 'object'
18
+ && Component.$$typeof?.toString() === 'Symbol(react.forward_ref)'
19
+ )
20
+ }
21
+
13
22
  export interface ReactRendererOptions {
14
23
  editor: Editor,
15
- props?: AnyObject,
24
+ props?: Record<string, any>,
16
25
  as?: string,
26
+ className?: string,
17
27
  }
18
28
 
19
- export class ReactRenderer {
29
+ type ComponentType<R, P> =
30
+ React.ComponentClass<P> |
31
+ React.FunctionComponent<P> |
32
+ React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<R>>;
33
+
34
+ export class ReactRenderer<R = unknown, P = unknown> {
20
35
  id: string
21
36
 
22
- editor: Editor
37
+ editor: ExtendedEditor
23
38
 
24
39
  component: any
25
40
 
26
41
  element: Element
27
42
 
28
- props: AnyObject
43
+ props: Record<string, any>
29
44
 
30
45
  reactElement: React.ReactNode
31
46
 
32
- ref: React.Component | null = null
47
+ ref: R | null = null
33
48
 
34
- constructor(component: React.Component | React.FunctionComponent, { editor, props = {}, as = 'div' }: ReactRendererOptions) {
49
+ constructor(component: ComponentType<R, P>, {
50
+ editor,
51
+ props = {},
52
+ as = 'div',
53
+ className = '',
54
+ }: ReactRendererOptions) {
35
55
  this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString()
36
56
  this.component = component
37
- this.editor = editor
57
+ this.editor = editor as ExtendedEditor
38
58
  this.props = props
39
59
  this.element = document.createElement(as)
40
60
  this.element.classList.add('react-renderer')
61
+
62
+ if (className) {
63
+ this.element.classList.add(...className.split(' '))
64
+ }
65
+
41
66
  this.render()
42
67
  }
43
68
 
@@ -45,25 +70,29 @@ export class ReactRenderer {
45
70
  const Component = this.component
46
71
  const props = this.props
47
72
 
48
- if (isClassComponent(Component)) {
49
- props.ref = (ref: React.Component) => {
73
+ if (isClassComponent(Component) || isForwardRefComponent(Component)) {
74
+ props.ref = (ref: R) => {
50
75
  this.ref = ref
51
76
  }
52
77
  }
53
78
 
54
79
  this.reactElement = <Component {...props } />
55
80
 
56
- if (this.editor?.contentComponent) {
57
- this.editor.contentComponent.setState({
58
- renderers: this.editor.contentComponent.state.renderers.set(
59
- this.id,
60
- this,
61
- ),
81
+ queueMicrotask(() => {
82
+ flushSync(() => {
83
+ if (this.editor?.contentComponent) {
84
+ this.editor.contentComponent.setState({
85
+ renderers: this.editor.contentComponent.state.renderers.set(
86
+ this.id,
87
+ this,
88
+ ),
89
+ })
90
+ }
62
91
  })
63
- }
92
+ })
64
93
  }
65
94
 
66
- updateProps(props: AnyObject = {}): void {
95
+ updateProps(props: Record<string, any> = {}): void {
67
96
  this.props = {
68
97
  ...this.props,
69
98
  ...props,
@@ -73,14 +102,18 @@ export class ReactRenderer {
73
102
  }
74
103
 
75
104
  destroy(): void {
76
- if (this.editor?.contentComponent) {
77
- const { renderers } = this.editor.contentComponent.state
105
+ queueMicrotask(() => {
106
+ flushSync(() => {
107
+ if (this.editor?.contentComponent) {
108
+ const { renderers } = this.editor.contentComponent.state
78
109
 
79
- renderers.delete(this.id)
110
+ renderers.delete(this.id)
80
111
 
81
- this.editor.contentComponent.setState({
82
- renderers,
112
+ this.editor.contentComponent.setState({
113
+ renderers,
114
+ })
115
+ }
83
116
  })
84
- }
117
+ })
85
118
  }
86
119
  }
package/src/index.ts CHANGED
@@ -1,10 +1,10 @@
1
- export * from '@tiptap/core'
2
1
  export * from './BubbleMenu'
3
2
  export { Editor } from './Editor'
4
- export * from './FloatingMenu'
5
- export * from './useEditor'
6
- export * from './ReactRenderer'
7
- export * from './ReactNodeViewRenderer'
8
3
  export * from './EditorContent'
9
- export * from './NodeViewWrapper'
4
+ export * from './FloatingMenu'
10
5
  export * from './NodeViewContent'
6
+ export * from './NodeViewWrapper'
7
+ export * from './ReactNodeViewRenderer'
8
+ export * from './ReactRenderer'
9
+ export * from './useEditor'
10
+ export * from '@tiptap/core'
package/src/useEditor.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { useState, useEffect } from 'react'
2
1
  import { EditorOptions } from '@tiptap/core'
2
+ import { DependencyList, useEffect, useState } from 'react'
3
+
3
4
  import { Editor } from './Editor'
4
5
 
5
6
  function useForceUpdate() {
@@ -8,21 +9,32 @@ function useForceUpdate() {
8
9
  return () => setValue(value => value + 1)
9
10
  }
10
11
 
11
- export const useEditor = (options: Partial<EditorOptions> = {}) => {
12
+ export const useEditor = (options: Partial<EditorOptions> = {}, deps: DependencyList = []) => {
12
13
  const [editor, setEditor] = useState<Editor | null>(null)
13
14
  const forceUpdate = useForceUpdate()
14
15
 
15
16
  useEffect(() => {
17
+ let isMounted = true
18
+
16
19
  const instance = new Editor(options)
17
20
 
18
21
  setEditor(instance)
19
22
 
20
- instance.on('transaction', forceUpdate)
23
+ instance.on('transaction', () => {
24
+ requestAnimationFrame(() => {
25
+ requestAnimationFrame(() => {
26
+ if (isMounted) {
27
+ forceUpdate()
28
+ }
29
+ })
30
+ })
31
+ })
21
32
 
22
33
  return () => {
23
34
  instance.destroy()
35
+ isMounted = false
24
36
  }
25
- }, [])
37
+ }, deps)
26
38
 
27
39
  return editor
28
40
  }
@@ -2,6 +2,7 @@ import { createContext, useContext } from 'react'
2
2
 
3
3
  export interface ReactNodeViewContextProps {
4
4
  onDragStart: (event: DragEvent) => void,
5
+ nodeViewContentRef: (element: HTMLElement | null) => void,
5
6
  }
6
7
 
7
8
  export const ReactNodeViewContext = createContext<Partial<ReactNodeViewContextProps>>({
package/CHANGELOG.md DELETED
@@ -1,178 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [2.0.0-beta.20](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.19...@tiptap/react@2.0.0-beta.20) (2021-04-15)
7
-
8
- **Note:** Version bump only for package @tiptap/react
9
-
10
-
11
-
12
-
13
-
14
- # [2.0.0-beta.19](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.18...@tiptap/react@2.0.0-beta.19) (2021-04-11)
15
-
16
-
17
- ### Bug Fixes
18
-
19
- * fix using react node views with insertContent ([ea0992f](https://github.com/ueberdosis/tiptap-next/commit/ea0992f66e9942c590e75c0ab2f5705640764f4d))
20
-
21
-
22
-
23
-
24
-
25
- # [2.0.0-beta.18](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.17...@tiptap/react@2.0.0-beta.18) (2021-04-08)
26
-
27
- **Note:** Version bump only for package @tiptap/react
28
-
29
-
30
-
31
-
32
-
33
- # [2.0.0-beta.17](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.16...@tiptap/react@2.0.0-beta.17) (2021-04-08)
34
-
35
-
36
- ### Bug Fixes
37
-
38
- * improve node view error message ([536663f](https://github.com/ueberdosis/tiptap-next/commit/536663f816039df6e3d8de23989f343d78e5d08e))
39
- * make `as` prop optional ([f8dec5f](https://github.com/ueberdosis/tiptap-next/commit/f8dec5f905baf5692dd257b3dddec3de2bcad1a1))
40
-
41
-
42
-
43
-
44
-
45
- # [2.0.0-beta.16](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.15...@tiptap/react@2.0.0-beta.16) (2021-04-07)
46
-
47
- **Note:** Version bump only for package @tiptap/react
48
-
49
-
50
-
51
-
52
-
53
- # [2.0.0-beta.15](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.14...@tiptap/react@2.0.0-beta.15) (2021-04-07)
54
-
55
- **Note:** Version bump only for package @tiptap/react
56
-
57
-
58
-
59
-
60
-
61
- # [2.0.0-beta.14](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.13...@tiptap/react@2.0.0-beta.14) (2021-04-04)
62
-
63
-
64
- ### Features
65
-
66
- * render wrapper element for inline node views as span, fix [#242](https://github.com/ueberdosis/tiptap-next/issues/242) ([bdb5d72](https://github.com/ueberdosis/tiptap-next/commit/bdb5d724956c0c757e29be38fb2c9dd85d8fd36b))
67
-
68
-
69
-
70
-
71
-
72
- # [2.0.0-beta.13](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.12...@tiptap/react@2.0.0-beta.13) (2021-04-01)
73
-
74
- **Note:** Version bump only for package @tiptap/react
75
-
76
-
77
-
78
-
79
-
80
- # [2.0.0-beta.12](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.11...@tiptap/react@2.0.0-beta.12) (2021-04-01)
81
-
82
- **Note:** Version bump only for package @tiptap/react
83
-
84
-
85
-
86
-
87
-
88
- # [2.0.0-beta.11](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.10...@tiptap/react@2.0.0-beta.11) (2021-04-01)
89
-
90
- **Note:** Version bump only for package @tiptap/react
91
-
92
-
93
-
94
-
95
-
96
- # [2.0.0-beta.10](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.9...@tiptap/react@2.0.0-beta.10) (2021-04-01)
97
-
98
- **Note:** Version bump only for package @tiptap/react
99
-
100
-
101
-
102
-
103
-
104
- # [2.0.0-beta.9](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.8...@tiptap/react@2.0.0-beta.9) (2021-03-31)
105
-
106
- **Note:** Version bump only for package @tiptap/react
107
-
108
-
109
-
110
-
111
-
112
- # [2.0.0-beta.8](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.7...@tiptap/react@2.0.0-beta.8) (2021-03-31)
113
-
114
- **Note:** Version bump only for package @tiptap/react
115
-
116
-
117
-
118
-
119
-
120
- # [2.0.0-beta.7](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.6...@tiptap/react@2.0.0-beta.7) (2021-03-31)
121
-
122
- **Note:** Version bump only for package @tiptap/react
123
-
124
-
125
-
126
-
127
-
128
- # [2.0.0-beta.6](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.5...@tiptap/react@2.0.0-beta.6) (2021-03-28)
129
-
130
- **Note:** Version bump only for package @tiptap/react
131
-
132
-
133
-
134
-
135
-
136
- # [2.0.0-beta.5](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.4...@tiptap/react@2.0.0-beta.5) (2021-03-24)
137
-
138
- **Note:** Version bump only for package @tiptap/react
139
-
140
-
141
-
142
-
143
-
144
- # [2.0.0-beta.4](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.3...@tiptap/react@2.0.0-beta.4) (2021-03-18)
145
-
146
- **Note:** Version bump only for package @tiptap/react
147
-
148
-
149
-
150
-
151
-
152
- # [2.0.0-beta.3](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.2...@tiptap/react@2.0.0-beta.3) (2021-03-16)
153
-
154
- **Note:** Version bump only for package @tiptap/react
155
-
156
-
157
-
158
-
159
-
160
- # [2.0.0-beta.2](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-beta.1...@tiptap/react@2.0.0-beta.2) (2021-03-09)
161
-
162
- **Note:** Version bump only for package @tiptap/react
163
-
164
-
165
-
166
-
167
-
168
- # [2.0.0-beta.1](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/react@2.0.0-alpha.2...@tiptap/react@2.0.0-beta.1) (2021-03-05)
169
-
170
- **Note:** Version bump only for package @tiptap/react
171
-
172
-
173
-
174
-
175
-
176
- # 2.0.0-alpha.2 (2021-02-26)
177
-
178
- **Note:** Version bump only for package @tiptap/react
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020, überdosis GbR
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.