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

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 (142) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/ReactEditorView.js +71 -75
  3. package/dist/cjs/StaticEditorView.js +19 -22
  4. package/dist/cjs/browser.js +1 -3
  5. package/dist/cjs/commands/reorderSiblings.js +9 -13
  6. package/dist/cjs/components/ChildNodeViews.js +68 -71
  7. package/dist/cjs/components/CursorWrapper.js +26 -17
  8. package/dist/cjs/components/LayoutGroup.js +12 -16
  9. package/dist/cjs/components/NativeWidgetView.js +15 -19
  10. package/dist/cjs/components/OutputSpec.js +9 -13
  11. package/dist/cjs/components/ProseMirror.js +37 -27
  12. package/dist/cjs/components/ProseMirrorDoc.js +25 -18
  13. package/dist/cjs/components/SeparatorHackView.js +20 -21
  14. package/dist/cjs/components/TextNodeView.js +22 -20
  15. package/dist/cjs/components/TrailingHackView.js +13 -17
  16. package/dist/cjs/components/WidgetView.js +14 -18
  17. package/dist/cjs/components/marks/DefaultMarkView.js +27 -15
  18. package/dist/cjs/components/marks/MarkView.js +32 -23
  19. package/dist/cjs/components/marks/MarkViewConstructorView.js +38 -22
  20. package/dist/cjs/components/marks/ReactMarkView.js +27 -16
  21. package/dist/cjs/components/nodes/DefaultNodeView.js +27 -15
  22. package/dist/cjs/components/nodes/DocNodeView.js +12 -16
  23. package/dist/cjs/components/nodes/NodeView.js +33 -26
  24. package/dist/cjs/components/nodes/NodeViewConstructorView.js +45 -29
  25. package/dist/cjs/components/nodes/ReactNodeView.js +39 -27
  26. package/dist/cjs/constants.js +6 -10
  27. package/dist/cjs/contexts/ChildDescriptionsContext.js +1 -3
  28. package/dist/cjs/contexts/EditorContext.js +1 -3
  29. package/dist/cjs/contexts/EditorStateContext.js +1 -3
  30. package/dist/cjs/contexts/IgnoreMutationContext.js +1 -3
  31. package/dist/cjs/contexts/LayoutGroupContext.js +1 -3
  32. package/dist/cjs/contexts/NodeViewContext.js +1 -3
  33. package/dist/cjs/contexts/SelectNodeContext.js +1 -3
  34. package/dist/cjs/contexts/StopEventContext.js +1 -3
  35. package/dist/cjs/decorations/ReactWidgetType.js +13 -19
  36. package/dist/cjs/decorations/computeDocDeco.js +3 -5
  37. package/dist/cjs/decorations/iterDeco.js +17 -19
  38. package/dist/cjs/decorations/viewDecorations.js +12 -15
  39. package/dist/cjs/dom.js +13 -34
  40. package/dist/cjs/findDOMNode.js +5 -9
  41. package/dist/cjs/hooks/useClientLayoutEffect.js +1 -3
  42. package/dist/cjs/hooks/useComponentEventListeners.js +6 -7
  43. package/dist/cjs/hooks/useEditor.js +30 -28
  44. package/dist/cjs/hooks/useEditorEffect.js +7 -9
  45. package/dist/cjs/hooks/useEditorEventCallback.js +7 -9
  46. package/dist/cjs/hooks/useEditorEventListener.js +6 -8
  47. package/dist/cjs/hooks/useEditorState.js +3 -5
  48. package/dist/cjs/hooks/useEffectEvent.js +1 -3
  49. package/dist/cjs/hooks/useForceUpdate.js +1 -3
  50. package/dist/cjs/hooks/useIgnoreMutation.js +7 -9
  51. package/dist/cjs/hooks/useIsEditorStatic.js +5 -5
  52. package/dist/cjs/hooks/useIsNodeSelected.js +3 -5
  53. package/dist/cjs/hooks/useLayoutGroupEffect.js +5 -7
  54. package/dist/cjs/hooks/useMarkViewDescription.js +25 -24
  55. package/dist/cjs/hooks/useNodePos.js +5 -7
  56. package/dist/cjs/hooks/useNodeViewDescription.js +41 -28
  57. package/dist/cjs/hooks/useReactKeys.js +5 -7
  58. package/dist/cjs/hooks/useSelectNode.js +8 -10
  59. package/dist/cjs/hooks/useStopEvent.js +7 -9
  60. package/dist/cjs/index.js +34 -66
  61. package/dist/cjs/plugins/beforeInputPlugin.js +23 -20
  62. package/dist/cjs/plugins/componentEventListeners.js +6 -8
  63. package/dist/cjs/plugins/componentEventListenersPlugin.js +6 -8
  64. package/dist/cjs/plugins/reactKeys.js +10 -15
  65. package/dist/cjs/props.js +19 -23
  66. package/dist/cjs/refs.js +1 -3
  67. package/dist/cjs/testing/editorViewTestHelpers.js +47 -40
  68. package/dist/cjs/testing/setupProseMirrorView.js +4 -7
  69. package/dist/cjs/tiptap/ReactProseMirrorNodeView.js +6 -10
  70. package/dist/cjs/tiptap/TiptapEditor.js +14 -15
  71. package/dist/cjs/tiptap/TiptapEditorContent.js +28 -18
  72. package/dist/cjs/tiptap/TiptapEditorView.js +34 -23
  73. package/dist/cjs/tiptap/contexts/TiptapEditorContext.js +1 -3
  74. package/dist/cjs/tiptap/extensions/ReactProseMirror.js +6 -8
  75. package/dist/cjs/tiptap/extensions/ReactProseMirrorCommands.js +3 -5
  76. package/dist/cjs/tiptap/extensions/commands/updateAttributes.js +2 -4
  77. package/dist/cjs/tiptap/hooks/useIsInReactProseMirror.js +3 -5
  78. package/dist/cjs/tiptap/hooks/useTiptapEditor.js +14 -12
  79. package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +10 -12
  80. package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +4 -6
  81. package/dist/cjs/tiptap/index.js +18 -36
  82. package/dist/cjs/tiptap/tiptapNodeView.js +62 -48
  83. package/dist/cjs/viewdesc.js +95 -119
  84. package/dist/esm/ReactEditorView.js +67 -69
  85. package/dist/esm/StaticEditorView.js +18 -19
  86. package/dist/esm/commands/reorderSiblings.js +5 -5
  87. package/dist/esm/components/ChildNodeViews.js +36 -33
  88. package/dist/esm/components/CursorWrapper.js +18 -5
  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 +17 -3
  93. package/dist/esm/components/ProseMirrorDoc.js +19 -6
  94. package/dist/esm/components/SeparatorHackView.js +8 -5
  95. package/dist/esm/components/TextNodeView.js +10 -6
  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 +22 -6
  99. package/dist/esm/components/marks/MarkView.js +24 -11
  100. package/dist/esm/components/marks/MarkViewConstructorView.js +27 -7
  101. package/dist/esm/components/marks/ReactMarkView.js +18 -3
  102. package/dist/esm/components/nodes/DefaultNodeView.js +22 -6
  103. package/dist/esm/components/nodes/DocNodeView.js +2 -2
  104. package/dist/esm/components/nodes/NodeView.js +24 -11
  105. package/dist/esm/components/nodes/NodeViewConstructorView.js +31 -11
  106. package/dist/esm/components/nodes/ReactNodeView.js +22 -6
  107. package/dist/esm/decorations/ReactWidgetType.js +8 -10
  108. package/dist/esm/decorations/iterDeco.js +13 -13
  109. package/dist/esm/decorations/viewDecorations.js +6 -7
  110. package/dist/esm/dom.js +2 -1
  111. package/dist/esm/findDOMNode.js +1 -1
  112. package/dist/esm/hooks/useComponentEventListeners.js +3 -2
  113. package/dist/esm/hooks/useEditor.js +9 -5
  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 +3 -1
  118. package/dist/esm/hooks/useMarkViewDescription.js +10 -7
  119. package/dist/esm/hooks/useNodeViewDescription.js +22 -7
  120. package/dist/esm/hooks/useReactKeys.js +1 -1
  121. package/dist/esm/plugins/beforeInputPlugin.js +17 -12
  122. package/dist/esm/plugins/reactKeys.js +4 -3
  123. package/dist/esm/props.js +15 -15
  124. package/dist/esm/testing/editorViewTestHelpers.js +31 -20
  125. package/dist/esm/testing/setupProseMirrorView.js +2 -1
  126. package/dist/esm/tiptap/ReactProseMirrorNodeView.js +5 -7
  127. package/dist/esm/tiptap/TiptapEditor.js +10 -9
  128. package/dist/esm/tiptap/TiptapEditorContent.js +18 -4
  129. package/dist/esm/tiptap/TiptapEditorView.js +23 -8
  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 +8 -4
  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 +38 -20
  136. package/dist/esm/viewdesc.js +72 -74
  137. package/dist/tsconfig.tsbuildinfo +1 -1
  138. package/dist/types/ReactEditorView.d.ts +2 -2
  139. package/dist/types/StaticEditorView.d.ts +2 -1
  140. package/dist/types/props.d.ts +26 -26
  141. package/dist/types/viewdesc.d.ts +2 -0
  142. package/package.json +10 -6
