@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 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { EditorView } from "prosemirror-view";
|
|
2
|
+
import { EMPTY_STATE } from "./constants.js";
|
|
3
|
+
function buildNodeViews(view) {
|
|
4
|
+
const result = Object.create(null);
|
|
5
|
+
function add(obj) {
|
|
6
|
+
for(const prop in obj)if (!Object.prototype.hasOwnProperty.call(result, prop)) // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
7
|
+
result[prop] = obj[prop];
|
|
8
|
+
}
|
|
9
|
+
view.someProp("nodeViews", add);
|
|
10
|
+
view.someProp("markViews", add);
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
function changedNodeViews(a, b) {
|
|
14
|
+
let nA = 0, nB = 0;
|
|
15
|
+
for(const prop in a){
|
|
16
|
+
if (a[prop] != b[prop]) return true;
|
|
17
|
+
nA++;
|
|
18
|
+
}
|
|
19
|
+
for(const _ in b)nB++;
|
|
20
|
+
return nA != nB;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Extends EditorView to make prop and state updates pure, remove the DOM
|
|
24
|
+
* Mutation Observer, and use a custom document view managed by React.
|
|
25
|
+
*
|
|
26
|
+
* @privateRemarks
|
|
27
|
+
*
|
|
28
|
+
* The implementation relies on the base class using a private member to store
|
|
29
|
+
* the committed props and having a public getter that we override to return the
|
|
30
|
+
* latest, uncommitted props. The base class can then be told to update when the
|
|
31
|
+
* React effects are commit an update, applying the pending, uncommitted props.
|
|
32
|
+
*/ export class ReactEditorView extends EditorView {
|
|
33
|
+
nextProps;
|
|
34
|
+
prevState;
|
|
35
|
+
_destroyed;
|
|
36
|
+
cursorWrapped;
|
|
37
|
+
constructor(place, props){
|
|
38
|
+
// Prevent the base class from destroying the React-managed nodes.
|
|
39
|
+
// Restore them below after invoking the base class constructor.
|
|
40
|
+
const reactContent = [
|
|
41
|
+
...place.mount.childNodes
|
|
42
|
+
];
|
|
43
|
+
// Prevent the base class from mutating the React-managed attributes.
|
|
44
|
+
// Restore them below after invoking the base class constructor.
|
|
45
|
+
const reactAttrs = [
|
|
46
|
+
...place.mount.attributes
|
|
47
|
+
];
|
|
48
|
+
for (const attr of reactAttrs){
|
|
49
|
+
place.mount.removeAttributeNode(attr);
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
// Call the superclass constructor with only a state and no plugins.
|
|
53
|
+
// We'll set everything else ourselves and apply props during layout.
|
|
54
|
+
super(place, {
|
|
55
|
+
state: EMPTY_STATE
|
|
56
|
+
});
|
|
57
|
+
this.domObserver.stop();
|
|
58
|
+
this.domObserver.observer = null;
|
|
59
|
+
this.domObserver.queue = [];
|
|
60
|
+
const originalOnSelectionChange = this.domObserver.onSelectionChange;
|
|
61
|
+
this.domObserver.onSelectionChange = ()=>{
|
|
62
|
+
// During a composition, we completely pause React-driven
|
|
63
|
+
// selection and DOM updates. Compositions are "fragile";
|
|
64
|
+
// in Safari, even updating the selection to the same
|
|
65
|
+
// position it's already set to will end the current
|
|
66
|
+
// composition.
|
|
67
|
+
if (this.composing) return;
|
|
68
|
+
originalOnSelectionChange();
|
|
69
|
+
};
|
|
70
|
+
} finally{
|
|
71
|
+
place.mount.replaceChildren(...reactContent);
|
|
72
|
+
for (const attr of place.mount.attributes){
|
|
73
|
+
place.mount.removeAttributeNode(attr);
|
|
74
|
+
}
|
|
75
|
+
for (const attr of reactAttrs){
|
|
76
|
+
place.mount.setAttributeNode(attr);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
this.prevState = EMPTY_STATE;
|
|
80
|
+
this.nextProps = props;
|
|
81
|
+
this.state = props.state;
|
|
82
|
+
this.nodeViews = buildNodeViews(this);
|
|
83
|
+
// Destroy the document view description that the base class makes.
|
|
84
|
+
// A React document view will assign itself to this attribute later.
|
|
85
|
+
this.docView.destroy();
|
|
86
|
+
// @ts-expect-error this violates the typing but class does it, too.
|
|
87
|
+
this.docView = null;
|
|
88
|
+
this._destroyed = false;
|
|
89
|
+
this.cursorWrapped = false;
|
|
90
|
+
}
|
|
91
|
+
get props() {
|
|
92
|
+
return this.nextProps;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* @privateremarks
|
|
96
|
+
*
|
|
97
|
+
* We override this getter because the base implementation
|
|
98
|
+
* relies on checking `docView === null`, but we unconditionally
|
|
99
|
+
* set view.docView in a layout effect in the DocNodeView.
|
|
100
|
+
* This has the effect of "un-destroying" the EditorView,
|
|
101
|
+
* making it impossible to determine whether it's been destroyed.
|
|
102
|
+
*/ get isDestroyed() {
|
|
103
|
+
return this._destroyed;
|
|
104
|
+
}
|
|
105
|
+
setProps(props) {
|
|
106
|
+
this.update({
|
|
107
|
+
...this.props,
|
|
108
|
+
...props
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
update(props) {
|
|
112
|
+
const prevProps = this.nextProps;
|
|
113
|
+
this.nextProps = props;
|
|
114
|
+
this.state = props.state;
|
|
115
|
+
if (prevProps.state.plugins !== props.state.plugins || prevProps.plugins !== props.plugins || prevProps.nodeViews !== props.nodeViews) {
|
|
116
|
+
const nodeViews = buildNodeViews(this);
|
|
117
|
+
if (changedNodeViews(this.nodeViews, nodeViews)) {
|
|
118
|
+
this.nodeViews = nodeViews;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
this.editable = !this.someProp("editable", (value)=>value(this.state) === false);
|
|
122
|
+
}
|
|
123
|
+
updateState(state) {
|
|
124
|
+
this.setProps({
|
|
125
|
+
state
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
someProp(propName, f) {
|
|
129
|
+
if (!this.props) {
|
|
130
|
+
// The base class constructor calls this method before props are set.
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
const prop = this.props[propName];
|
|
134
|
+
if (prop != null) {
|
|
135
|
+
const result = f ? f(prop) : prop;
|
|
136
|
+
if (result) {
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (const plugin of this.props.plugins ?? []){
|
|
141
|
+
const prop = plugin.props[propName];
|
|
142
|
+
if (prop != null) {
|
|
143
|
+
const result = f ? f(prop) : prop;
|
|
144
|
+
if (result) {
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (const plugin of this.state.plugins){
|
|
150
|
+
const prop = plugin.props[propName];
|
|
151
|
+
if (prop != null) {
|
|
152
|
+
const result = f ? f(prop) : prop;
|
|
153
|
+
if (result) {
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
destroy() {
|
|
161
|
+
// Prevent the base class from destroying the React-managed nodes.
|
|
162
|
+
// Restore them below after invoking the base class method.
|
|
163
|
+
const reactContent = [
|
|
164
|
+
...this.dom.childNodes
|
|
165
|
+
];
|
|
166
|
+
try {
|
|
167
|
+
super.destroy();
|
|
168
|
+
} finally{
|
|
169
|
+
this.dom.replaceChildren(...reactContent);
|
|
170
|
+
this._destroyed = true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Commit effects by appling the pending props and state.
|
|
175
|
+
*
|
|
176
|
+
* Ensures the DOM selection is correct and updates plugin views.
|
|
177
|
+
*
|
|
178
|
+
* @privateRemarks
|
|
179
|
+
*
|
|
180
|
+
* The correctness of this depends on the pure update function ensuring that
|
|
181
|
+
* the node view set is up to date so that it does not try to redraw.
|
|
182
|
+
*/ commitPendingEffects() {
|
|
183
|
+
// This class tracks state eagerly but the base class does it lazily.
|
|
184
|
+
// Temporarily roll it back so the base class can handle the updates.
|
|
185
|
+
this.state = this.prevState;
|
|
186
|
+
// Force the base class to try to update the document. React updated it, but
|
|
187
|
+
// this ensures that the base class validates the DOM selection and invokes
|
|
188
|
+
// node view selection callbacks.
|
|
189
|
+
this.docView.markDirty(-1, -1);
|
|
190
|
+
super.update(this.nextProps);
|
|
191
|
+
// Store the new previous state.
|
|
192
|
+
this.prevState = this.state;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export class StaticEditorView {
|
|
2
|
+
props;
|
|
3
|
+
nodeViews;
|
|
4
|
+
constructor(props){
|
|
5
|
+
this.props = props;
|
|
6
|
+
this.nodeViews = {};
|
|
7
|
+
}
|
|
8
|
+
get composing() {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
get dom() {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
get editable() {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
get state() {
|
|
18
|
+
return this.props.state;
|
|
19
|
+
}
|
|
20
|
+
get isDestroyed() {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
setProps(props) {
|
|
24
|
+
return this.update({
|
|
25
|
+
...this.props,
|
|
26
|
+
...props
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
update(props) {
|
|
30
|
+
this.props = props;
|
|
31
|
+
}
|
|
32
|
+
updateState(state) {
|
|
33
|
+
this.setProps({
|
|
34
|
+
state
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
someProp(propName, f) {
|
|
38
|
+
const prop = this.props[propName];
|
|
39
|
+
if (prop != null) {
|
|
40
|
+
const result = f ? f(prop) : prop;
|
|
41
|
+
if (result) {
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const plugin of this.props.plugins ?? []){
|
|
46
|
+
const prop = plugin.props[propName];
|
|
47
|
+
if (prop != null) {
|
|
48
|
+
const result = f ? f(prop) : prop;
|
|
49
|
+
if (result) {
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (const plugin of this.state.plugins){
|
|
55
|
+
const prop = plugin.props[propName];
|
|
56
|
+
if (prop != null) {
|
|
57
|
+
const result = f ? f(prop) : prop;
|
|
58
|
+
if (result) {
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
destroy() {
|
|
66
|
+
// pass
|
|
67
|
+
}
|
|
68
|
+
domSelectionRange() {
|
|
69
|
+
return {
|
|
70
|
+
anchorNode: null,
|
|
71
|
+
anchorOffset: 0,
|
|
72
|
+
focusNode: null,
|
|
73
|
+
focusOffset: 0
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
domSelection() {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const nav = typeof navigator != "undefined" ? navigator : null;
|
|
2
|
+
const doc = typeof document != "undefined" ? document : null;
|
|
3
|
+
const agent = nav && nav.userAgent || "";
|
|
4
|
+
const ie_edge = /Edge\/(\d+)/.exec(agent);
|
|
5
|
+
const ie_upto10 = /MSIE \d/.exec(agent);
|
|
6
|
+
const ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(agent);
|
|
7
|
+
const ie = !!(ie_upto10 || ie_11up || ie_edge);
|
|
8
|
+
const ie_version = ie_upto10 ? document.documentMode : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0;
|
|
9
|
+
const gecko = !ie && /gecko\/(\d+)/i.test(agent);
|
|
10
|
+
const gecko_version = gecko && +(/Firefox\/(\d+)/.exec(agent) || [
|
|
11
|
+
0,
|
|
12
|
+
0
|
|
13
|
+
])[1];
|
|
14
|
+
const _chrome = !ie && /Chrome\/(\d+)/.exec(agent);
|
|
15
|
+
const chrome = !!_chrome;
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
17
|
+
const chrome_version = _chrome ? +_chrome[1] : 0;
|
|
18
|
+
const safari = !ie && !!nav && /Apple Computer/.test(nav.vendor);
|
|
19
|
+
// Is true for both iOS and iPadOS for convenience
|
|
20
|
+
const ios = safari && (/Mobile\/\w+/.test(agent) || !!nav && nav.maxTouchPoints > 2);
|
|
21
|
+
const mac = ios || (nav ? /Mac/.test(nav.platform) : false);
|
|
22
|
+
const windows = nav ? /Win/.test(nav.platform) : false;
|
|
23
|
+
const android = /Android \d/.test(agent);
|
|
24
|
+
const webkit = !!doc && "webkitFontSmoothing" in doc.documentElement.style;
|
|
25
|
+
const webkit_version = webkit ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [
|
|
26
|
+
0,
|
|
27
|
+
0
|
|
28
|
+
])[1] : 0;
|
|
29
|
+
export const browser = {
|
|
30
|
+
ie,
|
|
31
|
+
ie_version,
|
|
32
|
+
gecko,
|
|
33
|
+
gecko_version,
|
|
34
|
+
chrome,
|
|
35
|
+
chrome_version,
|
|
36
|
+
safari,
|
|
37
|
+
ios,
|
|
38
|
+
mac,
|
|
39
|
+
windows,
|
|
40
|
+
android,
|
|
41
|
+
webkit,
|
|
42
|
+
webkit_version
|
|
43
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { reactKeysPluginKey } from "../plugins/reactKeys.js";
|
|
2
|
+
/**
|
|
3
|
+
* Create a command function that reorders the adjacent nodes starting
|
|
4
|
+
* at the provided position.
|
|
5
|
+
*
|
|
6
|
+
* @param pos - The `start` position of the parent of the nodes being reordered
|
|
7
|
+
* @param order - The new order for the nodes, expressed as an array of indices. For
|
|
8
|
+
* example, to swap the first two nodes in a set of three, `order`
|
|
9
|
+
* would be set to `[1, 0, 2]`. To move the first node to the end,
|
|
10
|
+
* and keep the other two in relative order, set `order` to `[1, 2, 0]`.
|
|
11
|
+
*/ export function reorderSiblings(pos, order) {
|
|
12
|
+
return function reorderSiblingsCommand(state, dispatch) {
|
|
13
|
+
const tr = state.tr;
|
|
14
|
+
return reorderSiblingsOnTransaction(pos, order, tr, state, dispatch);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function reorderSiblingsOnTransaction(pos, order, tr, state, dispatch) {
|
|
18
|
+
const orderLookup = order.reduce((acc, oldIndex, newIndex)=>{
|
|
19
|
+
acc[oldIndex] = newIndex;
|
|
20
|
+
return acc;
|
|
21
|
+
}, []);
|
|
22
|
+
const $pos = state.doc.resolve(pos);
|
|
23
|
+
if ($pos.start() !== pos) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (!dispatch) return true;
|
|
27
|
+
const nodes = $pos.parent.children;
|
|
28
|
+
const reordered = nodes.map((node, i)=>[
|
|
29
|
+
node,
|
|
30
|
+
i
|
|
31
|
+
]).sort((param, param1)=>{
|
|
32
|
+
let [, a] = param, [, b] = param1;
|
|
33
|
+
return orderLookup[a] - orderLookup[b];
|
|
34
|
+
}).map((param)=>{
|
|
35
|
+
let [node] = param;
|
|
36
|
+
return node;
|
|
37
|
+
});
|
|
38
|
+
tr.replaceWith(pos, $pos.parent.content.size + pos, reordered);
|
|
39
|
+
const meta = {
|
|
40
|
+
overrides: {}
|
|
41
|
+
};
|
|
42
|
+
const oldPositions = [];
|
|
43
|
+
let start = pos;
|
|
44
|
+
for (const node of nodes){
|
|
45
|
+
oldPositions.push(start);
|
|
46
|
+
start += node.nodeSize;
|
|
47
|
+
}
|
|
48
|
+
start = pos;
|
|
49
|
+
const newPositions = [];
|
|
50
|
+
for(let i = 0; i < reordered.length; i++){
|
|
51
|
+
const node = reordered[i];
|
|
52
|
+
newPositions[order[i]] = start;
|
|
53
|
+
start += node.nodeSize;
|
|
54
|
+
}
|
|
55
|
+
for(let i = 0; i < oldPositions.length; i++){
|
|
56
|
+
const oldPosition = oldPositions[i];
|
|
57
|
+
const newPosition = newPositions[i];
|
|
58
|
+
meta.overrides[oldPosition] = newPosition;
|
|
59
|
+
}
|
|
60
|
+
tr.setMeta(reactKeysPluginKey, meta);
|
|
61
|
+
dispatch(tr);
|
|
62
|
+
return true;
|
|
63
|
+
}
|