@handlewithcare/react-prosemirror 3.1.0-tiptap.42 → 3.1.0-tiptap.44

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 (143) hide show
  1. package/README.md +26 -0
  2. package/dist/cjs/ReactEditorView.js +74 -70
  3. package/dist/cjs/StaticEditorView.js +21 -18
  4. package/dist/cjs/browser.js +3 -1
  5. package/dist/cjs/commands/reorderSiblings.js +13 -9
  6. package/dist/cjs/components/ChildNodeViews.js +74 -69
  7. package/dist/cjs/components/CursorWrapper.js +20 -34
  8. package/dist/cjs/components/LayoutGroup.js +16 -12
  9. package/dist/cjs/components/NativeWidgetView.js +19 -15
  10. package/dist/cjs/components/OutputSpec.js +13 -9
  11. package/dist/cjs/components/ProseMirror.js +27 -37
  12. package/dist/cjs/components/ProseMirrorDoc.js +18 -25
  13. package/dist/cjs/components/SeparatorHackView.js +20 -17
  14. package/dist/cjs/components/TextNodeView.js +20 -22
  15. package/dist/cjs/components/TrailingHackView.js +17 -13
  16. package/dist/cjs/components/WidgetView.js +18 -14
  17. package/dist/cjs/components/marks/DefaultMarkView.js +15 -27
  18. package/dist/cjs/components/marks/MarkView.js +23 -32
  19. package/dist/cjs/components/marks/MarkViewConstructorView.js +22 -38
  20. package/dist/cjs/components/marks/ReactMarkView.js +16 -27
  21. package/dist/cjs/components/nodes/DefaultNodeView.js +15 -27
  22. package/dist/cjs/components/nodes/DocNodeView.js +16 -12
  23. package/dist/cjs/components/nodes/NodeView.js +26 -33
  24. package/dist/cjs/components/nodes/NodeViewConstructorView.js +29 -45
  25. package/dist/cjs/components/nodes/ReactNodeView.js +27 -39
  26. package/dist/cjs/constants.js +10 -6
  27. package/dist/cjs/contexts/ChildDescriptionsContext.js +3 -1
  28. package/dist/cjs/contexts/EditorContext.js +3 -1
  29. package/dist/cjs/contexts/EditorStateContext.js +3 -1
  30. package/dist/cjs/contexts/IgnoreMutationContext.js +3 -1
  31. package/dist/cjs/contexts/LayoutGroupContext.js +3 -1
  32. package/dist/cjs/contexts/NodeViewContext.js +3 -1
  33. package/dist/cjs/contexts/SelectNodeContext.js +3 -1
  34. package/dist/cjs/contexts/StopEventContext.js +3 -1
  35. package/dist/cjs/decorations/ReactWidgetType.js +19 -13
  36. package/dist/cjs/decorations/computeDocDeco.js +5 -3
  37. package/dist/cjs/decorations/iterDeco.js +19 -17
  38. package/dist/cjs/decorations/viewDecorations.js +15 -12
  39. package/dist/cjs/dom.js +34 -13
  40. package/dist/cjs/findDOMNode.js +9 -5
  41. package/dist/cjs/hooks/useClientLayoutEffect.js +3 -1
  42. package/dist/cjs/hooks/useComponentEventListeners.js +7 -6
  43. package/dist/cjs/hooks/useEditor.js +29 -32
  44. package/dist/cjs/hooks/useEditorEffect.js +9 -7
  45. package/dist/cjs/hooks/useEditorEventCallback.js +9 -7
  46. package/dist/cjs/hooks/useEditorEventListener.js +8 -6
  47. package/dist/cjs/hooks/useEditorState.js +5 -3
  48. package/dist/cjs/hooks/useEffectEvent.js +3 -1
  49. package/dist/cjs/hooks/useForceUpdate.js +3 -1
  50. package/dist/cjs/hooks/useIgnoreMutation.js +9 -7
  51. package/dist/cjs/hooks/useIsEditorStatic.js +5 -5
  52. package/dist/cjs/hooks/useIsNodeSelected.js +5 -3
  53. package/dist/cjs/hooks/useLayoutGroupEffect.js +7 -5
  54. package/dist/cjs/hooks/useMarkViewDescription.js +31 -25
  55. package/dist/cjs/hooks/useNodePos.js +7 -5
  56. package/dist/cjs/hooks/useNodeViewDescription.js +32 -28
  57. package/dist/cjs/hooks/useReactKeys.js +7 -5
  58. package/dist/cjs/hooks/useSelectNode.js +10 -8
  59. package/dist/cjs/hooks/useStopEvent.js +9 -7
  60. package/dist/cjs/index.js +66 -34
  61. package/dist/cjs/plugins/beforeInputPlugin.js +51 -24
  62. package/dist/cjs/plugins/componentEventListeners.js +8 -6
  63. package/dist/cjs/plugins/componentEventListenersPlugin.js +8 -6
  64. package/dist/cjs/plugins/reactKeys.js +15 -10
  65. package/dist/cjs/props.js +23 -19
  66. package/dist/cjs/refs.js +3 -1
  67. package/dist/cjs/testing/editorViewTestHelpers.js +40 -47
  68. package/dist/cjs/testing/setupProseMirrorView.js +7 -4
  69. package/dist/cjs/tiptap/ReactProseMirrorNodeView.js +10 -6
  70. package/dist/cjs/tiptap/TiptapEditor.js +15 -14
  71. package/dist/cjs/tiptap/TiptapEditorContent.js +18 -28
  72. package/dist/cjs/tiptap/TiptapEditorView.js +23 -34
  73. package/dist/cjs/tiptap/contexts/TiptapEditorContext.js +3 -1
  74. package/dist/cjs/tiptap/extensions/ReactProseMirror.js +8 -6
  75. package/dist/cjs/tiptap/extensions/ReactProseMirrorCommands.js +5 -3
  76. package/dist/cjs/tiptap/extensions/commands/updateAttributes.js +4 -2
  77. package/dist/cjs/tiptap/hooks/useIsInReactProseMirror.js +5 -3
  78. package/dist/cjs/tiptap/hooks/useTiptapEditor.js +12 -14
  79. package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +12 -10
  80. package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +6 -4
  81. package/dist/cjs/tiptap/index.js +36 -18
  82. package/dist/cjs/tiptap/tiptapNodeView.js +48 -62
  83. package/dist/cjs/viewdesc.js +119 -89
  84. package/dist/esm/ReactEditorView.js +68 -66
  85. package/dist/esm/StaticEditorView.js +18 -17
  86. package/dist/esm/commands/reorderSiblings.js +5 -5
  87. package/dist/esm/components/ChildNodeViews.js +36 -37
  88. package/dist/esm/components/CursorWrapper.js +10 -28
  89. package/dist/esm/components/LayoutGroup.js +1 -1
  90. package/dist/esm/components/NativeWidgetView.js +2 -2
  91. package/dist/esm/components/OutputSpec.js +1 -1
  92. package/dist/esm/components/ProseMirror.js +4 -18
  93. package/dist/esm/components/ProseMirrorDoc.js +6 -19
  94. package/dist/esm/components/SeparatorHackView.js +3 -4
  95. package/dist/esm/components/TextNodeView.js +6 -10
  96. package/dist/esm/components/TrailingHackView.js +2 -2
  97. package/dist/esm/components/WidgetView.js +3 -3
  98. package/dist/esm/components/marks/DefaultMarkView.js +6 -22
  99. package/dist/esm/components/marks/MarkView.js +11 -24
  100. package/dist/esm/components/marks/MarkViewConstructorView.js +7 -27
  101. package/dist/esm/components/marks/ReactMarkView.js +3 -18
  102. package/dist/esm/components/nodes/DefaultNodeView.js +6 -22
  103. package/dist/esm/components/nodes/DocNodeView.js +2 -2
  104. package/dist/esm/components/nodes/NodeView.js +11 -24
  105. package/dist/esm/components/nodes/NodeViewConstructorView.js +11 -31
  106. package/dist/esm/components/nodes/ReactNodeView.js +6 -22
  107. package/dist/esm/decorations/ReactWidgetType.js +10 -8
  108. package/dist/esm/decorations/iterDeco.js +13 -13
  109. package/dist/esm/decorations/viewDecorations.js +7 -6
  110. package/dist/esm/dom.js +1 -2
  111. package/dist/esm/findDOMNode.js +1 -1
  112. package/dist/esm/hooks/useComponentEventListeners.js +2 -3
  113. package/dist/esm/hooks/useEditor.js +6 -11
  114. package/dist/esm/hooks/useEditorEffect.js +1 -1
  115. package/dist/esm/hooks/useEditorEventCallback.js +1 -1
  116. package/dist/esm/hooks/useEditorEventListener.js +1 -1
  117. package/dist/esm/hooks/useIsEditorStatic.js +1 -3
  118. package/dist/esm/hooks/useMarkViewDescription.js +14 -10
  119. package/dist/esm/hooks/useNodeViewDescription.js +10 -8
  120. package/dist/esm/hooks/useReactKeys.js +1 -1
  121. package/dist/esm/plugins/beforeInputPlugin.js +44 -19
  122. package/dist/esm/plugins/reactKeys.js +3 -4
  123. package/dist/esm/props.js +15 -15
  124. package/dist/esm/testing/editorViewTestHelpers.js +20 -31
  125. package/dist/esm/testing/setupProseMirrorView.js +1 -2
  126. package/dist/esm/tiptap/ReactProseMirrorNodeView.js +7 -5
  127. package/dist/esm/tiptap/TiptapEditor.js +9 -10
  128. package/dist/esm/tiptap/TiptapEditorContent.js +4 -18
  129. package/dist/esm/tiptap/TiptapEditorView.js +8 -23
  130. package/dist/esm/tiptap/extensions/ReactProseMirror.js +1 -1
  131. package/dist/esm/tiptap/extensions/commands/updateAttributes.js +1 -1
  132. package/dist/esm/tiptap/hooks/useTiptapEditor.js +4 -8
  133. package/dist/esm/tiptap/hooks/useTiptapEditorEffect.js +4 -4
  134. package/dist/esm/tiptap/hooks/useTiptapEditorEventCallback.js +1 -1
  135. package/dist/esm/tiptap/tiptapNodeView.js +20 -38
  136. package/dist/esm/viewdesc.js +74 -66
  137. package/dist/tsconfig.tsbuildinfo +1 -1
  138. package/dist/types/constants.d.ts +1 -1
  139. package/dist/types/contexts/EditorContext.d.ts +1 -2
  140. package/dist/types/hooks/useEditor.d.ts +1 -1
  141. package/dist/types/props.d.ts +8 -8
  142. package/dist/types/testing/editorViewTestHelpers.d.ts +1 -0
  143. package/package.json +1 -2