@@ -4,18 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "useIgnoreMutation", {
6
6
  enumerable: true,
7
- get: function() {
8
- return useIgnoreMutation;
9
- }
7
+ get: ()=>useIgnoreMutation
10
8
  });
11
9
  const _react = require("react");
12
- const _IgnoreMutationContext = require("../contexts/IgnoreMutationContext.js");
13
- const _useEditorEffect = require("./useEditorEffect.js");
14
- const _useEditorEventCallback = require("./useEditorEventCallback.js");
10
+ const _ignoreMutationContextJs = require("../contexts/IgnoreMutationContext.js");
11
+ const _useEditorEffectJs = require("./useEditorEffect.js");
12
+ const _useEditorEventCallbackJs = require("./useEditorEventCallback.js");
15
13
  function useIgnoreMutation(ignoreMutation) {
16
- const register = (0, _react.useContext)(_IgnoreMutationContext.IgnoreMutationContext);
17
- const ignoreMutationMemo = (0, _useEditorEventCallback.useEditorEventCallback)(ignoreMutation);
18
- (0, _useEditorEffect.useEditorEffect)(()=>{
14
+ const register = (0, _react.useContext)(_ignoreMutationContextJs.IgnoreMutationContext);
15
+ const ignoreMutationMemo = (0, _useEditorEventCallbackJs.useEditorEventCallback)(ignoreMutation);
16
+ (0, _useEditorEffectJs.useEditorEffect)(()=>{
19
17
  return register(ignoreMutationMemo);
20
18
  }, [
21
19
  register,
@@ -4,12 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "useIsEditorStatic", {
6
6
  enumerable: true,
7
- get: function() {
8
- return useIsEditorStatic;
9
- }
7
+ get: ()=>useIsEditorStatic
10
8
  });
11
9
  const _react = require("react");
12
- const _EditorContext = require("../contexts/EditorContext.js");
10
+ const _editorContextJs = require("../contexts/EditorContext.js");
13
11
  function useIsEditorStatic() {
14
- return (0, _react.useContext)(_EditorContext.EditorContext)?.isStatic ?? false;
12
+ var ref;
13
+ var ref1;
14
+ return (ref1 = (ref = (0, _react.useContext)(_editorContextJs.EditorContext)) === null || ref === void 0 ? void 0 : ref.isStatic) !== null && ref1 !== void 0 ? ref1 : false;
15
15
  }
@@ -4,15 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "useIsNodeSelected", {
6
6
  enumerable: true,
7
- get: function() {
8
- return useIsNodeSelected;
9
- }
7
+ get: ()=>useIsNodeSelected
10
8
  });
11
9
  const _react = require("react");
12
- const _useSelectNode = require("./useSelectNode.js");
10
+ const _useSelectNodeJs = require("./useSelectNode.js");
13
11
  function useIsNodeSelected() {
14
12
  const [isSelected, setIsSelected] = (0, _react.useState)(false);
15
- (0, _useSelectNode.useSelectNode)(()=>{
13
+ (0, _useSelectNodeJs.useSelectNode)(()=>{
16
14
  setIsSelected(true);
17
15
  }, ()=>{
18
16
  setIsSelected(false);
@@ -4,17 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "useLayoutGroupEffect", {
6
6
  enumerable: true,
7
- get: function() {
8
- return useLayoutGroupEffect;
9
- }
7
+ get: ()=>useLayoutGroupEffect
10
8
  });
11
9
  const _react = require("react");
12
- const _LayoutGroupContext = require("../contexts/LayoutGroupContext.js");
13
- const _useClientLayoutEffect = require("./useClientLayoutEffect.js");
10
+ const _layoutGroupContextJs = require("../contexts/LayoutGroupContext.js");
11
+ const _useClientLayoutEffectJs = require("./useClientLayoutEffect.js");
14
12
  function useLayoutGroupEffect(effect, deps) {
15
- const register = (0, _react.useContext)(_LayoutGroupContext.LayoutGroupContext);
13
+ const register = (0, _react.useContext)(_layoutGroupContextJs.LayoutGroupContext);
16
14
  // The rule for hooks wants to statically verify the deps,
17
15
  // but the dependencies are up to the caller, not this implementation.
18
16
  // eslint-disable-next-line react-hooks/exhaustive-deps
19
- (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>register(effect), deps);
17
+ (0, _useClientLayoutEffectJs.useClientLayoutEffect)(()=>register(effect), deps);
20
18
  }
@@ -4,32 +4,31 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "useMarkViewDescription", {
6
6
  enumerable: true,
7
- get: function() {
8
- return useMarkViewDescription;
9
- }
7
+ get: ()=>useMarkViewDescription
10
8
  });
11
9
  const _react = require("react");
12
- const _ReactEditorView = require("../ReactEditorView.js");
13
- const _ChildDescriptionsContext = require("../contexts/ChildDescriptionsContext.js");
14
- const _EditorContext = require("../contexts/EditorContext.js");
15
- const _viewdesc = require("../viewdesc.js");
16
- const _useClientLayoutEffect = require("./useClientLayoutEffect.js");
17
- const _useEffectEvent = require("./useEffectEvent.js");
10
+ const _reactEditorViewJs = require("../ReactEditorView.js");
11
+ const _childDescriptionsContextJs = require("../contexts/ChildDescriptionsContext.js");
12
+ const _editorContextJs = require("../contexts/EditorContext.js");
13
+ const _viewdescJs = require("../viewdesc.js");
14
+ const _useClientLayoutEffectJs = require("./useClientLayoutEffect.js");
15
+ const _useEffectEventJs = require("./useEffectEvent.js");
18
16
  function useMarkViewDescription(getDOM, getContentDOM, constructor, props) {
19
- const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
20
- const { parentRef, siblingsRef } = (0, _react.useContext)(_ChildDescriptionsContext.ChildDescriptionsContext);
17
+ var ref;
18
+ const { view } = (0, _react.useContext)(_editorContextJs.EditorContext);
19
+ const { parentRef , siblingsRef } = (0, _react.useContext)(_childDescriptionsContextJs.ChildDescriptionsContext);
21
20
  const contentDOMRef = (0, _react.useRef)(null);
22
21
  const viewDescRef = (0, _react.useRef)();
23
22
  const childrenRef = (0, _react.useRef)([]);
24
- const create = (0, _useEffectEvent.useEffectEvent)(()=>{
25
- if (!(view instanceof _ReactEditorView.ReactEditorView)) {
23
+ const create = (0, _useEffectEventJs.useEffectEvent)(()=>{
24
+ if (!(view instanceof _reactEditorViewJs.ReactEditorView)) {
26
25
  return;
27
26
  }
28
27
  const dom = getDOM();
29
28
  if (!dom) {
30
29
  return;
31
30
  }
32
- const { mark, inline, getPos } = props;
31
+ const { mark , inline , getPos } = props;
33
32
  const markView = constructor(mark, view, inline);
34
33
  if (!markView) {
35
34
  return;
@@ -37,12 +36,12 @@ function useMarkViewDescription(getDOM, getContentDOM, constructor, props) {
37
36
  const parent = parentRef.current;
38
37
  const children = childrenRef.current;
39
38
  const contentDOM = getContentDOM(markView);
40
- const viewDesc = new _viewdesc.ReactMarkViewDesc(parent, children, getPos, mark, dom, contentDOM ?? markView.dom, markView);
39
+ const viewDesc = new _viewdescJs.ReactMarkViewDesc(parent, children, getPos, mark, dom, contentDOM !== null && contentDOM !== void 0 ? contentDOM : markView.dom, markView);
41
40
  contentDOMRef.current = contentDOM;
42
41
  return viewDesc;
43
42
  });
44
- const update = (0, _useEffectEvent.useEffectEvent)(()=>{
45
- if (!(view instanceof _ReactEditorView.ReactEditorView)) {
43
+ const update = (0, _useEffectEventJs.useEffectEvent)(()=>{
44
+ if (!(view instanceof _reactEditorViewJs.ReactEditorView)) {
46
45
  return false;
47
46
  }
48
47
  const viewDesc = viewDescRef.current;
@@ -54,13 +53,14 @@ function useMarkViewDescription(getDOM, getContentDOM, constructor, props) {
54
53
  return false;
55
54
  }
56
55
  const contentDOM = getContentDOM(viewDesc);
57
- if (contentDOM !== (viewDesc.contentDOM ?? dom)) {
56
+ var _contentDOM;
57
+ if (contentDOM !== ((_contentDOM = viewDesc.contentDOM) !== null && _contentDOM !== void 0 ? _contentDOM : dom)) {
58
58
  return false;
59
59
  }
60
- const { mark } = props;
60
+ const { mark } = props;
61
61
  return viewDesc.matchesMark(mark);
62
62
  });
63
- const destroy = (0, _useEffectEvent.useEffectEvent)(()=>{
63
+ const destroy = (0, _useEffectEventJs.useEffectEvent)(()=>{
64
64
  const viewDesc = viewDescRef.current;
65
65
  if (!viewDesc) {
66
66
  return;
@@ -73,7 +73,7 @@ function useMarkViewDescription(getDOM, getContentDOM, constructor, props) {
73
73
  }
74
74
  contentDOMRef.current = null;
75
75
  });
76
- (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
76
+ (0, _useClientLayoutEffectJs.useClientLayoutEffect)(()=>{
77
77
  viewDescRef.current = create();
78
78
  return ()=>{
79
79
  destroy();
@@ -92,7 +92,7 @@ function useMarkViewDescription(getDOM, getContentDOM, constructor, props) {
92
92
  destroy,
93
93
  update
94
94
  ]);
95
- (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
95
+ (0, _useClientLayoutEffectJs.useClientLayoutEffect)(()=>{
96
96
  if (!update()) {
97
97
  destroy();
98
98
  viewDescRef.current = create();
@@ -108,7 +108,7 @@ function useMarkViewDescription(getDOM, getContentDOM, constructor, props) {
108
108
  if (!siblings.includes(viewDesc)) {
109
109
  siblings.push(viewDesc);
110
110
  }
111
- siblings.sort(_viewdesc.sortViewDescs);
111
+ siblings.sort(_viewdescJs.sortViewDescs);
112
112
  for (const child of children){
113
113
  child.parent = viewDesc;
114
114
  }
@@ -120,9 +120,10 @@ function useMarkViewDescription(getDOM, getContentDOM, constructor, props) {
120
120
  childrenRef,
121
121
  viewDescRef
122
122
  ]);
123
+ var _current;
123
124
  return {
124
125
  childContextValue,
125
- contentDOM: contentDOMRef.current ?? viewDescRef.current?.dom,
126
+ contentDOM: (_current = contentDOMRef.current) !== null && _current !== void 0 ? _current : (ref = viewDescRef.current) === null || ref === void 0 ? void 0 : ref.dom,
126
127
  refUpdated
127
128
  };
128
129
  }
@@ -4,15 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "useNodePos", {
6
6
  enumerable: true,
7
- get: function() {
8
- return useNodePos;
9
- }
7
+ get: ()=>useNodePos
10
8
  });
11
9
  const _react = require("react");
12
- const _NodeView = require("../components/nodes/NodeView.js");
13
- const _useEditorState = require("./useEditorState.js");
10
+ const _nodeViewJs = require("../components/nodes/NodeView.js");
11
+ const _useEditorStateJs = require("./useEditorState.js");
14
12
  function useNodePos() {
15
- (0, _useEditorState.useEditorState)();
16
- const getPos = (0, _react.useContext)(_NodeView.GetPosContext);
13
+ (0, _useEditorStateJs.useEditorState)();
14
+ const getPos = (0, _react.useContext)(_nodeViewJs.GetPosContext);
17
15
  return getPos();
18
16
  }
@@ -4,32 +4,30 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "useNodeViewDescription", {
6
6
  enumerable: true,
7
- get: function() {
8
- return useNodeViewDescription;
9
- }
7
+ get: ()=>useNodeViewDescription
10
8
  });
11
9
  const _react = require("react");
12
- const _ReactEditorView = require("../ReactEditorView.js");
13
- const _ChildDescriptionsContext = require("../contexts/ChildDescriptionsContext.js");
14
- const _EditorContext = require("../contexts/EditorContext.js");
15
- const _viewdesc = require("../viewdesc.js");
16
- const _useClientLayoutEffect = require("./useClientLayoutEffect.js");
17
- const _useEffectEvent = require("./useEffectEvent.js");
10
+ const _reactEditorViewJs = require("../ReactEditorView.js");
11
+ const _childDescriptionsContextJs = require("../contexts/ChildDescriptionsContext.js");
12
+ const _editorContextJs = require("../contexts/EditorContext.js");
13
+ const _viewdescJs = require("../viewdesc.js");
14
+ const _useClientLayoutEffectJs = require("./useClientLayoutEffect.js");
15
+ const _useEffectEventJs = require("./useEffectEvent.js");
18
16
  function useNodeViewDescription(getDOM, getContentDOM, constructor, props) {
19
- const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
20
- const { parentRef, siblingsRef } = (0, _react.useContext)(_ChildDescriptionsContext.ChildDescriptionsContext);
17
+ const { view } = (0, _react.useContext)(_editorContextJs.EditorContext);
18
+ const { parentRef , siblingsRef } = (0, _react.useContext)(_childDescriptionsContextJs.ChildDescriptionsContext);
21
19
  const contentDOMRef = (0, _react.useRef)(null);
22
20
  const viewDescRef = (0, _react.useRef)();
23
21
  const childrenRef = (0, _react.useRef)([]);
24
- const create = (0, _useEffectEvent.useEffectEvent)(()=>{
25
- if (!(view instanceof _ReactEditorView.ReactEditorView)) {
22
+ const create = (0, _useEffectEventJs.useEffectEvent)(()=>{
23
+ if (!(view instanceof _reactEditorViewJs.ReactEditorView)) {
26
24
  return;
27
25
  }
28
26
  const dom = getDOM();
29
27
  if (!dom) {
30
28
  return;
31
29
  }
32
- const { node, getPos, decorations, innerDecorations } = props;
30
+ const { node , getPos , decorations , innerDecorations } = props;
33
31
  const nodeView = constructor(node, view, getPos, decorations, innerDecorations);
34
32
  if (!nodeView) {
35
33
  return;
@@ -38,17 +36,17 @@ function useNodeViewDescription(getDOM, getContentDOM, constructor, props) {
38
36
  const children = childrenRef.current;
39
37
  const contentDOM = getContentDOM(nodeView);
40
38
  const nodeDOM = nodeView.dom;
41
- const viewDesc = new _viewdesc.ReactNodeViewDesc(parent, children, getPos, node, decorations, innerDecorations, dom, contentDOM, nodeDOM, nodeView);
39
+ const viewDesc = new _viewdescJs.ReactNodeViewDesc(parent, children, getPos, node, decorations, innerDecorations, dom, contentDOM, nodeDOM, nodeView);
42
40
  const siblings = siblingsRef.current;
43
41
  if (!siblings.includes(viewDesc)) {
44
42
  siblings.push(viewDesc);
45
43
  }
46
- siblings.sort(_viewdesc.sortViewDescs);
44
+ siblings.sort(_viewdescJs.sortViewDescs);
47
45
  contentDOMRef.current = getContentDOM(nodeView);
48
46
  return viewDesc;
49
47
  });
50
- const update = (0, _useEffectEvent.useEffectEvent)(()=>{
51
- if (!(view instanceof _ReactEditorView.ReactEditorView)) {
48
+ const update = (0, _useEffectEventJs.useEffectEvent)(()=>{
49
+ if (!(view instanceof _reactEditorViewJs.ReactEditorView)) {
52
50
  return false;
53
51
  }
54
52
  const viewDesc = viewDescRef.current;
@@ -66,10 +64,10 @@ function useNodeViewDescription(getDOM, getContentDOM, constructor, props) {
66
64
  if (!dom.contains(viewDesc.nodeDOM)) {
67
65
  return false;
68
66
  }
69
- const { node, decorations, innerDecorations } = props;
67
+ const { node , decorations , innerDecorations } = props;
70
68
  return viewDesc.matchesNode(node, decorations, innerDecorations) || viewDesc.update(node, decorations, innerDecorations, view);
71
69
  });
72
- const destroy = (0, _useEffectEvent.useEffectEvent)(()=>{
70
+ const destroy = (0, _useEffectEventJs.useEffectEvent)(()=>{
73
71
  const viewDesc = viewDescRef.current;
74
72
  if (!viewDesc) {
75
73
  return;
@@ -82,7 +80,7 @@ function useNodeViewDescription(getDOM, getContentDOM, constructor, props) {
82
80
  }
83
81
  contentDOMRef.current = null;
84
82
  });
85
- (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
83
+ (0, _useClientLayoutEffectJs.useClientLayoutEffect)(()=>{
86
84
  viewDescRef.current = create();
87
85
  return ()=>{
88
86
  destroy();
@@ -102,7 +100,7 @@ function useNodeViewDescription(getDOM, getContentDOM, constructor, props) {
102
100
  destroy,
103
101
  update
104
102
  ]);
105
- (0, _useClientLayoutEffect.useClientLayoutEffect)(()=>{
103
+ (0, _useClientLayoutEffectJs.useClientLayoutEffect)(()=>{
106
104
  if (!update()) {
107
105
  destroy();
108
106
  viewDescRef.current = create();
@@ -111,7 +109,7 @@ function useNodeViewDescription(getDOM, getContentDOM, constructor, props) {
111
109
  if (!viewDesc) {
112
110
  return;
113
111
  }
114
- if (view.dom === viewDesc.dom && view instanceof _ReactEditorView.ReactEditorView) {
112
+ if (view.dom === viewDesc.dom && view instanceof _reactEditorViewJs.ReactEditorView) {
115
113
  view.docView = viewDesc;
116
114
  }
117
115
  const parent = parentRef.current;
@@ -121,19 +119,34 @@ function useNodeViewDescription(getDOM, getContentDOM, constructor, props) {
121
119
  if (!siblings.includes(viewDesc)) {
122
120
  siblings.push(viewDesc);
123
121
  }
124
- siblings.sort(_viewdesc.sortViewDescs);
122
+ // In strict/concurrent mode, a node can sometimes re-render
123
+ // entirely on its own, without even its parent re-rendering.
124
+ // In this case, we will have added our view descriptions to
125
+ // our parent's children, but our parent has no opportunity
126
+ // to sort its children, because it never renders. So
127
+ // we always sort our siblings, too.
128
+ siblings.sort(_viewdescJs.sortViewDescs);
129
+ // If a child updates, usually it will re-render and sort
130
+ // our children for us. But it's possible to reorder
131
+ // child nodes without changing their keys or node
132
+ // instances, in which case our children _won't_
133
+ // rerender. As a fallback, we do one last pass through
134
+ // our own child view descriptions and make sure
135
+ // they're ordered. This should be a cheap no-op in most cases.
136
+ children.sort(_viewdescJs.sortViewDescs);
125
137
  for (const child of children){
126
138
  child.parent = viewDesc;
127
139
  // Because TextNodeViews can't locate the DOM nodes
128
140
  // for compositions, we need to override them here
129
- if (child instanceof _viewdesc.CompositionViewDesc) {
130
- const compositionTopDOM = viewDesc?.contentDOM?.firstChild;
131
- if (!compositionTopDOM) throw new Error(`Started a composition but couldn't find the text node it belongs to.`);
141
+ if (child instanceof _viewdescJs.CompositionViewDesc) {
142
+ var ref;
143
+ const compositionTopDOM = viewDesc === null || viewDesc === void 0 ? void 0 : (ref = viewDesc.contentDOM) === null || ref === void 0 ? void 0 : ref.firstChild;
144
+ if (!compositionTopDOM) throw new Error("Started a composition but couldn't find the text node it belongs to.");
132
145
  let textDOM = compositionTopDOM;
133
146
  while(textDOM.firstChild){
134
147
  textDOM = textDOM.firstChild;
135
148
  }
136
- if (!textDOM || !(textDOM instanceof Text)) throw new Error(`Started a composition but couldn't find the text node it belongs to.`);
149
+ if (!textDOM || !(textDOM instanceof Text)) throw new Error("Started a composition but couldn't find the text node it belongs to.");
137
150
  child.dom = compositionTopDOM;
138
151
  child.textDOM = textDOM;
139
152
  child.text = textDOM.data;
@@ -4,14 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "useReactKeys", {
6
6
  enumerable: true,
7
- get: function() {
8
- return useReactKeys;
9
- }
7
+ get: ()=>useReactKeys
10
8
  });
11
9
  const _react = require("react");
12
- const _EditorContext = require("../contexts/EditorContext.js");
13
- const _reactKeys = require("../plugins/reactKeys.js");
10
+ const _editorContextJs = require("../contexts/EditorContext.js");
11
+ const _reactKeysJs = require("../plugins/reactKeys.js");
14
12
  function useReactKeys() {
15
- const { view } = (0, _react.useContext)(_EditorContext.EditorContext);
16
- return _reactKeys.reactKeysPluginKey.getState(view.state);
13
+ const { view } = (0, _react.useContext)(_editorContextJs.EditorContext);
14
+ return _reactKeysJs.reactKeysPluginKey.getState(view.state);
17
15
  }
@@ -4,23 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "useSelectNode", {
6
6
  enumerable: true,
7
- get: function() {
8
- return useSelectNode;
9
- }
7
+ get: ()=>useSelectNode
10
8
  });
11
9
  const _react = require("react");
12
- const _SelectNodeContext = require("../contexts/SelectNodeContext.js");
13
- const _useEditorEffect = require("./useEditorEffect.js");
14
- const _useEditorEventCallback = require("./useEditorEventCallback.js");
10
+ const _selectNodeContextJs = require("../contexts/SelectNodeContext.js");
11
+ const _useEditorEffectJs = require("./useEditorEffect.js");
12
+ const _useEditorEventCallbackJs = require("./useEditorEventCallback.js");
15
13
  function noop() {
16
14
  // empty
17
15
  }
18
16
  function useSelectNode(selectNode) {
19
17
  let deselectNode = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
20
- const register = (0, _react.useContext)(_SelectNodeContext.SelectNodeContext);
21
- const selectNodeMemo = (0, _useEditorEventCallback.useEditorEventCallback)(selectNode);
22
- const deselectNodeMemo = (0, _useEditorEventCallback.useEditorEventCallback)(deselectNode);
23
- return (0, _useEditorEffect.useEditorEffect)(()=>{
18
+ const register = (0, _react.useContext)(_selectNodeContextJs.SelectNodeContext);
19
+ const selectNodeMemo = (0, _useEditorEventCallbackJs.useEditorEventCallback)(selectNode);
20
+ const deselectNodeMemo = (0, _useEditorEventCallbackJs.useEditorEventCallback)(deselectNode);
21
+ return (0, _useEditorEffectJs.useEditorEffect)(()=>{
24
22
  return register(selectNodeMemo, deselectNodeMemo);
25
23
  }, [
26
24
  register,
@@ -4,18 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "useStopEvent", {
6
6
  enumerable: true,
7
- get: function() {
8
- return useStopEvent;
9
- }
7
+ get: ()=>useStopEvent
10
8
  });
11
9
  const _react = require("react");
12
- const _StopEventContext = require("../contexts/StopEventContext.js");
13
- const _useEditorEffect = require("./useEditorEffect.js");
14
- const _useEditorEventCallback = require("./useEditorEventCallback.js");
10
+ const _stopEventContextJs = require("../contexts/StopEventContext.js");
11
+ const _useEditorEffectJs = require("./useEditorEffect.js");
12
+ const _useEditorEventCallbackJs = require("./useEditorEventCallback.js");
15
13
  function useStopEvent(stopEvent) {
16
- const register = (0, _react.useContext)(_StopEventContext.StopEventContext);
17
- const stopEventMemo = (0, _useEditorEventCallback.useEditorEventCallback)(stopEvent);
18
- (0, _useEditorEffect.useEditorEffect)(()=>{
14
+ const register = (0, _react.useContext)(_stopEventContextJs.StopEventContext);
15
+ const stopEventMemo = (0, _useEditorEventCallbackJs.useEditorEventCallback)(stopEvent);
16
+ (0, _useEditorEffectJs.useEditorEffect)(()=>{
19
17
  return register(stopEventMemo);
20
18
  }, [
21
19
  register,
package/dist/cjs/index.js CHANGED
@@ -1,5 +1,4 @@
1
- /* Copyright (c) The New York Times Company */ "use client";
2
- "use strict";
1
+ /* Copyright (c) The New York Times Company */ "use strict";
3
2
  Object.defineProperty(exports, "__esModule", {
4
3
  value: true
5
4
  });
@@ -10,68 +9,37 @@ function _export(target, all) {
10
9
  });
11
10
  }
12
11
  _export(exports, {
13
- ProseMirror: function() {
14
- return _ProseMirror.ProseMirror;
15
- },
16
- ProseMirrorDoc: function() {
17
- return _ProseMirrorDoc.ProseMirrorDoc;
18
- },
19
- reactKeys: function() {
20
- return _reactKeys.reactKeys;
21
- },
22
- reorderSiblings: function() {
23
- return _reorderSiblings.reorderSiblings;
24
- },
25
- useEditorEffect: function() {
26
- return _useEditorEffect.useEditorEffect;
27
- },
28
- useEditorEventCallback: function() {
29
- return _useEditorEventCallback.useEditorEventCallback;
30
- },
31
- useEditorEventListener: function() {
32
- return _useEditorEventListener.useEditorEventListener;
33
- },
34
- useEditorState: function() {
35
- return _useEditorState.useEditorState;
36
- },
37
- useIgnoreMutation: function() {
38
- return _useIgnoreMutation.useIgnoreMutation;
39
- },
40
- useIsEditorStatic: function() {
41
- return _useIsEditorStatic.useIsEditorStatic;
42
- },
43
- useIsNodeSelected: function() {
44
- return _useIsNodeSelected.useIsNodeSelected;
45
- },
46
- useMergedDOMRefs: function() {
47
- return _refs.useMergedDOMRefs;
48
- },
49
- useNodePos: function() {
50
- return _useNodePos.useNodePos;
51
- },
52
- useSelectNode: function() {
53
- return _useSelectNode.useSelectNode;
54
- },
55
- useStopEvent: function() {
56
- return _useStopEvent.useStopEvent;
57
- },
58
- widget: function() {
59
- return _ReactWidgetType.widget;
60
- }
12
+ ProseMirror: ()=>_proseMirrorJs.ProseMirror,
13
+ ProseMirrorDoc: ()=>_proseMirrorDocJs.ProseMirrorDoc,
14
+ reorderSiblings: ()=>_reorderSiblingsJs.reorderSiblings,
15
+ useEditorEffect: ()=>_useEditorEffectJs.useEditorEffect,
16
+ useEditorEventCallback: ()=>_useEditorEventCallbackJs.useEditorEventCallback,
17
+ useEditorEventListener: ()=>_useEditorEventListenerJs.useEditorEventListener,
18
+ useEditorState: ()=>_useEditorStateJs.useEditorState,
19
+ useNodePos: ()=>_useNodePosJs.useNodePos,
20
+ useStopEvent: ()=>_useStopEventJs.useStopEvent,
21
+ useSelectNode: ()=>_useSelectNodeJs.useSelectNode,
22
+ useIgnoreMutation: ()=>_useIgnoreMutationJs.useIgnoreMutation,
23
+ useIsEditorStatic: ()=>_useIsEditorStaticJs.useIsEditorStatic,
24
+ useIsNodeSelected: ()=>_useIsNodeSelectedJs.useIsNodeSelected,
25
+ reactKeys: ()=>_reactKeysJs.reactKeys,
26
+ widget: ()=>_reactWidgetTypeJs.widget,
27
+ useMergedDOMRefs: ()=>_refsJs.useMergedDOMRefs
61
28
  });
62
- const _ProseMirror = require("./components/ProseMirror.js");
63
- const _ProseMirrorDoc = require("./components/ProseMirrorDoc.js");
64
- const _reorderSiblings = require("./commands/reorderSiblings.js");
65
- const _useEditorEffect = require("./hooks/useEditorEffect.js");
66
- const _useEditorEventCallback = require("./hooks/useEditorEventCallback.js");
67
- const _useEditorEventListener = require("./hooks/useEditorEventListener.js");
68
- const _useEditorState = require("./hooks/useEditorState.js");
69
- const _useNodePos = require("./hooks/useNodePos.js");
70
- const _useStopEvent = require("./hooks/useStopEvent.js");
71
- const _useSelectNode = require("./hooks/useSelectNode.js");
72
- const _useIgnoreMutation = require("./hooks/useIgnoreMutation.js");
73
- const _useIsEditorStatic = require("./hooks/useIsEditorStatic.js");
74
- const _useIsNodeSelected = require("./hooks/useIsNodeSelected.js");
75
- const _reactKeys = require("./plugins/reactKeys.js");
76
- const _ReactWidgetType = require("./decorations/ReactWidgetType.js");
77
- const _refs = require("./refs.js");
29
+ const _proseMirrorJs = require("./components/ProseMirror.js");
30
+ const _proseMirrorDocJs = require("./components/ProseMirrorDoc.js");
31
+ const _reorderSiblingsJs = require("./commands/reorderSiblings.js");
32
+ const _useEditorEffectJs = require("./hooks/useEditorEffect.js");
33
+ const _useEditorEventCallbackJs = require("./hooks/useEditorEventCallback.js");
34
+ const _useEditorEventListenerJs = require("./hooks/useEditorEventListener.js");
35
+ const _useEditorStateJs = require("./hooks/useEditorState.js");
36
+ const _useNodePosJs = require("./hooks/useNodePos.js");
37
+ const _useStopEventJs = require("./hooks/useStopEvent.js");
38
+ const _useSelectNodeJs = require("./hooks/useSelectNode.js");
39
+ const _useIgnoreMutationJs = require("./hooks/useIgnoreMutation.js");
40
+ const _useIsEditorStaticJs = require("./hooks/useIsEditorStatic.js");
41
+ const _useIsNodeSelectedJs = require("./hooks/useIsNodeSelected.js");
42
+ const _reactKeysJs = require("./plugins/reactKeys.js");
43
+ const _reactWidgetTypeJs = require("./decorations/ReactWidgetType.js");
44
+ const _refsJs = require("./refs.js");
45
+ "use client";