@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,30 @@
|
|
|
1
|
+
import { Extension } from "@tiptap/core";
|
|
2
|
+
import { reorderSiblingsOnTransaction } from "../../commands/reorderSiblings.js";
|
|
3
|
+
import { reactKeys } from "../../plugins/reactKeys.js";
|
|
4
|
+
export const ReactProseMirror = Extension.create({
|
|
5
|
+
name: "@handlewithcare/react-prosemirror/reactKeys",
|
|
6
|
+
addProseMirrorPlugins () {
|
|
7
|
+
return [
|
|
8
|
+
reactKeys()
|
|
9
|
+
];
|
|
10
|
+
},
|
|
11
|
+
addCommands () {
|
|
12
|
+
return {
|
|
13
|
+
/**
|
|
14
|
+
* Command that reorders the adjacent nodes starting
|
|
15
|
+
* at the provided position.
|
|
16
|
+
*
|
|
17
|
+
* @param pos - The `start` position of the parent of the nodes being reordered
|
|
18
|
+
* @param order - The new order for the nodes, expressed as an array of indices. For
|
|
19
|
+
* example, to swap the first two nodes in a set of three, `order`
|
|
20
|
+
* would be set to `[1, 0, 2]`. To move the first node to the end,
|
|
21
|
+
* and keep the other two in relative order, set `order` to `[1, 2, 0]`.
|
|
22
|
+
*/ reorderSiblings (initialPos, order) {
|
|
23
|
+
return function reorderSiblingsCommand(param) {
|
|
24
|
+
let { tr, state, dispatch } = param;
|
|
25
|
+
return reorderSiblingsOnTransaction(initialPos, order, tr, state, dispatch);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Extension, commands as coreCommands } from "@tiptap/core";
|
|
2
|
+
import { updateAttributes } from "./commands/updateAttributes.js";
|
|
3
|
+
export const ReactProseMirrorCommands = Extension.create({
|
|
4
|
+
name: "reactProseMirrorCommands",
|
|
5
|
+
addCommands () {
|
|
6
|
+
return {
|
|
7
|
+
...coreCommands,
|
|
8
|
+
updateAttributes
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { getMarkType, getNodeType, getSchemaTypeNameByName } from "@tiptap/core";
|
|
2
|
+
// Tiptap's updateAttributes command, but using setNodeAttribute instead of
|
|
3
|
+
// setNodeMarkup to avoid replacing entire leaf nodes
|
|
4
|
+
export const updateAttributes = function(typeOrName) {
|
|
5
|
+
let attributes = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
6
|
+
return (param)=>{
|
|
7
|
+
let { tr, state, dispatch } = param;
|
|
8
|
+
let nodeType = null;
|
|
9
|
+
let markType = null;
|
|
10
|
+
const schemaType = getSchemaTypeNameByName(typeof typeOrName === "string" ? typeOrName : typeOrName.name, state.schema);
|
|
11
|
+
if (!schemaType) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (schemaType === "node") {
|
|
15
|
+
nodeType = getNodeType(typeOrName, state.schema);
|
|
16
|
+
}
|
|
17
|
+
if (schemaType === "mark") {
|
|
18
|
+
markType = getMarkType(typeOrName, state.schema);
|
|
19
|
+
}
|
|
20
|
+
let canUpdate = false;
|
|
21
|
+
tr.selection.ranges.forEach((range)=>{
|
|
22
|
+
const from = range.$from.pos;
|
|
23
|
+
const to = range.$to.pos;
|
|
24
|
+
let lastPos;
|
|
25
|
+
let lastNode;
|
|
26
|
+
let trimmedFrom;
|
|
27
|
+
let trimmedTo;
|
|
28
|
+
if (tr.selection.empty) {
|
|
29
|
+
state.doc.nodesBetween(from, to, (node, pos)=>{
|
|
30
|
+
if (nodeType && nodeType === node.type) {
|
|
31
|
+
canUpdate = true;
|
|
32
|
+
trimmedFrom = Math.max(pos, from);
|
|
33
|
+
trimmedTo = Math.min(pos + node.nodeSize, to);
|
|
34
|
+
lastPos = pos;
|
|
35
|
+
lastNode = node;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
state.doc.nodesBetween(from, to, (node, pos)=>{
|
|
40
|
+
if (pos < from && nodeType && nodeType === node.type) {
|
|
41
|
+
canUpdate = true;
|
|
42
|
+
trimmedFrom = Math.max(pos, from);
|
|
43
|
+
trimmedTo = Math.min(pos + node.nodeSize, to);
|
|
44
|
+
lastPos = pos;
|
|
45
|
+
lastNode = node;
|
|
46
|
+
}
|
|
47
|
+
if (pos >= from && pos <= to) {
|
|
48
|
+
if (nodeType && nodeType === node.type) {
|
|
49
|
+
canUpdate = true;
|
|
50
|
+
if (dispatch) {
|
|
51
|
+
Object.entries(attributes).forEach((param)=>{
|
|
52
|
+
let [key, value] = param;
|
|
53
|
+
tr.setNodeAttribute(pos, key, value);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (markType && node.marks.length) {
|
|
58
|
+
node.marks.forEach((mark)=>{
|
|
59
|
+
if (markType === mark.type) {
|
|
60
|
+
canUpdate = true;
|
|
61
|
+
if (dispatch) {
|
|
62
|
+
const trimmedFrom2 = Math.max(pos, from);
|
|
63
|
+
const trimmedTo2 = Math.min(pos + node.nodeSize, to);
|
|
64
|
+
tr.addMark(trimmedFrom2, trimmedTo2, markType.create({
|
|
65
|
+
...mark.attrs,
|
|
66
|
+
...attributes
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (lastNode) {
|
|
76
|
+
if (dispatch) {
|
|
77
|
+
Object.entries(attributes).forEach((param)=>{
|
|
78
|
+
let [key, value] = param;
|
|
79
|
+
if (lastPos !== undefined) tr.setNodeAttribute(lastPos, key, value);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (markType && lastNode.marks.length) {
|
|
83
|
+
lastNode.marks.forEach((mark)=>{
|
|
84
|
+
if (markType === mark.type && dispatch) {
|
|
85
|
+
tr.addMark(trimmedFrom, trimmedTo, markType.create({
|
|
86
|
+
...mark.attrs,
|
|
87
|
+
...attributes
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return canUpdate;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
// Forked from Tiptap's useEditor hook, with modifications to support
|
|
2
|
+
// server-side rendering
|
|
3
|
+
import { Editor } from "@tiptap/core";
|
|
4
|
+
import { useDebugValue, useEffect, useRef, useState } from "react";
|
|
5
|
+
import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
|
|
6
|
+
import { StaticEditorView } from "../../StaticEditorView.js";
|
|
7
|
+
let ReactEditor = class ReactEditor extends Editor {
|
|
8
|
+
constructor(options){
|
|
9
|
+
super(options);
|
|
10
|
+
// @ts-expect-error Internal property
|
|
11
|
+
this.editorView = new StaticEditorView({
|
|
12
|
+
// @ts-expect-error Internal property
|
|
13
|
+
state: this.editorState.reconfigure({
|
|
14
|
+
plugins: this.extensionManager.plugins
|
|
15
|
+
}),
|
|
16
|
+
...this.options.editorProps,
|
|
17
|
+
attributes: {
|
|
18
|
+
role: "textbox",
|
|
19
|
+
...this.options.editorProps.attributes
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* This class handles the creation, destruction, and re-creation of the editor instance.
|
|
26
|
+
*/ let EditorInstanceManager = class EditorInstanceManager {
|
|
27
|
+
/**
|
|
28
|
+
* The current editor instance.
|
|
29
|
+
*/ editor = null;
|
|
30
|
+
/**
|
|
31
|
+
* The most recent options to apply to the editor.
|
|
32
|
+
*/ options;
|
|
33
|
+
/**
|
|
34
|
+
* The subscriptions to notify when the editor instance
|
|
35
|
+
* has been created or destroyed.
|
|
36
|
+
*/ subscriptions = new Set();
|
|
37
|
+
/**
|
|
38
|
+
* A timeout to destroy the editor if it was not mounted within a time frame.
|
|
39
|
+
*/ scheduledDestructionTimeout;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the editor has been mounted.
|
|
42
|
+
*/ isComponentMounted = false;
|
|
43
|
+
/**
|
|
44
|
+
* The most recent dependencies array.
|
|
45
|
+
*/ previousDeps = null;
|
|
46
|
+
/**
|
|
47
|
+
* The unique instance ID. This is used to identify the editor instance. And will be re-generated for each new instance.
|
|
48
|
+
*/ instanceId = "";
|
|
49
|
+
constructor(options){
|
|
50
|
+
this.options = options;
|
|
51
|
+
this.subscriptions = new Set();
|
|
52
|
+
this.setEditor(this.createEditor());
|
|
53
|
+
this.scheduleDestroy();
|
|
54
|
+
this.getEditor = this.getEditor.bind(this);
|
|
55
|
+
this.getServerSnapshot = this.getServerSnapshot.bind(this);
|
|
56
|
+
this.subscribe = this.subscribe.bind(this);
|
|
57
|
+
this.refreshEditorInstance = this.refreshEditorInstance.bind(this);
|
|
58
|
+
this.scheduleDestroy = this.scheduleDestroy.bind(this);
|
|
59
|
+
this.onRender = this.onRender.bind(this);
|
|
60
|
+
this.createEditor = this.createEditor.bind(this);
|
|
61
|
+
}
|
|
62
|
+
setEditor(editor) {
|
|
63
|
+
this.editor = editor;
|
|
64
|
+
this.instanceId = Math.random().toString(36).slice(2, 9);
|
|
65
|
+
// Notify all subscribers that the editor instance has been created
|
|
66
|
+
this.subscriptions.forEach((cb)=>cb());
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Create a new editor instance. And attach event listeners.
|
|
70
|
+
*/ createEditor() {
|
|
71
|
+
var _this = this;
|
|
72
|
+
const optionsToApply = {
|
|
73
|
+
...this.options.current,
|
|
74
|
+
// Always call the most recent version of the callback function by default
|
|
75
|
+
onBeforeCreate: function() {
|
|
76
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
77
|
+
args[_key] = arguments[_key];
|
|
78
|
+
}
|
|
79
|
+
return _this.options.current.onBeforeCreate?.(...args);
|
|
80
|
+
},
|
|
81
|
+
onBlur: function() {
|
|
82
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
83
|
+
args[_key] = arguments[_key];
|
|
84
|
+
}
|
|
85
|
+
return _this.options.current.onBlur?.(...args);
|
|
86
|
+
},
|
|
87
|
+
onCreate: function() {
|
|
88
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
89
|
+
args[_key] = arguments[_key];
|
|
90
|
+
}
|
|
91
|
+
return _this.options.current.onCreate?.(...args);
|
|
92
|
+
},
|
|
93
|
+
onDestroy: function() {
|
|
94
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
95
|
+
args[_key] = arguments[_key];
|
|
96
|
+
}
|
|
97
|
+
return _this.options.current.onDestroy?.(...args);
|
|
98
|
+
},
|
|
99
|
+
onFocus: function() {
|
|
100
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
101
|
+
args[_key] = arguments[_key];
|
|
102
|
+
}
|
|
103
|
+
return _this.options.current.onFocus?.(...args);
|
|
104
|
+
},
|
|
105
|
+
onSelectionUpdate: function() {
|
|
106
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
107
|
+
args[_key] = arguments[_key];
|
|
108
|
+
}
|
|
109
|
+
return _this.options.current.onSelectionUpdate?.(...args);
|
|
110
|
+
},
|
|
111
|
+
onTransaction: function() {
|
|
112
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
113
|
+
args[_key] = arguments[_key];
|
|
114
|
+
}
|
|
115
|
+
return _this.options.current.onTransaction?.(...args);
|
|
116
|
+
},
|
|
117
|
+
onUpdate: function() {
|
|
118
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
119
|
+
args[_key] = arguments[_key];
|
|
120
|
+
}
|
|
121
|
+
return _this.options.current.onUpdate?.(...args);
|
|
122
|
+
},
|
|
123
|
+
onContentError: function() {
|
|
124
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
125
|
+
args[_key] = arguments[_key];
|
|
126
|
+
}
|
|
127
|
+
return _this.options.current.onContentError?.(...args);
|
|
128
|
+
},
|
|
129
|
+
onDrop: function() {
|
|
130
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
131
|
+
args[_key] = arguments[_key];
|
|
132
|
+
}
|
|
133
|
+
return _this.options.current.onDrop?.(...args);
|
|
134
|
+
},
|
|
135
|
+
onPaste: function() {
|
|
136
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
137
|
+
args[_key] = arguments[_key];
|
|
138
|
+
}
|
|
139
|
+
return _this.options.current.onPaste?.(...args);
|
|
140
|
+
},
|
|
141
|
+
onDelete: function() {
|
|
142
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
143
|
+
args[_key] = arguments[_key];
|
|
144
|
+
}
|
|
145
|
+
return _this.options.current.onDelete?.(...args);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const editor = new ReactEditor(optionsToApply);
|
|
149
|
+
// no need to keep track of the event listeners, they will be removed when the editor is destroyed
|
|
150
|
+
return editor;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get the current editor instance.
|
|
154
|
+
*/ getEditor() {
|
|
155
|
+
return this.editor;
|
|
156
|
+
}
|
|
157
|
+
// ----- FORKED CHANGES -----
|
|
158
|
+
/**
|
|
159
|
+
* Always disable the editor on the server-side.
|
|
160
|
+
*/ getServerSnapshot() {
|
|
161
|
+
// return null;
|
|
162
|
+
// Return editor in SSRm, contrary to Tiptap's implementation
|
|
163
|
+
return this.editor;
|
|
164
|
+
}
|
|
165
|
+
// ----- END FORKED CHANGES -----
|
|
166
|
+
/**
|
|
167
|
+
* Subscribe to the editor instance's changes.
|
|
168
|
+
*/ subscribe(onStoreChange) {
|
|
169
|
+
this.subscriptions.add(onStoreChange);
|
|
170
|
+
return ()=>{
|
|
171
|
+
this.subscriptions.delete(onStoreChange);
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
static compareOptions(a, b) {
|
|
175
|
+
return Object.keys(a).every((key)=>{
|
|
176
|
+
if ([
|
|
177
|
+
"onCreate",
|
|
178
|
+
"onBeforeCreate",
|
|
179
|
+
"onDestroy",
|
|
180
|
+
"onUpdate",
|
|
181
|
+
"onTransaction",
|
|
182
|
+
"onFocus",
|
|
183
|
+
"onBlur",
|
|
184
|
+
"onSelectionUpdate",
|
|
185
|
+
"onContentError",
|
|
186
|
+
"onDrop",
|
|
187
|
+
"onPaste"
|
|
188
|
+
].includes(key)) {
|
|
189
|
+
// we don't want to compare callbacks, they are always different and only registered once
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
// We often encourage putting extensions inlined in the options object, so we will do a slightly deeper comparison here
|
|
193
|
+
if (key === "extensions" && a.extensions && b.extensions) {
|
|
194
|
+
if (a.extensions.length !== b.extensions.length) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
return a.extensions.every((extension, index)=>{
|
|
198
|
+
if (extension !== b.extensions?.[index]) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
return true;
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
if (a[key] !== b[key]) {
|
|
205
|
+
// if any of the options have changed, we should update the editor options
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
return true;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* On each render, we will create, update, or destroy the editor instance.
|
|
213
|
+
* @param deps The dependencies to watch for changes
|
|
214
|
+
* @returns A cleanup function
|
|
215
|
+
*/ onRender(deps) {
|
|
216
|
+
// The returned callback will run on each render
|
|
217
|
+
return ()=>{
|
|
218
|
+
this.isComponentMounted = true;
|
|
219
|
+
// Cleanup any scheduled destructions, since we are currently rendering
|
|
220
|
+
clearTimeout(this.scheduledDestructionTimeout);
|
|
221
|
+
if (this.editor && !this.editor.isDestroyed && deps.length === 0) {
|
|
222
|
+
// if the editor does exist & deps are empty, we don't need to re-initialize the editor generally
|
|
223
|
+
if (!EditorInstanceManager.compareOptions(this.options.current, this.editor.options)) {
|
|
224
|
+
// But, the options are different, so we need to update the editor options
|
|
225
|
+
// Still, this is faster than re-creating the editor
|
|
226
|
+
this.editor.setOptions({
|
|
227
|
+
...this.options.current,
|
|
228
|
+
editable: this.editor.isEditable
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
// When the editor:
|
|
233
|
+
// - does not yet exist
|
|
234
|
+
// - is destroyed
|
|
235
|
+
// - the deps array changes
|
|
236
|
+
// We need to destroy the editor instance and re-initialize it
|
|
237
|
+
this.refreshEditorInstance(deps);
|
|
238
|
+
}
|
|
239
|
+
return ()=>{
|
|
240
|
+
this.isComponentMounted = false;
|
|
241
|
+
this.scheduleDestroy();
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Recreate the editor instance if the dependencies have changed.
|
|
247
|
+
*/ refreshEditorInstance(deps) {
|
|
248
|
+
if (this.editor && !this.editor.isDestroyed) {
|
|
249
|
+
// Editor instance already exists
|
|
250
|
+
if (this.previousDeps === null) {
|
|
251
|
+
// If lastDeps has not yet been initialized, reuse the current editor instance
|
|
252
|
+
this.previousDeps = deps;
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const depsAreEqual = this.previousDeps.length === deps.length && this.previousDeps.every((dep, index)=>dep === deps[index]);
|
|
256
|
+
if (depsAreEqual) {
|
|
257
|
+
// deps exist and are equal, no need to recreate
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (this.editor && !this.editor.isDestroyed) {
|
|
262
|
+
// Destroy the editor instance if it exists
|
|
263
|
+
this.editor.destroy();
|
|
264
|
+
}
|
|
265
|
+
this.setEditor(this.createEditor());
|
|
266
|
+
// Update the lastDeps to the current deps
|
|
267
|
+
this.previousDeps = deps;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Schedule the destruction of the editor instance.
|
|
271
|
+
* This will only destroy the editor if it was not mounted on the next tick.
|
|
272
|
+
* This is to avoid destroying the editor instance when it's actually still mounted.
|
|
273
|
+
*/ scheduleDestroy() {
|
|
274
|
+
const currentInstanceId = this.instanceId;
|
|
275
|
+
const currentEditor = this.editor;
|
|
276
|
+
// Wait two ticks to see if the component is still mounted
|
|
277
|
+
this.scheduledDestructionTimeout = setTimeout(()=>{
|
|
278
|
+
if (this.isComponentMounted && this.instanceId === currentInstanceId) {
|
|
279
|
+
// If still mounted on the following tick, with the same instanceId, do not destroy the editor
|
|
280
|
+
if (currentEditor) {
|
|
281
|
+
// just re-apply options as they might have changed
|
|
282
|
+
currentEditor.setOptions(this.options.current);
|
|
283
|
+
}
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (currentEditor && !currentEditor.isDestroyed) {
|
|
287
|
+
currentEditor.destroy();
|
|
288
|
+
if (this.instanceId === currentInstanceId) {
|
|
289
|
+
this.setEditor(null);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// This allows the effect to run again between ticks
|
|
293
|
+
// which may save us from having to re-create the editor
|
|
294
|
+
}, 1);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
export function useEditor() {
|
|
298
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, deps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
299
|
+
const mostRecentOptions = useRef(options);
|
|
300
|
+
mostRecentOptions.current = options;
|
|
301
|
+
const [instanceManager] = useState(()=>new EditorInstanceManager(mostRecentOptions));
|
|
302
|
+
const editor = useSyncExternalStore(instanceManager.subscribe, instanceManager.getEditor, instanceManager.getServerSnapshot);
|
|
303
|
+
useDebugValue(editor);
|
|
304
|
+
// This effect will handle creating/updating the editor instance
|
|
305
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
306
|
+
useEffect(instanceManager.onRender(deps));
|
|
307
|
+
return editor;
|
|
308
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { EditorContext } from "../../contexts/EditorContext.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the hook is called in a
|
|
5
|
+
* component that's a descendant of the
|
|
6
|
+
* ProseMirror component
|
|
7
|
+
*/ export function useIsInReactProseMirror() {
|
|
8
|
+
return useContext(EditorContext) !== null;
|
|
9
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ReactProseMirror } from "../extensions/ReactProseMirror.js";
|
|
2
|
+
import { ReactProseMirrorCommands } from "../extensions/ReactProseMirrorCommands.js";
|
|
3
|
+
import { useEditor } from "./useEditor.js";
|
|
4
|
+
/**
|
|
5
|
+
* Create a React ProseMirror integrated Tiptap Editor instance.
|
|
6
|
+
* @param options The editor options
|
|
7
|
+
* @param deps The dependencies to watch for changes
|
|
8
|
+
* @returns The editor instance
|
|
9
|
+
* @example const editor = useEditor({ extensions: [...] })
|
|
10
|
+
*/ export function useTiptapEditor(options, deps) {
|
|
11
|
+
const extensions = [
|
|
12
|
+
ReactProseMirror,
|
|
13
|
+
...options.extensions ?? []
|
|
14
|
+
];
|
|
15
|
+
// If a consumer explicitly disables core extensions (or the Commands core extension)
|
|
16
|
+
// do not re-add our custom Commands
|
|
17
|
+
if (options.enableCoreExtensions === false || typeof options.enableCoreExtensions === "object" && options?.enableCoreExtensions?.commands === false) {
|
|
18
|
+
// Do nothing
|
|
19
|
+
} else {
|
|
20
|
+
options.enableCoreExtensions = {
|
|
21
|
+
...typeof options.enableCoreExtensions === "object" ? options.enableCoreExtensions : {},
|
|
22
|
+
commands: false
|
|
23
|
+
};
|
|
24
|
+
extensions.push(ReactProseMirrorCommands);
|
|
25
|
+
}
|
|
26
|
+
return useEditor({
|
|
27
|
+
...options,
|
|
28
|
+
extensions,
|
|
29
|
+
element: null
|
|
30
|
+
}, deps);
|
|
31
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useCurrentEditor } from "@tiptap/react";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { ReactEditorView } from "../../ReactEditorView.js";
|
|
4
|
+
import { EditorContext } from "../../contexts/EditorContext.js";
|
|
5
|
+
import { useEditorEffect } from "../../hooks/useEditorEffect.js";
|
|
6
|
+
import { TiptapEditorContext } from "../contexts/TiptapEditorContext.js";
|
|
7
|
+
/**
|
|
8
|
+
* Registers a layout effect to run after the EditorView has
|
|
9
|
+
* been updated with the latest EditorState and Decorations.
|
|
10
|
+
*
|
|
11
|
+
* Effects can take a Tiptap Editor instance as an argument.
|
|
12
|
+
* This hook should be used to execute layout effects that
|
|
13
|
+
* depend on the Editor, such as for positioning DOM
|
|
14
|
+
* nodes based on ProseMirror positions.
|
|
15
|
+
*
|
|
16
|
+
* Layout effects registered with this hook still fire
|
|
17
|
+
* synchronously after all DOM mutations, but they do so
|
|
18
|
+
* _after_ the Editor has been updated, even when the
|
|
19
|
+
* Editor lives in an ancestor component.
|
|
20
|
+
*
|
|
21
|
+
* This hook can only be used in a component that is mounted
|
|
22
|
+
* as a child of the TiptapEditorView component, including
|
|
23
|
+
* React node view components.
|
|
24
|
+
*/ export function useTiptapEditorEffect(effect, dependencies) {
|
|
25
|
+
const { view } = useContext(EditorContext);
|
|
26
|
+
const { editor } = useCurrentEditor();
|
|
27
|
+
const { isEditorInitialized } = useContext(TiptapEditorContext);
|
|
28
|
+
useEditorEffect(()=>{
|
|
29
|
+
if (editor?.view instanceof ReactEditorView && view instanceof ReactEditorView && isEditorInitialized) {
|
|
30
|
+
return effect(editor);
|
|
31
|
+
}
|
|
32
|
+
// The rules of hooks want to be able to statically
|
|
33
|
+
// verify the dependencies for the effect, but this will
|
|
34
|
+
// have already happened at the call-site.
|
|
35
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
36
|
+
}, dependencies && [
|
|
37
|
+
editor,
|
|
38
|
+
view,
|
|
39
|
+
isEditorInitialized,
|
|
40
|
+
...dependencies
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useCurrentEditor } from "@tiptap/react";
|
|
2
|
+
import { useCallback, useRef } from "react";
|
|
3
|
+
import { useEditorEffect } from "../../hooks/useEditorEffect.js";
|
|
4
|
+
function assertEditor(editor) {
|
|
5
|
+
if (editor) return;
|
|
6
|
+
throw new DOMException("Tiptap Editor is not initialized", "InvalidStateError");
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Returns a stable function reference to be used as an
|
|
10
|
+
* event handler callback.
|
|
11
|
+
*
|
|
12
|
+
* The callback will be called with the Tiptap Editor instance
|
|
13
|
+
* as its first argument.
|
|
14
|
+
*
|
|
15
|
+
* This hook can only be used in a component that is mounted
|
|
16
|
+
* as a child of the TiptapEditorView component, including
|
|
17
|
+
* React node view components.
|
|
18
|
+
*/ export function useTiptapEditorEventCallback(callback) {
|
|
19
|
+
const ref = useRef(callback);
|
|
20
|
+
const { editor } = useCurrentEditor();
|
|
21
|
+
useEditorEffect(()=>{
|
|
22
|
+
ref.current = callback;
|
|
23
|
+
}, [
|
|
24
|
+
callback
|
|
25
|
+
]);
|
|
26
|
+
return useCallback(function() {
|
|
27
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
28
|
+
args[_key] = arguments[_key];
|
|
29
|
+
}
|
|
30
|
+
assertEditor(editor);
|
|
31
|
+
return ref.current(editor, ...args);
|
|
32
|
+
}, [
|
|
33
|
+
editor
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { tiptapNodeView } from "./tiptapNodeView.js";
|
|
2
|
+
export { TiptapEditorView } from "./TiptapEditorView.js";
|
|
3
|
+
export { TiptapEditorContent } from "./TiptapEditorContent.js";
|
|
4
|
+
export { useTiptapEditorEffect } from "./hooks/useTiptapEditorEffect.js";
|
|
5
|
+
export { useIsInReactProseMirror } from "./hooks/useIsInReactProseMirror.js";
|
|
6
|
+
export { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallback.js";
|
|
7
|
+
export { TiptapEditor } from "./TiptapEditor.js";
|
|
8
|
+
export { useTiptapEditor } from "./hooks/useTiptapEditor.js";
|
|
9
|
+
export { ReactProseMirror } from "./extensions/ReactProseMirror.js";
|