@stesura/react-prosemirror 3.2.11-stesura.1
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/LICENSE.txt +21 -0
- package/README.md +939 -0
- package/dist/cjs/AbstractEditorView.js +4 -0
- package/dist/cjs/ReactEditorView.js +194 -0
- package/dist/cjs/StaticEditorView.js +89 -0
- package/dist/cjs/browser.js +53 -0
- package/dist/cjs/commands/reorderSiblings.js +72 -0
- package/dist/cjs/components/ChildNodeViews.js +418 -0
- package/dist/cjs/components/CursorWrapper.js +84 -0
- package/dist/cjs/components/EditorStateSelectorsProvider.js +90 -0
- package/dist/cjs/components/LayoutGroup.js +112 -0
- package/dist/cjs/components/NativeWidgetView.js +108 -0
- package/dist/cjs/components/OutputSpec.js +121 -0
- package/dist/cjs/components/ProseMirror.js +146 -0
- package/dist/cjs/components/ProseMirrorDoc.js +74 -0
- package/dist/cjs/components/SeparatorHackView.js +99 -0
- package/dist/cjs/components/TextNodeView.js +113 -0
- package/dist/cjs/components/TrailingHackView.js +87 -0
- package/dist/cjs/components/WidgetView.js +94 -0
- package/dist/cjs/components/WidgetViewComponentProps.js +4 -0
- package/dist/cjs/components/marks/DefaultMarkView.js +70 -0
- package/dist/cjs/components/marks/MarkView.js +85 -0
- package/dist/cjs/components/marks/MarkViewComponentProps.js +4 -0
- package/dist/cjs/components/marks/MarkViewConstructorView.js +116 -0
- package/dist/cjs/components/marks/ReactMarkView.js +109 -0
- package/dist/cjs/components/nodes/DefaultNodeView.js +68 -0
- package/dist/cjs/components/nodes/DocNodeView.js +97 -0
- package/dist/cjs/components/nodes/NodeView.js +129 -0
- package/dist/cjs/components/nodes/NodeViewComponentProps.js +4 -0
- package/dist/cjs/components/nodes/NodeViewConstructorView.js +145 -0
- package/dist/cjs/components/nodes/ReactNodeView.js +189 -0
- package/dist/cjs/constants.js +33 -0
- package/dist/cjs/contexts/ChildDescriptionsContext.js +19 -0
- package/dist/cjs/contexts/EditorContext.js +12 -0
- package/dist/cjs/contexts/EditorStateContext.js +12 -0
- package/dist/cjs/contexts/EditorStateStoreContext.js +45 -0
- package/dist/cjs/contexts/IgnoreMutationContext.js +12 -0
- package/dist/cjs/contexts/LayoutGroupContext.js +12 -0
- package/dist/cjs/contexts/NodeViewContext.js +12 -0
- package/dist/cjs/contexts/RenderStoreContext.js +54 -0
- package/dist/cjs/contexts/SelectNodeContext.js +12 -0
- package/dist/cjs/contexts/StopEventContext.js +12 -0
- package/dist/cjs/decorations/ReactWidgetType.js +58 -0
- package/dist/cjs/decorations/computeDocDeco.js +44 -0
- package/dist/cjs/decorations/internalTypes.js +4 -0
- package/dist/cjs/decorations/iterDeco.js +91 -0
- package/dist/cjs/decorations/viewDecorations.js +155 -0
- package/dist/cjs/dom.js +147 -0
- package/dist/cjs/findDOMNode.js +46 -0
- package/dist/cjs/hooks/useClientLayoutEffect.js +19 -0
- package/dist/cjs/hooks/useComponentEventListeners.js +72 -0
- package/dist/cjs/hooks/useEditor.js +130 -0
- package/dist/cjs/hooks/useEditorEffect.js +39 -0
- package/dist/cjs/hooks/useEditorEventCallback.js +38 -0
- package/dist/cjs/hooks/useEditorEventListener.js +34 -0
- package/dist/cjs/hooks/useEditorState.js +18 -0
- package/dist/cjs/hooks/useEditorStateSelector.js +17 -0
- package/dist/cjs/hooks/useEffectEvent.js +34 -0
- package/dist/cjs/hooks/useForceUpdate.js +15 -0
- package/dist/cjs/hooks/useIgnoreMutation.js +24 -0
- package/dist/cjs/hooks/useIsComposingIn.js +25 -0
- package/dist/cjs/hooks/useIsEditorStatic.js +15 -0
- package/dist/cjs/hooks/useIsNodeSelected.js +21 -0
- package/dist/cjs/hooks/useLayoutGroupEffect.js +20 -0
- package/dist/cjs/hooks/useMarkViewDescription.js +134 -0
- package/dist/cjs/hooks/useNodePos.js +18 -0
- package/dist/cjs/hooks/useNodeViewDescription.js +154 -0
- package/dist/cjs/hooks/useReactKeys.js +17 -0
- package/dist/cjs/hooks/useSelectNode.js +30 -0
- package/dist/cjs/hooks/useSetDom.js +57 -0
- package/dist/cjs/hooks/useStopEvent.js +24 -0
- package/dist/cjs/index.js +85 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/plugins/beforeInputPlugin.js +356 -0
- package/dist/cjs/plugins/reactKeys.js +121 -0
- package/dist/cjs/props.js +283 -0
- package/dist/cjs/refs.js +28 -0
- package/dist/cjs/testing/editorViewTestHelpers.js +109 -0
- package/dist/cjs/testing/setupProseMirrorView.js +94 -0
- package/dist/cjs/tiptap/ReactProseMirrorNodeView.js +26 -0
- package/dist/cjs/tiptap/TiptapEditor.js +34 -0
- package/dist/cjs/tiptap/TiptapEditorContent.js +143 -0
- package/dist/cjs/tiptap/TiptapEditorView.js +130 -0
- package/dist/cjs/tiptap/contexts/TiptapEditorContext.js +12 -0
- package/dist/cjs/tiptap/extensions/ReactProseMirror.js +40 -0
- package/dist/cjs/tiptap/extensions/ReactProseMirrorCommands.js +21 -0
- package/dist/cjs/tiptap/extensions/commands/updateAttributes.js +104 -0
- package/dist/cjs/tiptap/hooks/useEditor.js +318 -0
- package/dist/cjs/tiptap/hooks/useIsInReactProseMirror.js +15 -0
- package/dist/cjs/tiptap/hooks/useTiptapEditor.js +35 -0
- package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +35 -0
- package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +35 -0
- package/dist/cjs/tiptap/index.js +48 -0
- package/dist/cjs/tiptap/tiptapNodeView.js +245 -0
- package/dist/cjs/viewdesc.js +862 -0
- package/dist/esm/AbstractEditorView.js +1 -0
- package/dist/esm/ReactEditorView.js +194 -0
- package/dist/esm/StaticEditorView.js +79 -0
- package/dist/esm/browser.js +43 -0
- package/dist/esm/commands/reorderSiblings.js +63 -0
- package/dist/esm/components/ChildNodeViews.js +359 -0
- package/dist/esm/components/CursorWrapper.js +33 -0
- package/dist/esm/components/EditorStateSelectorsProvider.js +31 -0
- package/dist/esm/components/LayoutGroup.js +67 -0
- package/dist/esm/components/NativeWidgetView.js +57 -0
- package/dist/esm/components/OutputSpec.js +71 -0
- package/dist/esm/components/ProseMirror.js +95 -0
- package/dist/esm/components/ProseMirrorDoc.js +15 -0
- package/dist/esm/components/SeparatorHackView.js +48 -0
- package/dist/esm/components/TextNodeView.js +103 -0
- package/dist/esm/components/TrailingHackView.js +36 -0
- package/dist/esm/components/WidgetView.js +43 -0
- package/dist/esm/components/WidgetViewComponentProps.js +1 -0
- package/dist/esm/components/marks/DefaultMarkView.js +19 -0
- package/dist/esm/components/marks/MarkView.js +34 -0
- package/dist/esm/components/marks/MarkViewComponentProps.js +1 -0
- package/dist/esm/components/marks/MarkViewConstructorView.js +65 -0
- package/dist/esm/components/marks/ReactMarkView.js +58 -0
- package/dist/esm/components/nodes/DefaultNodeView.js +17 -0
- package/dist/esm/components/nodes/DocNodeView.js +46 -0
- package/dist/esm/components/nodes/NodeView.js +67 -0
- package/dist/esm/components/nodes/NodeViewComponentProps.js +1 -0
- package/dist/esm/components/nodes/NodeViewConstructorView.js +94 -0
- package/dist/esm/components/nodes/ReactNodeView.js +138 -0
- package/dist/esm/constants.js +15 -0
- package/dist/esm/contexts/ChildDescriptionsContext.js +9 -0
- package/dist/esm/contexts/EditorContext.js +7 -0
- package/dist/esm/contexts/EditorStateContext.js +2 -0
- package/dist/esm/contexts/EditorStateStoreContext.js +27 -0
- package/dist/esm/contexts/IgnoreMutationContext.js +2 -0
- package/dist/esm/contexts/LayoutGroupContext.js +2 -0
- package/dist/esm/contexts/NodeViewContext.js +2 -0
- package/dist/esm/contexts/RenderStoreContext.js +33 -0
- package/dist/esm/contexts/SelectNodeContext.js +2 -0
- package/dist/esm/contexts/StopEventContext.js +2 -0
- package/dist/esm/decorations/ReactWidgetType.js +40 -0
- package/dist/esm/decorations/computeDocDeco.js +44 -0
- package/dist/esm/decorations/internalTypes.js +1 -0
- package/dist/esm/decorations/iterDeco.js +85 -0
- package/dist/esm/decorations/viewDecorations.js +155 -0
- package/dist/esm/dom.js +110 -0
- package/dist/esm/findDOMNode.js +31 -0
- package/dist/esm/hooks/useClientLayoutEffect.js +9 -0
- package/dist/esm/hooks/useComponentEventListeners.js +87 -0
- package/dist/esm/hooks/useEditor.js +128 -0
- package/dist/esm/hooks/useEditorEffect.js +46 -0
- package/dist/esm/hooks/useEditorEventCallback.js +38 -0
- package/dist/esm/hooks/useEditorEventListener.js +28 -0
- package/dist/esm/hooks/useEditorState.js +10 -0
- package/dist/esm/hooks/useEditorStateSelector.js +14 -0
- package/dist/esm/hooks/useEffectEvent.js +24 -0
- package/dist/esm/hooks/useForceUpdate.js +8 -0
- package/dist/esm/hooks/useIgnoreMutation.js +14 -0
- package/dist/esm/hooks/useIsComposingIn.js +17 -0
- package/dist/esm/hooks/useIsEditorStatic.js +8 -0
- package/dist/esm/hooks/useIsNodeSelected.js +11 -0
- package/dist/esm/hooks/useLayoutGroupEffect.js +10 -0
- package/dist/esm/hooks/useMarkViewDescription.js +124 -0
- package/dist/esm/hooks/useNodePos.js +15 -0
- package/dist/esm/hooks/useNodeViewDescription.js +144 -0
- package/dist/esm/hooks/useReactKeys.js +7 -0
- package/dist/esm/hooks/useSelectNode.js +20 -0
- package/dist/esm/hooks/useSetDom.js +47 -0
- package/dist/esm/hooks/useStopEvent.js +14 -0
- package/dist/esm/index.js +19 -0
- package/dist/esm/plugins/beforeInputPlugin.js +346 -0
- package/dist/esm/plugins/reactKeys.js +106 -0
- package/dist/esm/props.js +267 -0
- package/dist/esm/refs.js +18 -0
- package/dist/esm/testing/editorViewTestHelpers.js +86 -0
- package/dist/esm/testing/setupProseMirrorView.js +76 -0
- package/dist/esm/tiptap/ReactProseMirrorNodeView.js +22 -0
- package/dist/esm/tiptap/TiptapEditor.js +24 -0
- package/dist/esm/tiptap/TiptapEditorContent.js +99 -0
- package/dist/esm/tiptap/TiptapEditorView.js +76 -0
- package/dist/esm/tiptap/contexts/TiptapEditorContext.js +2 -0
- package/dist/esm/tiptap/extensions/ReactProseMirror.js +30 -0
- package/dist/esm/tiptap/extensions/ReactProseMirrorCommands.js +11 -0
- package/dist/esm/tiptap/extensions/commands/updateAttributes.js +96 -0
- package/dist/esm/tiptap/hooks/useEditor.js +308 -0
- package/dist/esm/tiptap/hooks/useIsInReactProseMirror.js +9 -0
- package/dist/esm/tiptap/hooks/useTiptapEditor.js +31 -0
- package/dist/esm/tiptap/hooks/useTiptapEditorEffect.js +42 -0
- package/dist/esm/tiptap/hooks/useTiptapEditorEventCallback.js +35 -0
- package/dist/esm/tiptap/index.js +9 -0
- package/dist/esm/tiptap/tiptapNodeView.js +211 -0
- package/dist/esm/viewdesc.js +844 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/AbstractEditorView.d.ts +28 -0
- package/dist/types/ReactEditorView.d.ts +102 -0
- package/dist/types/StaticEditorView.d.ts +26 -0
- package/dist/types/__tests__/viewdesc.test.d.ts +1 -0
- package/dist/types/browser.d.ts +15 -0
- package/dist/types/commands/__tests__/reorderSiblings.test.d.ts +1 -0
- package/dist/types/commands/reorderSiblings.d.ts +14 -0
- package/dist/types/components/ChildNodeViews.d.ts +9 -0
- package/dist/types/components/CursorWrapper.d.ts +3 -0
- package/dist/types/components/EditorStateSelectorsProvider.d.ts +10 -0
- package/dist/types/components/LayoutGroup.d.ts +12 -0
- package/dist/types/components/NativeWidgetView.d.ts +8 -0
- package/dist/types/components/OutputSpec.d.ts +10 -0
- package/dist/types/components/ProseMirror.d.ts +14 -0
- package/dist/types/components/ProseMirrorDoc.d.ts +16 -0
- package/dist/types/components/SeparatorHackView.d.ts +6 -0
- package/dist/types/components/TextNodeView.d.ts +27 -0
- package/dist/types/components/TrailingHackView.d.ts +6 -0
- package/dist/types/components/WidgetView.d.ts +8 -0
- package/dist/types/components/WidgetViewComponentProps.d.ts +7 -0
- package/dist/types/components/__tests__/ProseMirror.composition.test.d.ts +17 -0
- package/dist/types/components/__tests__/ProseMirror.domchange.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.draw-decoration.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.draw.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.memory-leak.test.d.ts +6 -0
- package/dist/types/components/__tests__/ProseMirror.mobile.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.node-view.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.selection.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.test.d.ts +1 -0
- package/dist/types/components/__tests__/stableContexts.test.d.ts +10 -0
- package/dist/types/components/marks/DefaultMarkView.d.ts +3 -0
- package/dist/types/components/marks/MarkView.d.ts +10 -0
- package/dist/types/components/marks/MarkViewComponentProps.d.ts +11 -0
- package/dist/types/components/marks/MarkViewConstructorView.d.ts +12 -0
- package/dist/types/components/marks/ReactMarkView.d.ts +12 -0
- package/dist/types/components/nodes/DefaultNodeView.d.ts +3 -0
- package/dist/types/components/nodes/DocNodeView.d.ts +12 -0
- package/dist/types/components/nodes/NodeView.d.ts +14 -0
- package/dist/types/components/nodes/NodeViewComponentProps.d.ts +13 -0
- package/dist/types/components/nodes/NodeViewConstructorView.d.ts +12 -0
- package/dist/types/components/nodes/ReactNodeView.d.ts +13 -0
- package/dist/types/constants.d.ts +4 -0
- package/dist/types/contexts/ChildDescriptionsContext.d.ts +7 -0
- package/dist/types/contexts/EditorContext.d.ts +18 -0
- package/dist/types/contexts/EditorStateContext.d.ts +2 -0
- package/dist/types/contexts/EditorStateStoreContext.d.ts +9 -0
- package/dist/types/contexts/IgnoreMutationContext.d.ts +5 -0
- package/dist/types/contexts/LayoutGroupContext.d.ts +5 -0
- package/dist/types/contexts/NodeViewContext.d.ts +9 -0
- package/dist/types/contexts/RenderStoreContext.d.ts +24 -0
- package/dist/types/contexts/SelectNodeContext.d.ts +5 -0
- package/dist/types/contexts/StopEventContext.d.ts +5 -0
- package/dist/types/contexts/__tests__/DeferredLayoutEffects.test.d.ts +1 -0
- package/dist/types/decorations/ReactWidgetType.d.ts +40 -0
- package/dist/types/decorations/computeDocDeco.d.ts +14 -0
- package/dist/types/decorations/internalTypes.d.ts +20 -0
- package/dist/types/decorations/iterDeco.d.ts +3 -0
- package/dist/types/decorations/viewDecorations.d.ts +14 -0
- package/dist/types/dom.d.ts +22 -0
- package/dist/types/findDOMNode.d.ts +3 -0
- package/dist/types/hooks/__tests__/useEditorEffect.test.d.ts +1 -0
- package/dist/types/hooks/useClientLayoutEffect.d.ts +2 -0
- package/dist/types/hooks/useComponentEventListeners.d.ts +34 -0
- package/dist/types/hooks/useEditor.d.ts +37 -0
- package/dist/types/hooks/useEditorEffect.d.ts +21 -0
- package/dist/types/hooks/useEditorEventCallback.d.ts +13 -0
- package/dist/types/hooks/useEditorEventListener.d.ts +8 -0
- package/dist/types/hooks/useEditorState.d.ts +5 -0
- package/dist/types/hooks/useEditorStateSelector.d.ts +10 -0
- package/dist/types/hooks/useEffectEvent.d.ts +1 -0
- package/dist/types/hooks/useForceUpdate.d.ts +5 -0
- package/dist/types/hooks/useIgnoreMutation.d.ts +2 -0
- package/dist/types/hooks/useIsComposingIn.d.ts +4 -0
- package/dist/types/hooks/useIsEditorStatic.d.ts +5 -0
- package/dist/types/hooks/useIsNodeSelected.d.ts +1 -0
- package/dist/types/hooks/useLayoutGroupEffect.d.ts +3 -0
- package/dist/types/hooks/useMarkViewDescription.d.ts +15 -0
- package/dist/types/hooks/useNodePos.d.ts +9 -0
- package/dist/types/hooks/useNodeViewDescription.d.ts +16 -0
- package/dist/types/hooks/useReactKeys.d.ts +2 -0
- package/dist/types/hooks/useSelectNode.d.ts +2 -0
- package/dist/types/hooks/useSetDom.d.ts +2 -0
- package/dist/types/hooks/useStopEvent.d.ts +2 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/plugins/__tests__/reactKeys.test.d.ts +1 -0
- package/dist/types/plugins/beforeInputPlugin.d.ts +2 -0
- package/dist/types/plugins/reactKeys.d.ts +23 -0
- package/dist/types/props.d.ts +1173 -0
- package/dist/types/refs.d.ts +2 -0
- package/dist/types/testing/editorViewTestHelpers.d.ts +24 -0
- package/dist/types/testing/setupProseMirrorView.d.ts +2 -0
- package/dist/types/tiptap/ReactProseMirrorNodeView.d.ts +15 -0
- package/dist/types/tiptap/TiptapEditor.d.ts +6 -0
- package/dist/types/tiptap/TiptapEditorContent.d.ts +28 -0
- package/dist/types/tiptap/TiptapEditorView.d.ts +16 -0
- package/dist/types/tiptap/contexts/TiptapEditorContext.d.ts +6 -0
- package/dist/types/tiptap/extensions/ReactProseMirror.d.ts +9 -0
- package/dist/types/tiptap/extensions/ReactProseMirrorCommands.d.ts +2 -0
- package/dist/types/tiptap/extensions/commands/updateAttributes.d.ts +24 -0
- package/dist/types/tiptap/hooks/useEditor.d.ts +38 -0
- package/dist/types/tiptap/hooks/useIsInReactProseMirror.d.ts +6 -0
- package/dist/types/tiptap/hooks/useTiptapEditor.d.ts +11 -0
- package/dist/types/tiptap/hooks/useTiptapEditorEffect.d.ts +21 -0
- package/dist/types/tiptap/hooks/useTiptapEditorEventCallback.d.ts +13 -0
- package/dist/types/tiptap/index.d.ts +9 -0
- package/dist/types/tiptap/tiptapNodeView.d.ts +50 -0
- package/dist/types/viewdesc.d.ts +179 -0
- package/package.json +167 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
2
|
+
export function useEffectEvent(fn) {
|
|
3
|
+
const ref = useRef(fn);
|
|
4
|
+
// Ideally this would be a useInsertionEffect, but
|
|
5
|
+
// that was introduced in React 18 and we still
|
|
6
|
+
// support React 17. useLayoutEffect is safe
|
|
7
|
+
// here as long as the function returned by
|
|
8
|
+
// useEffectEvent isn't called in a layout effect
|
|
9
|
+
// that's defined _before_ the useEffectEvent
|
|
10
|
+
// call, and effect events are never passed
|
|
11
|
+
// to child components.
|
|
12
|
+
useLayoutEffect(()=>{
|
|
13
|
+
ref.current = fn;
|
|
14
|
+
}, [
|
|
15
|
+
fn
|
|
16
|
+
]);
|
|
17
|
+
return useCallback(function() {
|
|
18
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
19
|
+
args[_key] = arguments[_key];
|
|
20
|
+
}
|
|
21
|
+
const f = ref.current;
|
|
22
|
+
return f(...args);
|
|
23
|
+
}, []);
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* Copyright (c) The New York Times Company */ import { useReducer } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Provides a function that forces an update of the
|
|
4
|
+
* component.
|
|
5
|
+
*/ export function useForceUpdate() {
|
|
6
|
+
const [, forceUpdate] = useReducer((x)=>x + 1, 0);
|
|
7
|
+
return forceUpdate;
|
|
8
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { IgnoreMutationContext } from "../contexts/IgnoreMutationContext.js";
|
|
3
|
+
import { useEditorEffect } from "./useEditorEffect.js";
|
|
4
|
+
import { useEditorEventCallback } from "./useEditorEventCallback.js";
|
|
5
|
+
export function useIgnoreMutation(ignoreMutation) {
|
|
6
|
+
const register = useContext(IgnoreMutationContext);
|
|
7
|
+
const ignoreMutationMemo = useEditorEventCallback(ignoreMutation);
|
|
8
|
+
useEditorEffect(()=>{
|
|
9
|
+
return register(ignoreMutationMemo);
|
|
10
|
+
}, [
|
|
11
|
+
register,
|
|
12
|
+
ignoreMutationMemo
|
|
13
|
+
]);
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useContext, useState } from "react";
|
|
2
|
+
import { GetPosContext } from "../components/nodes/NodeView.js";
|
|
3
|
+
import { useEditorEventListener } from "../index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Returns true while an IME composition is active inside the current node.
|
|
6
|
+
*/ export function useIsComposingIn() {
|
|
7
|
+
const [isComposing, setIsComposing] = useState(false);
|
|
8
|
+
const getPos = useContext(GetPosContext);
|
|
9
|
+
useEditorEventListener("compositionstart", (view)=>{
|
|
10
|
+
const compositionRoot = view.state.selection.$from.before();
|
|
11
|
+
setIsComposing(compositionRoot === getPos());
|
|
12
|
+
});
|
|
13
|
+
useEditorEventListener("compositionend", ()=>{
|
|
14
|
+
setIsComposing(false);
|
|
15
|
+
});
|
|
16
|
+
return isComposing;
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { EditorContext } from "../contexts/EditorContext.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the nearest ProseMirror component
|
|
5
|
+
* is rendered with the `static` prop set to `true`.
|
|
6
|
+
*/ export function useIsEditorStatic() {
|
|
7
|
+
return useContext(EditorContext)?.isStatic ?? false;
|
|
8
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { useSelectNode } from "./useSelectNode.js";
|
|
3
|
+
export function useIsNodeSelected() {
|
|
4
|
+
const [isSelected, setIsSelected] = useState(false);
|
|
5
|
+
useSelectNode(()=>{
|
|
6
|
+
setIsSelected(true);
|
|
7
|
+
}, ()=>{
|
|
8
|
+
setIsSelected(false);
|
|
9
|
+
});
|
|
10
|
+
return isSelected;
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* Copyright (c) The New York Times Company */ import { useContext } from "react";
|
|
2
|
+
import { LayoutGroupContext } from "../contexts/LayoutGroupContext.js";
|
|
3
|
+
import { useClientLayoutEffect } from "./useClientLayoutEffect.js";
|
|
4
|
+
/** Registers a layout effect to run at the nearest `LayoutGroup` boundary. */ export function useLayoutGroupEffect(effect, deps) {
|
|
5
|
+
const register = useContext(LayoutGroupContext);
|
|
6
|
+
// The rule for hooks wants to statically verify the deps,
|
|
7
|
+
// but the dependencies are up to the caller, not this implementation.
|
|
8
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
9
|
+
useClientLayoutEffect(()=>register(effect), deps);
|
|
10
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { useCallback, useContext, useMemo, useRef } from "react";
|
|
2
|
+
import { ReactEditorView } from "../ReactEditorView.js";
|
|
3
|
+
import { ChildDescriptionsContext } from "../contexts/ChildDescriptionsContext.js";
|
|
4
|
+
import { EditorContext } from "../contexts/EditorContext.js";
|
|
5
|
+
import { ReactMarkViewDesc, placeViewDesc } from "../viewdesc.js";
|
|
6
|
+
import { useClientLayoutEffect } from "./useClientLayoutEffect.js";
|
|
7
|
+
import { useEffectEvent } from "./useEffectEvent.js";
|
|
8
|
+
export function useMarkViewDescription(getDOM, getContentDOM, constructor, props) {
|
|
9
|
+
const mountedRef = useRef(false);
|
|
10
|
+
const { view } = useContext(EditorContext);
|
|
11
|
+
const { parentRef, siblingsRef } = useContext(ChildDescriptionsContext);
|
|
12
|
+
const contentDOMRef = useRef(null);
|
|
13
|
+
const viewDescRef = useRef();
|
|
14
|
+
const childrenRef = useRef([]);
|
|
15
|
+
const create = useEffectEvent(()=>{
|
|
16
|
+
if (!(view instanceof ReactEditorView)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const dom = getDOM();
|
|
20
|
+
if (!dom) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const { mark, inline, getPos } = props;
|
|
24
|
+
const markView = constructor(mark, view, inline);
|
|
25
|
+
if (!markView) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const parent = parentRef.current;
|
|
29
|
+
const children = childrenRef.current;
|
|
30
|
+
const contentDOM = getContentDOM(markView);
|
|
31
|
+
const viewDesc = new ReactMarkViewDesc(parent, children, getPos, mark, dom, contentDOM ?? markView.dom, markView);
|
|
32
|
+
// When create() runs after a destroy() (either here in a layout
|
|
33
|
+
// effect or in refUpdated), the inherited children still reference
|
|
34
|
+
// the just-destroyed desc. Re-parent them onto this fresh desc
|
|
35
|
+
// before any other code can observe the stale pointer.
|
|
36
|
+
for (const child of children){
|
|
37
|
+
child.parent = viewDesc;
|
|
38
|
+
}
|
|
39
|
+
contentDOMRef.current = contentDOM;
|
|
40
|
+
return viewDesc;
|
|
41
|
+
});
|
|
42
|
+
const update = useEffectEvent(()=>{
|
|
43
|
+
if (!(view instanceof ReactEditorView)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const viewDesc = viewDescRef.current;
|
|
47
|
+
if (!viewDesc) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const dom = getDOM();
|
|
51
|
+
if (!dom || dom !== viewDesc.dom) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
const contentDOM = getContentDOM(viewDesc);
|
|
55
|
+
if (contentDOM !== (viewDesc.contentDOM ?? dom)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const { mark } = props;
|
|
59
|
+
return viewDesc.matchesMark(mark);
|
|
60
|
+
});
|
|
61
|
+
const destroy = useEffectEvent(()=>{
|
|
62
|
+
const viewDesc = viewDescRef.current;
|
|
63
|
+
if (!viewDesc) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
viewDescRef.current = undefined;
|
|
67
|
+
viewDesc.destroy();
|
|
68
|
+
const siblings = siblingsRef.current;
|
|
69
|
+
if (siblings.includes(viewDesc)) {
|
|
70
|
+
const index = siblings.indexOf(viewDesc);
|
|
71
|
+
siblings.splice(index, 1);
|
|
72
|
+
}
|
|
73
|
+
contentDOMRef.current = null;
|
|
74
|
+
});
|
|
75
|
+
useClientLayoutEffect(()=>{
|
|
76
|
+
mountedRef.current = true;
|
|
77
|
+
viewDescRef.current = create();
|
|
78
|
+
return ()=>{
|
|
79
|
+
mountedRef.current = false;
|
|
80
|
+
destroy();
|
|
81
|
+
};
|
|
82
|
+
}, [
|
|
83
|
+
create,
|
|
84
|
+
destroy
|
|
85
|
+
]);
|
|
86
|
+
const refUpdated = useCallback(()=>{
|
|
87
|
+
if (!mountedRef.current) return;
|
|
88
|
+
if (!update()) {
|
|
89
|
+
destroy();
|
|
90
|
+
viewDescRef.current = create();
|
|
91
|
+
}
|
|
92
|
+
}, [
|
|
93
|
+
create,
|
|
94
|
+
destroy,
|
|
95
|
+
update
|
|
96
|
+
]);
|
|
97
|
+
useClientLayoutEffect(()=>{
|
|
98
|
+
if (!update()) {
|
|
99
|
+
destroy();
|
|
100
|
+
viewDescRef.current = create();
|
|
101
|
+
}
|
|
102
|
+
const viewDesc = viewDescRef.current;
|
|
103
|
+
if (!viewDesc) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const parent = parentRef.current;
|
|
107
|
+
const siblings = siblingsRef.current;
|
|
108
|
+
const children = childrenRef.current;
|
|
109
|
+
viewDesc.parent = parent;
|
|
110
|
+
placeViewDesc(siblings, viewDesc);
|
|
111
|
+
for (const child of children){
|
|
112
|
+
child.parent = viewDesc;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
const childContextValue = useMemo(()=>({
|
|
116
|
+
parentRef: viewDescRef,
|
|
117
|
+
siblingsRef: childrenRef
|
|
118
|
+
}), []);
|
|
119
|
+
return {
|
|
120
|
+
childContextValue,
|
|
121
|
+
contentDOM: contentDOMRef.current ?? viewDescRef.current?.dom,
|
|
122
|
+
refUpdated
|
|
123
|
+
};
|
|
124
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { GetPosContext } from "../components/nodes/NodeView.js";
|
|
3
|
+
import { useEditorState } from "./useEditorState.js";
|
|
4
|
+
/**
|
|
5
|
+
* Get this node's current position in the document.
|
|
6
|
+
*
|
|
7
|
+
* Using this hook will subscribe this node to the
|
|
8
|
+
* EditorState, which means that it will be re-rendered
|
|
9
|
+
* on every EditorState update. This may have performance
|
|
10
|
+
* implications for large documents.
|
|
11
|
+
*/ export function useNodePos() {
|
|
12
|
+
useEditorState();
|
|
13
|
+
const getPos = useContext(GetPosContext);
|
|
14
|
+
return getPos();
|
|
15
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { useCallback, useContext, useMemo, useRef } from "react";
|
|
2
|
+
import { ReactEditorView } from "../ReactEditorView.js";
|
|
3
|
+
import { ChildDescriptionsContext } from "../contexts/ChildDescriptionsContext.js";
|
|
4
|
+
import { EditorContext } from "../contexts/EditorContext.js";
|
|
5
|
+
import { ReactNodeViewDesc, placeViewDesc, sortViewDescs } from "../viewdesc.js";
|
|
6
|
+
import { useClientLayoutEffect } from "./useClientLayoutEffect.js";
|
|
7
|
+
import { useEffectEvent } from "./useEffectEvent.js";
|
|
8
|
+
export function useNodeViewDescription(getDOM, getContentDOM, constructor, props) {
|
|
9
|
+
const mountedRef = useRef(false);
|
|
10
|
+
const { view } = useContext(EditorContext);
|
|
11
|
+
const { parentRef, siblingsRef } = useContext(ChildDescriptionsContext);
|
|
12
|
+
const contentDOMRef = useRef(null);
|
|
13
|
+
const viewDescRef = useRef();
|
|
14
|
+
const childrenRef = useRef([]);
|
|
15
|
+
const create = useEffectEvent(()=>{
|
|
16
|
+
if (!(view instanceof ReactEditorView)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const dom = getDOM();
|
|
20
|
+
if (!dom) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const { node, getPos, decorations, innerDecorations } = props;
|
|
24
|
+
const nodeView = constructor(node, view, getPos, decorations, innerDecorations);
|
|
25
|
+
if (!nodeView) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const parent = parentRef.current;
|
|
29
|
+
const children = childrenRef.current;
|
|
30
|
+
const contentDOM = getContentDOM(nodeView);
|
|
31
|
+
const nodeDOM = nodeView.dom;
|
|
32
|
+
const viewDesc = new ReactNodeViewDesc(parent, children, getPos, node, decorations, innerDecorations, dom, contentDOM, nodeDOM, nodeView);
|
|
33
|
+
for (const child of children){
|
|
34
|
+
child.parent = viewDesc;
|
|
35
|
+
}
|
|
36
|
+
placeViewDesc(siblingsRef.current, viewDesc);
|
|
37
|
+
contentDOMRef.current = getContentDOM(nodeView);
|
|
38
|
+
return viewDesc;
|
|
39
|
+
});
|
|
40
|
+
const update = useEffectEvent(()=>{
|
|
41
|
+
if (!(view instanceof ReactEditorView)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const viewDesc = viewDescRef.current;
|
|
45
|
+
if (!viewDesc) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const dom = getDOM();
|
|
49
|
+
if (!dom || dom !== viewDesc.dom) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
const contentDOM = getContentDOM(viewDesc);
|
|
53
|
+
if (contentDOM !== viewDesc.contentDOM) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (!dom.contains(viewDesc.nodeDOM)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const { node, decorations, innerDecorations } = props;
|
|
60
|
+
return viewDesc.matchesNode(node, decorations, innerDecorations) || viewDesc.update(node, decorations, innerDecorations, view);
|
|
61
|
+
});
|
|
62
|
+
const destroy = useEffectEvent(()=>{
|
|
63
|
+
const viewDesc = viewDescRef.current;
|
|
64
|
+
if (!viewDesc) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
viewDescRef.current = undefined;
|
|
68
|
+
viewDesc.destroy();
|
|
69
|
+
const siblings = siblingsRef.current;
|
|
70
|
+
if (siblings.includes(viewDesc)) {
|
|
71
|
+
const index = siblings.indexOf(viewDesc);
|
|
72
|
+
siblings.splice(index, 1);
|
|
73
|
+
}
|
|
74
|
+
contentDOMRef.current = null;
|
|
75
|
+
});
|
|
76
|
+
useClientLayoutEffect(()=>{
|
|
77
|
+
mountedRef.current = true;
|
|
78
|
+
viewDescRef.current = create();
|
|
79
|
+
return ()=>{
|
|
80
|
+
mountedRef.current = false;
|
|
81
|
+
destroy();
|
|
82
|
+
};
|
|
83
|
+
}, [
|
|
84
|
+
create,
|
|
85
|
+
destroy
|
|
86
|
+
]);
|
|
87
|
+
const refUpdated = useCallback(()=>{
|
|
88
|
+
if (!mountedRef.current) return;
|
|
89
|
+
if (!update()) {
|
|
90
|
+
destroy();
|
|
91
|
+
viewDescRef.current = create();
|
|
92
|
+
}
|
|
93
|
+
}, [
|
|
94
|
+
create,
|
|
95
|
+
destroy,
|
|
96
|
+
update
|
|
97
|
+
]);
|
|
98
|
+
useClientLayoutEffect(()=>{
|
|
99
|
+
if (!update()) {
|
|
100
|
+
destroy();
|
|
101
|
+
viewDescRef.current = create();
|
|
102
|
+
}
|
|
103
|
+
const viewDesc = viewDescRef.current;
|
|
104
|
+
if (!viewDesc) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (view.dom === viewDesc.dom && view instanceof ReactEditorView) {
|
|
108
|
+
view.docView = viewDesc;
|
|
109
|
+
}
|
|
110
|
+
const parent = parentRef.current;
|
|
111
|
+
const siblings = siblingsRef.current;
|
|
112
|
+
const children = childrenRef.current;
|
|
113
|
+
viewDesc.parent = parent;
|
|
114
|
+
// In strict/concurrent mode, a node can sometimes re-render
|
|
115
|
+
// entirely on its own, without even its parent re-rendering.
|
|
116
|
+
// In this case, we will have added our view descriptions to
|
|
117
|
+
// our parent's children, but our parent has no opportunity
|
|
118
|
+
// to sort its children, because it never renders. So
|
|
119
|
+
// we always place ourselves among our siblings, too.
|
|
120
|
+
placeViewDesc(siblings, viewDesc);
|
|
121
|
+
// If a child updates, usually it will re-render and sort
|
|
122
|
+
// our children for us. But it's possible to reorder
|
|
123
|
+
// child nodes without changing their keys or node
|
|
124
|
+
// instances, in which case our children _won't_
|
|
125
|
+
// rerender. As a fallback, we do one last pass through
|
|
126
|
+
// our own child view descriptions and make sure
|
|
127
|
+
// they're ordered. This should be a cheap no-op in most cases.
|
|
128
|
+
children.sort(sortViewDescs);
|
|
129
|
+
for (const child of children){
|
|
130
|
+
child.parent = viewDesc;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const childContextValue = useMemo(()=>({
|
|
134
|
+
parentRef: viewDescRef,
|
|
135
|
+
siblingsRef: childrenRef
|
|
136
|
+
}), []);
|
|
137
|
+
const isMounted = useCallback(()=>mountedRef.current, []);
|
|
138
|
+
return {
|
|
139
|
+
childContextValue,
|
|
140
|
+
contentDOM: contentDOMRef.current,
|
|
141
|
+
refUpdated,
|
|
142
|
+
isMounted
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { EditorContext } from "../contexts/EditorContext.js";
|
|
3
|
+
import { reactKeysPluginKey } from "../plugins/reactKeys.js";
|
|
4
|
+
export function useReactKeys() {
|
|
5
|
+
const { view } = useContext(EditorContext);
|
|
6
|
+
return reactKeysPluginKey.getState(view.state);
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { SelectNodeContext } from "../contexts/SelectNodeContext.js";
|
|
3
|
+
import { useEditorEffect } from "./useEditorEffect.js";
|
|
4
|
+
import { useEditorEventCallback } from "./useEditorEventCallback.js";
|
|
5
|
+
function noop() {
|
|
6
|
+
// empty
|
|
7
|
+
}
|
|
8
|
+
export function useSelectNode(selectNode) {
|
|
9
|
+
let deselectNode = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
10
|
+
const register = useContext(SelectNodeContext);
|
|
11
|
+
const selectNodeMemo = useEditorEventCallback(selectNode);
|
|
12
|
+
const deselectNodeMemo = useEditorEventCallback(deselectNode);
|
|
13
|
+
return useEditorEffect(()=>{
|
|
14
|
+
return register(selectNodeMemo, deselectNodeMemo);
|
|
15
|
+
}, [
|
|
16
|
+
register,
|
|
17
|
+
selectNodeMemo,
|
|
18
|
+
deselectNodeMemo
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useCallback, useRef } from "react";
|
|
2
|
+
export function useSetDom(domRef, refUpdated, isMounted, forceUpdate) {
|
|
3
|
+
const pendingRef = useRef(false);
|
|
4
|
+
return useCallback((el)=>{
|
|
5
|
+
if (el !== null) {
|
|
6
|
+
pendingRef.current = false;
|
|
7
|
+
const changed = domRef.current !== el;
|
|
8
|
+
domRef.current = el;
|
|
9
|
+
if (changed) forceUpdate?.();
|
|
10
|
+
refUpdated();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (pendingRef.current) return;
|
|
14
|
+
pendingRef.current = true;
|
|
15
|
+
// React calls old ref callbacks with
|
|
16
|
+
// null before synchronously calling
|
|
17
|
+
// new ref callbacks with the existing
|
|
18
|
+
// element ref. We don't have any
|
|
19
|
+
// way to distinguish a call with null
|
|
20
|
+
// because the downstream callback is
|
|
21
|
+
// unstable and being replaced during render
|
|
22
|
+
// from a call with null because the referenced
|
|
23
|
+
// element has been unmounted.
|
|
24
|
+
//
|
|
25
|
+
// Since the ref callback calls are synchronous,
|
|
26
|
+
// we can queue a microtask and check
|
|
27
|
+
// whether the ref is still null at
|
|
28
|
+
// the end of this event loop task. If it
|
|
29
|
+
// is, we actually unmounted. If it's not,
|
|
30
|
+
// we already handled it in the synchronous
|
|
31
|
+
// branch above, so we just bail.
|
|
32
|
+
queueMicrotask(()=>{
|
|
33
|
+
if (!pendingRef.current) return;
|
|
34
|
+
pendingRef.current = false;
|
|
35
|
+
if (domRef.current !== null) {
|
|
36
|
+
domRef.current = null;
|
|
37
|
+
if (isMounted?.()) forceUpdate?.();
|
|
38
|
+
}
|
|
39
|
+
refUpdated();
|
|
40
|
+
});
|
|
41
|
+
}, [
|
|
42
|
+
domRef,
|
|
43
|
+
forceUpdate,
|
|
44
|
+
isMounted,
|
|
45
|
+
refUpdated
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { StopEventContext } from "../contexts/StopEventContext.js";
|
|
3
|
+
import { useEditorEffect } from "./useEditorEffect.js";
|
|
4
|
+
import { useEditorEventCallback } from "./useEditorEventCallback.js";
|
|
5
|
+
export function useStopEvent(stopEvent) {
|
|
6
|
+
const register = useContext(StopEventContext);
|
|
7
|
+
const stopEventMemo = useEditorEventCallback(stopEvent);
|
|
8
|
+
useEditorEffect(()=>{
|
|
9
|
+
return register(stopEventMemo);
|
|
10
|
+
}, [
|
|
11
|
+
register,
|
|
12
|
+
stopEventMemo
|
|
13
|
+
]);
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* Copyright (c) The New York Times Company */ "use client";
|
|
2
|
+
export { ProseMirror } from "./components/ProseMirror.js";
|
|
3
|
+
export { ProseMirrorDoc } from "./components/ProseMirrorDoc.js";
|
|
4
|
+
export { reorderSiblings } from "./commands/reorderSiblings.js";
|
|
5
|
+
export { useIsComposingIn } from "./hooks/useIsComposingIn.js";
|
|
6
|
+
export { useEditorEffect } from "./hooks/useEditorEffect.js";
|
|
7
|
+
export { useEditorEventCallback } from "./hooks/useEditorEventCallback.js";
|
|
8
|
+
export { useEditorEventListener } from "./hooks/useEditorEventListener.js";
|
|
9
|
+
export { useEditorState } from "./hooks/useEditorState.js";
|
|
10
|
+
export { useNodePos } from "./hooks/useNodePos.js";
|
|
11
|
+
export { useEditorStateSelector } from "./hooks/useEditorStateSelector.js";
|
|
12
|
+
export { useStopEvent } from "./hooks/useStopEvent.js";
|
|
13
|
+
export { useSelectNode } from "./hooks/useSelectNode.js";
|
|
14
|
+
export { useIgnoreMutation } from "./hooks/useIgnoreMutation.js";
|
|
15
|
+
export { useIsEditorStatic } from "./hooks/useIsEditorStatic.js";
|
|
16
|
+
export { useIsNodeSelected } from "./hooks/useIsNodeSelected.js";
|
|
17
|
+
export { reactKeys } from "./plugins/reactKeys.js";
|
|
18
|
+
export { widget } from "./decorations/ReactWidgetType.js";
|
|
19
|
+
export { useMergedDOMRefs } from "./refs.js";
|