@@ -1,18 +1,4 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */ function _extends() {
2
- _extends = Object.assign || function(target) {
3
- for(var i = 1; i < arguments.length; i++){
4
- var source = arguments[i];
5
- for(var key in source){
6
- if (Object.prototype.hasOwnProperty.call(source, key)) {
7
- target[key] = source[key];
8
- }
9
- }
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
15
- import { render } from "@testing-library/react";
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */ import { render } from "@testing-library/react";
16
2
  import { expect } from "expect";
17
3
  import { Node } from "prosemirror-model";
18
4
  import { EditorState, TextSelection } from "prosemirror-state";
@@ -29,7 +15,7 @@ const toEqualNode = function(actual, expected) {
29
15
  const pass = eq(actual, expected);
30
16
  return {
31
17
  message: ()=>// `this` context will have correct typings
32
- "expected ".concat(this.utils.printReceived(actual), " ").concat(pass ? "not " : "", "to equal ").concat(this.utils.printExpected(expected)),
18
+ `expected ${this.utils.printReceived(actual)} ${pass ? "not " : ""}to equal ${this.utils.printExpected(expected)}`,
33
19
  pass
34
20
  };
35
21
  };
@@ -37,15 +23,14 @@ expect.extend({
37
23
  toEqualNode
38
24
  });
39
25
  export function tempEditor(param) {
40
- let { doc: startDoc , selection , controlled , plugins , ...props } = param;
41
- var ref, ref1;
42
- startDoc = startDoc !== null && startDoc !== void 0 ? startDoc : doc(p());
26
+ let { doc: startDoc, selection, controlled, plugins, ...props } = param;
27
+ startDoc = startDoc ?? doc(p());
43
28
  const state = EditorState.create({
44
29
  doc: startDoc,
45
30
  schema,
46
- selection: (selection !== null && selection !== void 0 ? selection : (ref = startDoc.tag) === null || ref === void 0 ? void 0 : ref.a) ? TextSelection.create(startDoc, startDoc.tag.a, (ref1 = startDoc.tag) === null || ref1 === void 0 ? void 0 : ref1.b) : undefined,
31
+ selection: selection ?? (startDoc.tag?.a ? TextSelection.create(startDoc, startDoc.tag.a, startDoc.tag?.b) : undefined),
47
32
  plugins: [
48
- ...plugins !== null && plugins !== void 0 ? plugins : [],
33
+ ...plugins ?? [],
49
34
  reactKeys()
50
35
  ]
51
36
  });
@@ -56,21 +41,25 @@ export function tempEditor(param) {
56
41
  });
57
42
  return null;
58
43
  }
59
- const { rerender , unmount } = render(/*#__PURE__*/ React.createElement(ProseMirror, _extends({}, controlled ? {
60
- state
61
- } : {
62
- defaultState: state
63
- }, props), /*#__PURE__*/ React.createElement(Test, null), /*#__PURE__*/ React.createElement(ProseMirrorDoc, null)));
64
- function rerenderEditor() {
65
- let { ...newProps } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
66
- rerender(/*#__PURE__*/ React.createElement(ProseMirror, _extends({}, controlled ? {
44
+ const { rerender, unmount } = render(/*#__PURE__*/ React.createElement(ProseMirror, {
45
+ ...controlled ? {
67
46
  state
68
47
  } : {
69
48
  defaultState: state
70
- }, {
49
+ },
50
+ ...props
51
+ }, /*#__PURE__*/ React.createElement(Test, null), /*#__PURE__*/ React.createElement(ProseMirrorDoc, null)));
52
+ function rerenderEditor() {
53
+ let { ...newProps } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
54
+ rerender(/*#__PURE__*/ React.createElement(ProseMirror, {
55
+ ...controlled ? {
56
+ state
57
+ } : {
58
+ defaultState: state
59
+ },
71
60
  ...props,
72
61
  ...newProps
73
- }), /*#__PURE__*/ React.createElement(Test, null), /*#__PURE__*/ React.createElement(ProseMirrorDoc, null)));
62
+ }, /*#__PURE__*/ React.createElement(Test, null), /*#__PURE__*/ React.createElement(ProseMirrorDoc, null)));
74
63
  return view;
75
64
  }
76
65
  return {
@@ -53,8 +53,7 @@ const mockGetClientRects = ()=>{
53
53
  ];
54
54
  const domRectList = Object.assign(list, {
55
55
  item (index) {
56
- var _index;
57
- return (_index = list[index]) !== null && _index !== void 0 ? _index : null;
56
+ return list[index] ?? null;
58
57
  }
59
58
  });
60
59
  return domRectList;
@@ -6,15 +6,17 @@ import { NodeView } from "@tiptap/core";
6
6
  * ViewDesc, so that we can call Tiptap's default stopEvent and ignoreMutation
7
7
  * methods
8
8
  */ export class ReactProseMirrorNodeView extends NodeView {
9
+ _dom;
10
+ _contentDOM;
11
+ constructor(component, props, dom, contentDOM, options){
12
+ super(component, props, options);
13
+ this._dom = dom;
14
+ this._contentDOM = contentDOM;
15
+ }
9
16
  get dom() {
10
17
  return this._dom;
11
18
  }
12
19
  get contentDOM() {
13
20
  return this._contentDOM;
14
21
  }
15
- constructor(component, props, dom, contentDOM, options){
16
- super(component, props, options);
17
- this._dom = dom;
18
- this._contentDOM = contentDOM;
19
- }
20
22
  }
@@ -2,10 +2,15 @@ import { Editor } from "@tiptap/core";
2
2
  import { EditorState } from "prosemirror-state";
3
3
  import { StaticEditorView } from "../StaticEditorView.js";
4
4
  export class TiptapEditor extends Editor {
5
+ constructor(options = {}){
6
+ super({
7
+ ...options,
8
+ element: null
9
+ });
10
+ }
5
11
  get view() {
6
- var // @ts-expect-error private property
7
- _editorView;
8
- return (_editorView = this.editorView) !== null && _editorView !== void 0 ? _editorView : new StaticEditorView({
12
+ return(// @ts-expect-error private property
13
+ this.editorView ?? new StaticEditorView({
9
14
  state: EditorState.create({
10
15
  schema: this.extensionManager.schema
11
16
  }),
@@ -14,12 +19,6 @@ export class TiptapEditor extends Editor {
14
19
  role: "textbox",
15
20
  ...this.options.editorProps.attributes
16
21
  }
17
- });
18
- }
19
- constructor(options = {}){
20
- super({
21
- ...options,
22
- element: null
23
- });
22
+ }));
24
23
  }
25
24
  }
@@ -1,17 +1,3 @@
1
- function _extends() {
2
- _extends = Object.assign || function(target) {
3
- for(var i = 1; i < arguments.length; i++){
4
- var source = arguments[i];
5
- for(var key in source){
6
- if (Object.prototype.hasOwnProperty.call(source, key)) {
7
- target[key] = source[key];
8
- }
9
- }
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
15
1
  import React, { useContext, useSyncExternalStore } from "react";
16
2
  import { createPortal } from "react-dom";
17
3
  import { ProseMirrorDoc } from "../components/ProseMirrorDoc.js";
@@ -20,7 +6,7 @@ import { TiptapEditorContext } from "./contexts/TiptapEditorContext.js";
20
6
  /**
21
7
  * This component renders all of the editor's registered "React renderers".
22
8
  */ const Portals = (param)=>{
23
- let { contentComponent } = param;
9
+ let { contentComponent } = param;
24
10
  const renderers = useSyncExternalStore(contentComponent.subscribe, contentComponent.getSnapshot, contentComponent.getServerSnapshot);
25
11
  return /*#__PURE__*/ React.createElement(React.Fragment, null, Object.values(renderers));
26
12
  };
@@ -64,9 +50,9 @@ function getInstance() {
64
50
  };
65
51
  }
66
52
  export function TiptapEditorContent(param) {
67
- let { editor: editorProp , ...props } = param;
53
+ let { editor: editorProp, ...props } = param;
68
54
  const editor = editorProp;
69
- const { onEditorInitialize , onEditorDeinitialize } = useContext(TiptapEditorContext);
55
+ const { onEditorInitialize, onEditorDeinitialize } = useContext(TiptapEditorContext);
70
56
  useEditorEffect((view)=>{
71
57
  if (editor.view === view) {
72
58
  return;
@@ -100,7 +86,7 @@ export function TiptapEditorContent(param) {
100
86
  onEditorDeinitialize,
101
87
  onEditorInitialize
102
88
  ]);
103
- return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ProseMirrorDoc, _extends({}, props)), (editor === null || editor === void 0 ? void 0 : editor.contentComponent) && /*#__PURE__*/ React.createElement(Portals, {
89
+ return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ProseMirrorDoc, props), editor?.contentComponent && /*#__PURE__*/ React.createElement(Portals, {
104
90
  contentComponent: editor.contentComponent
105
91
  }));
106
92
  }
@@ -1,17 +1,3 @@
1
- function _extends() {
2
- _extends = Object.assign || function(target) {
3
- for(var i = 1; i < arguments.length; i++){
4
- var source = arguments[i];
5
- for(var key in source){
6
- if (Object.prototype.hasOwnProperty.call(source, key)) {
7
- target[key] = source[key];
8
- }
9
- }
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
15
1
  import { EditorContext } from "@tiptap/react";
16
2
  import cx from "classnames";
17
3
  import React, { useCallback, useMemo, useState } from "react";
@@ -21,10 +7,9 @@ import { TiptapEditorContext } from "./contexts/TiptapEditorContext.js";
21
7
  /**
22
8
  * Render a Tiptap-compatible React ProseMirror editor.
23
9
  */ export function TiptapEditorView(param) {
24
- let { editor , nodeViewComponents , markViewComponents , children , static: isStatic = false } = param;
25
- var ref;
10
+ let { editor, nodeViewComponents, markViewComponents, children, static: isStatic = false } = param;
26
11
  const [isEditorInitialized, setIsEditorInitialized] = useState(editor.isInitialized);
27
- const attributesProp = (ref = editor.options.editorProps) === null || ref === void 0 ? void 0 : ref.attributes;
12
+ const attributesProp = editor.options.editorProps?.attributes;
28
13
  const [attributes, setAttributes] = useState(typeof attributesProp === "function" ? attributesProp(editor.state) : attributesProp);
29
14
  const forceUpdate = useForceUpdate();
30
15
  const dispatchTransaction = useCallback((tr)=>{
@@ -47,10 +32,10 @@ import { TiptapEditorContext } from "./contexts/TiptapEditorContext.js";
47
32
  attributes: {
48
33
  role: "textbox",
49
34
  ...attributes,
50
- class: cx(attributes === null || attributes === void 0 ? void 0 : attributes.class, "tiptap")
35
+ class: cx(attributes?.class, "tiptap")
51
36
  }
52
37
  };
53
- const { nodeViews , markViews } = editor.isDestroyed ? {
38
+ const { nodeViews, markViews } = editor.isDestroyed ? {
54
39
  nodeViews: undefined,
55
40
  markViews: undefined
56
41
  } : editor.view.props;
@@ -74,16 +59,16 @@ import { TiptapEditorContext } from "./contexts/TiptapEditorContext.js";
74
59
  onEditorDeinitialize,
75
60
  onEditorInitialize
76
61
  ]);
77
- return /*#__PURE__*/ React.createElement(ProseMirror, _extends({
78
- static: isStatic
79
- }, editorProps, {
62
+ return /*#__PURE__*/ React.createElement(ProseMirror, {
63
+ static: isStatic,
64
+ ...editorProps,
80
65
  markViewComponents: markViewComponents,
81
66
  markViews: markViews,
82
67
  nodeViewComponents: nodeViewComponents,
83
68
  nodeViews: nodeViews,
84
69
  state: editor.state,
85
70
  dispatchTransaction: dispatchTransaction
86
- }), /*#__PURE__*/ React.createElement(EditorContext.Provider, {
71
+ }, /*#__PURE__*/ React.createElement(EditorContext.Provider, {
87
72
  value: contextValue
88
73
  }, /*#__PURE__*/ React.createElement(TiptapEditorContext.Provider, {
89
74
  value: tiptapEditorContextValue
@@ -21,7 +21,7 @@ export const ReactProseMirror = Extension.create({
21
21
  * and keep the other two in relative order, set `order` to `[1, 2, 0]`.
22
22
  */ reorderSiblings (initialPos, order) {
23
23
  return function reorderSiblingsCommand(param) {
24
- let { tr , state , dispatch } = param;
24
+ let { tr, state, dispatch } = param;
25
25
  return reorderSiblingsOnTransaction(initialPos, order, tr, state, dispatch);
26
26
  };
27
27
  }
@@ -4,7 +4,7 @@ import { getMarkType, getNodeType, getSchemaTypeNameByName } from "@tiptap/core"
4
4
  export const updateAttributes = function(typeOrName) {
5
5
  let attributes = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
6
6
  return (param)=>{
7
- let { tr , state , dispatch } = param;
7
+ let { tr, state, dispatch } = param;
8
8
  let nodeType = null;
9
9
  let markType = null;
10
10
  const schemaType = getSchemaTypeNameByName(typeof typeOrName === "string" ? typeOrName : typeOrName.name, state.schema);
@@ -1,19 +1,15 @@
1
- var // @ts-expect-error private property
2
- _editor;
3
1
  import { useEditor } from "@tiptap/react";
4
2
  import { StaticEditorView } from "../../StaticEditorView.js";
5
3
  import { ReactProseMirror } from "../extensions/ReactProseMirror.js";
6
4
  import { ReactProseMirrorCommands } from "../extensions/ReactProseMirrorCommands.js";
7
5
  export function useTiptapEditor(options, deps) {
8
- var ref;
9
- var _extensions;
10
6
  const extensions = [
11
7
  ReactProseMirror,
12
- ...(_extensions = options.extensions) !== null && _extensions !== void 0 ? _extensions : []
8
+ ...options.extensions ?? []
13
9
  ];
14
10
  // If a consumer explicitly disables core extensions (or the Commands core extension)
15
11
  // do not re-add our custom Commands
16
- if (options.enableCoreExtensions === false || typeof options.enableCoreExtensions === "object" && (options === null || options === void 0 ? void 0 : (ref = options.enableCoreExtensions) === null || ref === void 0 ? void 0 : ref.commands) === false) {
12
+ if (options.enableCoreExtensions === false || typeof options.enableCoreExtensions === "object" && options?.enableCoreExtensions?.commands === false) {
17
13
  // Do nothing
18
14
  } else {
19
15
  options.enableCoreExtensions = {
@@ -27,8 +23,8 @@ export function useTiptapEditor(options, deps) {
27
23
  extensions,
28
24
  element: null
29
25
  }, deps);
30
- var _editorView;
31
- (_editorView = (_editor = editor).editorView) !== null && _editorView !== void 0 ? _editorView : _editor.editorView = new StaticEditorView({
26
+ // @ts-expect-error private property
27
+ editor.editorView ??= new StaticEditorView({
32
28
  // @ts-expect-error private property
33
29
  state: editor.editorState,
34
30
  ...editor.options.editorProps,
@@ -22,11 +22,11 @@ import { TiptapEditorContext } from "../contexts/TiptapEditorContext.js";
22
22
  * as a child of the TiptapEditorView component, including
23
23
  * React node view components.
24
24
  */ export function useTiptapEditorEffect(effect, dependencies) {
25
- const { view } = useContext(EditorContext);
26
- const { editor } = useCurrentEditor();
27
- const { isEditorInitialized } = useContext(TiptapEditorContext);
25
+ const { view } = useContext(EditorContext);
26
+ const { editor } = useCurrentEditor();
27
+ const { isEditorInitialized } = useContext(TiptapEditorContext);
28
28
  useEditorEffect(()=>{
29
- if ((editor === null || editor === void 0 ? void 0 : editor.view) instanceof ReactEditorView && view instanceof ReactEditorView && isEditorInitialized) {
29
+ if (editor?.view instanceof ReactEditorView && view instanceof ReactEditorView && isEditorInitialized) {
30
30
  return effect(editor);
31
31
  }
32
32
  // The rules of hooks want to be able to statically
@@ -17,7 +17,7 @@ function assertEditor(editor) {
17
17
  * React node view components.
18
18
  */ export function useTiptapEditorEventCallback(callback) {
19
19
  const ref = useRef(callback);
20
- const { editor } = useCurrentEditor();
20
+ const { editor } = useCurrentEditor();
21
21
  useEditorEffect(()=>{
22
22
  ref.current = callback;
23
23
  }, [
@@ -1,17 +1,3 @@
1
- function _extends() {
2
- _extends = Object.assign || function(target) {
3
- for(var i = 1; i < arguments.length; i++){
4
- var source = arguments[i];
5
- for(var key in source){
6
- if (Object.prototype.hasOwnProperty.call(source, key)) {
7
- target[key] = source[key];
8
- }
9
- }
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
15
1
  import { getAttributesFromExtensions, getRenderedAttributes } from "@tiptap/core";
16
2
  import { ReactNodeViewContext, useCurrentEditor } from "@tiptap/react";
17
3
  import cx from "classnames";
@@ -49,16 +35,14 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
49
35
  * }
50
36
  * ```
51
37
  */ export function tiptapNodeView(param) {
52
- let { component: WrappedComponent , extension , as , className ="" , attrs , contentDOMElementTag: InnerTag = "div" , stopEvent , ignoreMutation } = param;
38
+ let { component: WrappedComponent, extension, as, className = "", attrs, contentDOMElementTag: InnerTag = "div", stopEvent, ignoreMutation } = param;
53
39
  const TiptapNodeView = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function TiptapNodeView(param, ref) {
54
- let { children , nodeProps , ...props } = param;
55
- const { node , getPos , decorations , innerDecorations , contentDOMRef } = nodeProps;
56
- const OuterTag = as !== null && as !== void 0 ? as : node.type.isInline ? "span" : "div";
57
- const { editor } = useCurrentEditor();
58
- var ref1;
59
- const extensionManager = (ref1 = editor === null || editor === void 0 ? void 0 : editor.extensionManager) !== null && ref1 !== void 0 ? ref1 : null;
60
- var ref2;
61
- const extensions = (ref2 = extensionManager === null || extensionManager === void 0 ? void 0 : extensionManager.extensions) !== null && ref2 !== void 0 ? ref2 : null;
40
+ let { children, nodeProps, ...props } = param;
41
+ const { node, getPos, decorations, innerDecorations, contentDOMRef } = nodeProps;
42
+ const OuterTag = as ?? (node.type.isInline ? "span" : "div");
43
+ const { editor } = useCurrentEditor();
44
+ const extensionManager = editor?.extensionManager ?? null;
45
+ const extensions = extensionManager?.extensions ?? null;
62
46
  const selected = useIsNodeSelected();
63
47
  const isDraggingRef = useRef(false);
64
48
  const htmlAttributes = useMemo(()=>{
@@ -95,10 +79,9 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
95
79
  isDraggingRef.current = nodeView.isDragging;
96
80
  return result;
97
81
  }
98
- var ref;
99
- const result1 = (ref = nodeView.stopEvent(event)) !== null && ref !== void 0 ? ref : false;
82
+ const result = nodeView.stopEvent(event) ?? false;
100
83
  isDraggingRef.current = nodeView.isDragging;
101
- return result1;
84
+ return result;
102
85
  });
103
86
  useIgnoreMutation(function(_, mutation) {
104
87
  if (ignoreMutation) {
@@ -121,16 +104,15 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
121
104
  node,
122
105
  view: editor.view
123
106
  }, this.dom, this.contentDOM);
124
- var ref;
125
- return (ref = nodeView.ignoreMutation(mutation)) !== null && ref !== void 0 ? ref : false;
107
+ return nodeView.ignoreMutation(mutation) ?? false;
126
108
  });
127
- const { extraClassName , htmlProps } = useMemo(()=>{
109
+ const { extraClassName, htmlProps } = useMemo(()=>{
128
110
  if (!attrs) return {};
129
111
  const resolvedAttrs = typeof attrs === "function" ? attrs({
130
112
  node,
131
113
  HTMLAttributes: htmlAttributes
132
114
  }) : attrs;
133
- const { className: extraClassName , ...htmlProps } = htmlAttrsToReactProps(resolvedAttrs);
115
+ const { className: extraClassName, ...htmlProps } = htmlAttrsToReactProps(resolvedAttrs);
134
116
  return {
135
117
  extraClassName,
136
118
  htmlProps
@@ -139,7 +121,7 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
139
121
  htmlAttributes,
140
122
  node
141
123
  ]);
142
- const finalClassName = cx("react-renderer", "node-".concat(node.type.name), props.className, className, extraClassName, {
124
+ const finalClassName = cx("react-renderer", `node-${node.type.name}`, props.className, className, extraClassName, {
143
125
  "ProseMirror-selectednode": selected
144
126
  });
145
127
  const updateAttributes = useEditorEventCallback((_, attributes)=>{
@@ -147,7 +129,7 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
147
129
  return;
148
130
  }
149
131
  editor.commands.command((param)=>{
150
- let { tr } = param;
132
+ let { tr } = param;
151
133
  const pos = getPos();
152
134
  tr.setNodeMarkup(pos, undefined, {
153
135
  ...node.attrs,
@@ -207,11 +189,12 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
207
189
  if (!editor) return null;
208
190
  return /*#__PURE__*/ React.createElement(ReactNodeViewContext.Provider, {
209
191
  value: nodeViewContext
210
- }, /*#__PURE__*/ React.createElement(OuterTag, _extends({
211
- ref: finalRef
212
- }, props, htmlProps, {
192
+ }, /*#__PURE__*/ React.createElement(OuterTag, {
193
+ ref: finalRef,
194
+ ...props,
195
+ ...htmlProps,
213
196
  className: finalClassName
214
- }), /*#__PURE__*/ React.createElement(WrappedComponent, {
197
+ }, /*#__PURE__*/ React.createElement(WrappedComponent, {
215
198
  node: node,
216
199
  getPos: getPos,
217
200
  view: editor.view,
@@ -225,7 +208,6 @@ import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallba
225
208
  deleteNode: deleteNode
226
209
  })));
227
210
  }));
228
- var _displayName;
229
- TiptapNodeView.displayName = "TiptapNodeView(".concat((_displayName = WrappedComponent.displayName) !== null && _displayName !== void 0 ? _displayName : "Anonymous", ")");
211
+ TiptapNodeView.displayName = `TiptapNodeView(${WrappedComponent.displayName ?? "Anonymous"})`;
230
212
  return TiptapNodeView;
231
213
  }