@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,267 @@
|
|
|
1
|
+
import cx from "classnames";
|
|
2
|
+
let patched = false;
|
|
3
|
+
function patchConsoleError() {
|
|
4
|
+
if (patched) return;
|
|
5
|
+
/* eslint-disable no-console */ const consoleError = console.error;
|
|
6
|
+
console.error = function() {
|
|
7
|
+
for(var _len = arguments.length, data = new Array(_len), _key = 0; _key < _len; _key++){
|
|
8
|
+
data[_key] = arguments[_key];
|
|
9
|
+
}
|
|
10
|
+
const [message, prop, correction] = data;
|
|
11
|
+
if (typeof message === "string" && message.includes("Invalid DOM property `%s`. Did you mean `%s`?") && prop === "STYLE" && correction === "style") {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
consoleError(...data);
|
|
15
|
+
};
|
|
16
|
+
patched = true;
|
|
17
|
+
/* eslint-enable no-console */ }
|
|
18
|
+
function mergeStyleProps(a, b) {
|
|
19
|
+
if (!("STYLE" in a) || typeof a.STYLE !== "string") {
|
|
20
|
+
if (!("STYLE" in b) || typeof b.STYLE !== "string") {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return b.STYLE;
|
|
24
|
+
}
|
|
25
|
+
if (!("STYLE" in b) || typeof b.STYLE !== "string") {
|
|
26
|
+
return a.STYLE;
|
|
27
|
+
}
|
|
28
|
+
return `${a.STYLE.match(/;\s*$/) ? a.STYLE : `${a.STYLE};`} ${b.STYLE}`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Merges two sets of React props. Class names
|
|
32
|
+
* will be concatenated and style objects
|
|
33
|
+
* will be merged.
|
|
34
|
+
*/ export function mergeReactProps(a, b) {
|
|
35
|
+
return {
|
|
36
|
+
...a,
|
|
37
|
+
...b,
|
|
38
|
+
className: cx(a.className, b.className),
|
|
39
|
+
STYLE: mergeStyleProps(a, b),
|
|
40
|
+
style: {
|
|
41
|
+
...a.style,
|
|
42
|
+
...b.style
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Given a record of HTML attributes, returns tho
|
|
48
|
+
* equivalent React props.
|
|
49
|
+
*/ export function htmlAttrsToReactProps(attrs) {
|
|
50
|
+
patchConsoleError();
|
|
51
|
+
const props = {};
|
|
52
|
+
for (const [attrName, attrValue] of Object.entries(attrs)){
|
|
53
|
+
switch(attrName.toLowerCase()){
|
|
54
|
+
case "class":
|
|
55
|
+
{
|
|
56
|
+
props.className = attrValue;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case "style":
|
|
60
|
+
{
|
|
61
|
+
// HACK: React expects the `style` prop to be an
|
|
62
|
+
// object mapping from CSS property name to value.
|
|
63
|
+
// However, it will pass un-recognized props through
|
|
64
|
+
// to the underlying DOM element, and HTML attributes
|
|
65
|
+
// are case insensitive. So we use `STYLE` instead,
|
|
66
|
+
// which React doesn't intercept, but the DOM treats
|
|
67
|
+
// as `style`
|
|
68
|
+
props.STYLE = attrValue;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case "autocapitalize":
|
|
72
|
+
{
|
|
73
|
+
props.autoCapitalize = attrValue;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case "contenteditable":
|
|
77
|
+
{
|
|
78
|
+
if (attrValue === "" || attrValue === "true") {
|
|
79
|
+
props.contentEditable = true;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
if (attrValue === "false") {
|
|
83
|
+
props.contentEditable = false;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
if (attrValue === "plaintext-only") {
|
|
87
|
+
props.contentEditable = "plaintext-only";
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
props.contentEditable = null;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
case "draggable":
|
|
94
|
+
{
|
|
95
|
+
props.draggable = attrValue != null;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case "enterkeyhint":
|
|
99
|
+
{
|
|
100
|
+
props.enterKeyHint = attrValue;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case "for":
|
|
104
|
+
{
|
|
105
|
+
props.htmlFor = attrValue;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case "hidden":
|
|
109
|
+
{
|
|
110
|
+
props.hidden = attrValue;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case "inputmode":
|
|
114
|
+
{
|
|
115
|
+
props.inputMode = attrValue;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case "itemprop":
|
|
119
|
+
{
|
|
120
|
+
props.itemProp = attrValue;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
case "spellcheck":
|
|
124
|
+
{
|
|
125
|
+
if (attrValue === "" || attrValue === "true") {
|
|
126
|
+
props.spellCheck = true;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
if (attrValue === "false") {
|
|
130
|
+
props.spellCheck = false;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
props.spellCheck = null;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case "tabindex":
|
|
137
|
+
{
|
|
138
|
+
const numValue = parseInt(attrValue, 10);
|
|
139
|
+
if (!Number.isNaN(numValue)) {
|
|
140
|
+
props.tabIndex = numValue;
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
case "autocomplete":
|
|
145
|
+
{
|
|
146
|
+
props.autoComplete = attrValue;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case "autofocus":
|
|
150
|
+
{
|
|
151
|
+
props.autoFocus = attrValue != null;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
case "formaction":
|
|
155
|
+
{
|
|
156
|
+
props.formAction = attrValue;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
case "formenctype":
|
|
160
|
+
{
|
|
161
|
+
props.formEnctype = attrValue;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case "formmethod":
|
|
165
|
+
{
|
|
166
|
+
props.formMethod = attrValue;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
case "formnovalidate":
|
|
170
|
+
{
|
|
171
|
+
props.formNoValidate = attrValue;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case "formtarget":
|
|
175
|
+
{
|
|
176
|
+
props.formTarget = attrValue;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case "maxlength":
|
|
180
|
+
{
|
|
181
|
+
const numValue = parseInt(attrValue, 10);
|
|
182
|
+
if (!Number.isNaN(numValue)) {
|
|
183
|
+
props.maxLength = attrValue;
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
case "minlength":
|
|
188
|
+
{
|
|
189
|
+
const numValue = parseInt(attrValue, 10);
|
|
190
|
+
if (!Number.isNaN(numValue)) {
|
|
191
|
+
props.minLength = attrValue;
|
|
192
|
+
}
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
case "max":
|
|
196
|
+
{
|
|
197
|
+
const numValue = parseInt(attrValue, 10);
|
|
198
|
+
if (!Number.isNaN(numValue)) {
|
|
199
|
+
props.max = attrValue;
|
|
200
|
+
}
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
case "min":
|
|
204
|
+
{
|
|
205
|
+
const numValue = parseInt(attrValue, 10);
|
|
206
|
+
if (!Number.isNaN(numValue)) {
|
|
207
|
+
props.min = attrValue;
|
|
208
|
+
}
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
case "multiple":
|
|
212
|
+
{
|
|
213
|
+
props.multiple = attrValue != null;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
case "readonly":
|
|
217
|
+
{
|
|
218
|
+
props.readOnly = attrValue != null;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
case "required":
|
|
222
|
+
{
|
|
223
|
+
props.required = attrValue != null;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
case "size":
|
|
227
|
+
{
|
|
228
|
+
const numValue = parseInt(attrValue, 10);
|
|
229
|
+
if (!Number.isNaN(numValue)) {
|
|
230
|
+
props.size = attrValue;
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
case "step":
|
|
235
|
+
{
|
|
236
|
+
if (attrValue === "any") {
|
|
237
|
+
props.step = attrValue;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
const numValue = parseInt(attrValue, 10);
|
|
241
|
+
if (!Number.isNaN(numValue) && numValue > 0) {
|
|
242
|
+
props.step = attrValue;
|
|
243
|
+
}
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
case "disabled":
|
|
247
|
+
{
|
|
248
|
+
props.disabled = attrValue != null;
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
case "rows":
|
|
252
|
+
{
|
|
253
|
+
const numValue = parseInt(attrValue, 10);
|
|
254
|
+
if (!Number.isNaN(numValue)) {
|
|
255
|
+
props.rows = attrValue;
|
|
256
|
+
}
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
default:
|
|
260
|
+
{
|
|
261
|
+
props[attrName] = attrValue;
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return props;
|
|
267
|
+
}
|
package/dist/esm/refs.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
export function useMergedDOMRefs() {
|
|
3
|
+
for(var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++){
|
|
4
|
+
refs[_key] = arguments[_key];
|
|
5
|
+
}
|
|
6
|
+
return useCallback((value)=>{
|
|
7
|
+
refs.forEach((ref)=>{
|
|
8
|
+
if (typeof ref === "function") {
|
|
9
|
+
ref(value);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (ref) {
|
|
13
|
+
ref.current = value;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
17
|
+
}, refs);
|
|
18
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */ import { render } from "@testing-library/react";
|
|
2
|
+
import { expect } from "expect";
|
|
3
|
+
import { Node } from "prosemirror-model";
|
|
4
|
+
import { EditorState, TextSelection } from "prosemirror-state";
|
|
5
|
+
import { doc, eq, p, schema } from "prosemirror-test-builder";
|
|
6
|
+
import React from "react";
|
|
7
|
+
import { ProseMirror } from "../components/ProseMirror.js";
|
|
8
|
+
import { ProseMirrorDoc } from "../components/ProseMirrorDoc.js";
|
|
9
|
+
import { useEditorEffect } from "../hooks/useEditorEffect.js";
|
|
10
|
+
import { reactKeys } from "../plugins/reactKeys.js";
|
|
11
|
+
const toEqualNode = function(actual, expected) {
|
|
12
|
+
if (!(actual instanceof Node && expected instanceof Node)) {
|
|
13
|
+
throw new Error("Must be comparing nodes");
|
|
14
|
+
}
|
|
15
|
+
const pass = eq(actual, expected);
|
|
16
|
+
return {
|
|
17
|
+
message: ()=>// `this` context will have correct typings
|
|
18
|
+
`expected ${this.utils.printReceived(actual)} ${pass ? "not " : ""}to equal ${this.utils.printExpected(expected)}`,
|
|
19
|
+
pass
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
expect.extend({
|
|
23
|
+
toEqualNode
|
|
24
|
+
});
|
|
25
|
+
export function tempEditor(param) {
|
|
26
|
+
let { doc: startDoc, selection, controlled, plugins, ...props } = param;
|
|
27
|
+
startDoc = startDoc ?? doc(p());
|
|
28
|
+
const state = EditorState.create({
|
|
29
|
+
doc: startDoc,
|
|
30
|
+
schema,
|
|
31
|
+
selection: selection ?? (startDoc.tag?.a ? TextSelection.create(startDoc, startDoc.tag.a, startDoc.tag?.b) : undefined),
|
|
32
|
+
plugins: [
|
|
33
|
+
...plugins ?? [],
|
|
34
|
+
reactKeys()
|
|
35
|
+
]
|
|
36
|
+
});
|
|
37
|
+
let view = null;
|
|
38
|
+
function Test() {
|
|
39
|
+
useEditorEffect((v)=>{
|
|
40
|
+
view = v;
|
|
41
|
+
});
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const { rerender, unmount } = render(/*#__PURE__*/ React.createElement(ProseMirror, {
|
|
45
|
+
...controlled ? {
|
|
46
|
+
state
|
|
47
|
+
} : {
|
|
48
|
+
defaultState: state
|
|
49
|
+
},
|
|
50
|
+
...props
|
|
51
|
+
}, /*#__PURE__*/ React.createElement(Test, null), /*#__PURE__*/ React.createElement(ProseMirrorDoc, null)));
|
|
52
|
+
function rerenderEditor() {
|
|
53
|
+
let { ...newProps } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
54
|
+
rerender(/*#__PURE__*/ React.createElement(ProseMirror, {
|
|
55
|
+
...controlled ? {
|
|
56
|
+
state
|
|
57
|
+
} : {
|
|
58
|
+
defaultState: state
|
|
59
|
+
},
|
|
60
|
+
...props,
|
|
61
|
+
...newProps
|
|
62
|
+
}, /*#__PURE__*/ React.createElement(Test, null), /*#__PURE__*/ React.createElement(ProseMirrorDoc, null)));
|
|
63
|
+
return view;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
view: view,
|
|
67
|
+
rerender: rerenderEditor,
|
|
68
|
+
unmount
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function findTextNodeInner(node, text) {
|
|
72
|
+
if (node.nodeType == 3) {
|
|
73
|
+
if (node.nodeValue == text) return node;
|
|
74
|
+
} else if (node.nodeType == 1) {
|
|
75
|
+
for(let ch = node.firstChild; ch; ch = ch.nextSibling){
|
|
76
|
+
const found = findTextNodeInner(ch, text);
|
|
77
|
+
if (found) return found;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
export function findTextNode(node, text) {
|
|
83
|
+
const found = findTextNodeInner(node, text);
|
|
84
|
+
if (found) return found;
|
|
85
|
+
throw new Error("Unable to find matching text node");
|
|
86
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/* Copyright (c) The New York Times Company */ let oldElementFromPoint;
|
|
2
|
+
let oldGetClientRects;
|
|
3
|
+
let oldGetBoundingClientRect;
|
|
4
|
+
const mockElementFromPoint = ()=>globalThis.document.body;
|
|
5
|
+
const mockGetBoundingClientRect = ()=>{
|
|
6
|
+
return {
|
|
7
|
+
bottom: 0,
|
|
8
|
+
height: 0,
|
|
9
|
+
left: 0,
|
|
10
|
+
right: 0,
|
|
11
|
+
top: 0,
|
|
12
|
+
width: 0,
|
|
13
|
+
x: 0,
|
|
14
|
+
y: 0,
|
|
15
|
+
toJSON () {
|
|
16
|
+
return {
|
|
17
|
+
bottom: 0,
|
|
18
|
+
height: 0,
|
|
19
|
+
left: 0,
|
|
20
|
+
right: 0,
|
|
21
|
+
top: 0,
|
|
22
|
+
width: 0,
|
|
23
|
+
x: 0,
|
|
24
|
+
y: 0
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const mockGetClientRects = ()=>{
|
|
30
|
+
const list = [
|
|
31
|
+
{
|
|
32
|
+
bottom: 0,
|
|
33
|
+
height: 0,
|
|
34
|
+
left: 0,
|
|
35
|
+
right: 0,
|
|
36
|
+
top: 0,
|
|
37
|
+
width: 0,
|
|
38
|
+
x: 0,
|
|
39
|
+
y: 0,
|
|
40
|
+
toJSON () {
|
|
41
|
+
return {
|
|
42
|
+
bottom: 0,
|
|
43
|
+
height: 0,
|
|
44
|
+
left: 0,
|
|
45
|
+
right: 0,
|
|
46
|
+
top: 0,
|
|
47
|
+
width: 0,
|
|
48
|
+
x: 0,
|
|
49
|
+
y: 0
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
];
|
|
54
|
+
const domRectList = Object.assign(list, {
|
|
55
|
+
item (index) {
|
|
56
|
+
return list[index] ?? null;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return domRectList;
|
|
60
|
+
};
|
|
61
|
+
export function setupProseMirrorView() {
|
|
62
|
+
oldElementFromPoint = Document.prototype.elementFromPoint;
|
|
63
|
+
Document.prototype.elementFromPoint = mockElementFromPoint;
|
|
64
|
+
oldGetClientRects = Range.prototype.getClientRects;
|
|
65
|
+
Range.prototype.getClientRects = mockGetClientRects;
|
|
66
|
+
oldGetBoundingClientRect = Range.prototype.getBoundingClientRect;
|
|
67
|
+
Range.prototype.getBoundingClientRect = mockGetBoundingClientRect;
|
|
68
|
+
}
|
|
69
|
+
export function teardownProseMirrorView() {
|
|
70
|
+
// @ts-expect-error jsdom actually doesn't implement these, so they might be undefined
|
|
71
|
+
Document.prototype.elementFromPoint = oldElementFromPoint;
|
|
72
|
+
// @ts-expect-error jsdom actually doesn't implement these, so they might be undefined
|
|
73
|
+
Range.prototype.getClientRects = oldGetClientRects;
|
|
74
|
+
// @ts-expect-error jsdom actually doesn't implement these, so they might be undefined
|
|
75
|
+
Range.prototype.getBoundingClientRect = oldGetBoundingClientRect;
|
|
76
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NodeView } from "@tiptap/core";
|
|
2
|
+
/**
|
|
3
|
+
* Subclass of Tiptap's NodeView to be used in tiptapNodeView.
|
|
4
|
+
*
|
|
5
|
+
* Allows us to pass in an existing dom and contentDOM from React ProseMirror's
|
|
6
|
+
* ViewDesc, so that we can call Tiptap's default stopEvent and ignoreMutation
|
|
7
|
+
* methods
|
|
8
|
+
*/ export class ReactProseMirrorNodeView extends NodeView {
|
|
9
|
+
_dom;
|
|
10
|
+
_contentDOM;
|
|
11
|
+
constructor(component, props, dom, contentDOM, options){
|
|
12
|
+
super(component, props, options);
|
|
13
|
+
this._dom = dom;
|
|
14
|
+
this._contentDOM = contentDOM;
|
|
15
|
+
}
|
|
16
|
+
get dom() {
|
|
17
|
+
return this._dom;
|
|
18
|
+
}
|
|
19
|
+
get contentDOM() {
|
|
20
|
+
return this._contentDOM;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Editor } from "@tiptap/core";
|
|
2
|
+
import { EditorState } from "prosemirror-state";
|
|
3
|
+
import { StaticEditorView } from "../StaticEditorView.js";
|
|
4
|
+
export class TiptapEditor extends Editor {
|
|
5
|
+
constructor(options = {}){
|
|
6
|
+
super({
|
|
7
|
+
...options,
|
|
8
|
+
element: null
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
get view() {
|
|
12
|
+
return(// @ts-expect-error private property
|
|
13
|
+
this.editorView ?? new StaticEditorView({
|
|
14
|
+
state: EditorState.create({
|
|
15
|
+
schema: this.extensionManager.schema
|
|
16
|
+
}),
|
|
17
|
+
...this.options.editorProps,
|
|
18
|
+
attributes: {
|
|
19
|
+
role: "textbox",
|
|
20
|
+
...this.options.editorProps.attributes
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import React, { useContext, useSyncExternalStore } from "react";
|
|
2
|
+
import { createPortal } from "react-dom";
|
|
3
|
+
import { ProseMirrorDoc } from "../components/ProseMirrorDoc.js";
|
|
4
|
+
import { useEditorEffect } from "../hooks/useEditorEffect.js";
|
|
5
|
+
import { TiptapEditorContext } from "./contexts/TiptapEditorContext.js";
|
|
6
|
+
/**
|
|
7
|
+
* This component renders all of the editor's registered "React renderers".
|
|
8
|
+
*/ const Portals = (param)=>{
|
|
9
|
+
let { contentComponent } = param;
|
|
10
|
+
const renderers = useSyncExternalStore(contentComponent.subscribe, contentComponent.getSnapshot, contentComponent.getServerSnapshot);
|
|
11
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, Object.values(renderers));
|
|
12
|
+
};
|
|
13
|
+
function getInstance() {
|
|
14
|
+
const subscribers = new Set();
|
|
15
|
+
let renderers = {};
|
|
16
|
+
return {
|
|
17
|
+
/**
|
|
18
|
+
* Subscribe to the editor instance's changes.
|
|
19
|
+
*/ subscribe (callback) {
|
|
20
|
+
subscribers.add(callback);
|
|
21
|
+
return ()=>{
|
|
22
|
+
subscribers.delete(callback);
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
getSnapshot () {
|
|
26
|
+
return renderers;
|
|
27
|
+
},
|
|
28
|
+
getServerSnapshot () {
|
|
29
|
+
return renderers;
|
|
30
|
+
},
|
|
31
|
+
/**
|
|
32
|
+
* Adds a new React Renderer to the editor.
|
|
33
|
+
*/ setRenderer (id, renderer) {
|
|
34
|
+
renderers = {
|
|
35
|
+
...renderers,
|
|
36
|
+
[id]: /*#__PURE__*/ createPortal(renderer.reactElement, renderer.element, id)
|
|
37
|
+
};
|
|
38
|
+
subscribers.forEach((subscriber)=>subscriber());
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* Removes a React Renderer from the editor.
|
|
42
|
+
*/ removeRenderer (id) {
|
|
43
|
+
const nextRenderers = {
|
|
44
|
+
...renderers
|
|
45
|
+
};
|
|
46
|
+
delete nextRenderers[id];
|
|
47
|
+
renderers = nextRenderers;
|
|
48
|
+
subscribers.forEach((subscriber)=>subscriber());
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Renders the actual editable ProseMirror document.
|
|
54
|
+
*
|
|
55
|
+
* This **must** be passed as a child to the `TiptapEditorView`
|
|
56
|
+
* component. It may be wrapped in other components, and other
|
|
57
|
+
* childern may be passed before or after. It must be passed the
|
|
58
|
+
* same `editor` as is passed to the `TiptapEditorView`.
|
|
59
|
+
*/ export function TiptapEditorContent(param) {
|
|
60
|
+
let { editor: editorProp, ...props } = param;
|
|
61
|
+
const editor = editorProp;
|
|
62
|
+
const { onEditorInitialize, onEditorDeinitialize } = useContext(TiptapEditorContext);
|
|
63
|
+
useEditorEffect((view)=>{
|
|
64
|
+
if (editor.view === view) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
// @ts-expect-error private property
|
|
68
|
+
editor.editorView = view;
|
|
69
|
+
editor.contentComponent = getInstance();
|
|
70
|
+
// @ts-expect-error private method
|
|
71
|
+
editor.injectCSS();
|
|
72
|
+
const dom = view.dom;
|
|
73
|
+
dom.editor = editor;
|
|
74
|
+
setTimeout(()=>{
|
|
75
|
+
if (editor.isDestroyed) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
editor.commands.focus(editor.options.autofocus);
|
|
79
|
+
editor.emit("create", {
|
|
80
|
+
editor
|
|
81
|
+
});
|
|
82
|
+
editor.isInitialized = true;
|
|
83
|
+
onEditorInitialize();
|
|
84
|
+
});
|
|
85
|
+
return ()=>{
|
|
86
|
+
editor.isInitialized = false;
|
|
87
|
+
editor.contentComponent = null;
|
|
88
|
+
editor.destroy();
|
|
89
|
+
onEditorDeinitialize();
|
|
90
|
+
};
|
|
91
|
+
}, [
|
|
92
|
+
editor,
|
|
93
|
+
onEditorDeinitialize,
|
|
94
|
+
onEditorInitialize
|
|
95
|
+
]);
|
|
96
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ProseMirrorDoc, props), editor?.contentComponent && /*#__PURE__*/ React.createElement(Portals, {
|
|
97
|
+
contentComponent: editor.contentComponent
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { EditorContext } from "@tiptap/react";
|
|
2
|
+
import cx from "classnames";
|
|
3
|
+
import React, { useCallback, useMemo, useState } from "react";
|
|
4
|
+
import { ProseMirror } from "../components/ProseMirror.js";
|
|
5
|
+
import { useForceUpdate } from "../hooks/useForceUpdate.js";
|
|
6
|
+
import { TiptapEditorContext } from "./contexts/TiptapEditorContext.js";
|
|
7
|
+
/**
|
|
8
|
+
* Render a Tiptap-compatible React ProseMirror editor.
|
|
9
|
+
*/ export function TiptapEditorView(param) {
|
|
10
|
+
let { editor, nodeViewComponents, markViewComponents, children, static: isStatic = false } = param;
|
|
11
|
+
const [isEditorInitialized, setIsEditorInitialized] = useState(editor.isInitialized);
|
|
12
|
+
const attributesProp = editor.options.editorProps?.attributes;
|
|
13
|
+
const [attributes, setAttributes] = useState(typeof attributesProp === "function" ? attributesProp(editor.state) : attributesProp);
|
|
14
|
+
const forceUpdate = useForceUpdate();
|
|
15
|
+
const dispatchTransaction = useCallback((tr)=>{
|
|
16
|
+
// @ts-expect-error calling private method
|
|
17
|
+
editor.dispatchTransaction(tr);
|
|
18
|
+
if (typeof attributesProp === "function") {
|
|
19
|
+
setAttributes(attributesProp(editor.state));
|
|
20
|
+
}
|
|
21
|
+
// Tiptap's dispatchTransaction doesn't trigger
|
|
22
|
+
// a re-render, so we need to manually force
|
|
23
|
+
// one to ensure that React stays in sync.
|
|
24
|
+
forceUpdate();
|
|
25
|
+
}, [
|
|
26
|
+
attributesProp,
|
|
27
|
+
editor,
|
|
28
|
+
forceUpdate
|
|
29
|
+
]);
|
|
30
|
+
const editorProps = {
|
|
31
|
+
...editor.options.editorProps,
|
|
32
|
+
attributes: {
|
|
33
|
+
role: "textbox",
|
|
34
|
+
...attributes,
|
|
35
|
+
class: cx(attributes?.class, "tiptap")
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const { nodeViews, markViews } = editor.isDestroyed ? {
|
|
39
|
+
nodeViews: undefined,
|
|
40
|
+
markViews: undefined
|
|
41
|
+
} : editor.view.props;
|
|
42
|
+
const contextValue = useMemo(()=>({
|
|
43
|
+
editor
|
|
44
|
+
}), [
|
|
45
|
+
editor
|
|
46
|
+
]);
|
|
47
|
+
const onEditorInitialize = useCallback(()=>{
|
|
48
|
+
setIsEditorInitialized(true);
|
|
49
|
+
}, []);
|
|
50
|
+
const onEditorDeinitialize = useCallback(()=>{
|
|
51
|
+
setIsEditorInitialized(false);
|
|
52
|
+
}, []);
|
|
53
|
+
const tiptapEditorContextValue = useMemo(()=>({
|
|
54
|
+
isEditorInitialized,
|
|
55
|
+
onEditorInitialize,
|
|
56
|
+
onEditorDeinitialize
|
|
57
|
+
}), [
|
|
58
|
+
isEditorInitialized,
|
|
59
|
+
onEditorDeinitialize,
|
|
60
|
+
onEditorInitialize
|
|
61
|
+
]);
|
|
62
|
+
return /*#__PURE__*/ React.createElement(ProseMirror, {
|
|
63
|
+
static: isStatic,
|
|
64
|
+
...editorProps,
|
|
65
|
+
markViewComponents: markViewComponents,
|
|
66
|
+
markViews: markViews,
|
|
67
|
+
nodeViewComponents: nodeViewComponents,
|
|
68
|
+
nodeViews: nodeViews,
|
|
69
|
+
state: editor.state,
|
|
70
|
+
dispatchTransaction: dispatchTransaction
|
|
71
|
+
}, /*#__PURE__*/ React.createElement(EditorContext.Provider, {
|
|
72
|
+
value: contextValue
|
|
73
|
+
}, /*#__PURE__*/ React.createElement(TiptapEditorContext.Provider, {
|
|
74
|
+
value: tiptapEditorContextValue
|
|
75
|
+
}, children)));
|
|
76
|
+
}
|