Skip to content
Snippets Groups Projects
Commit b1d0d0b6 authored by chris's avatar chris
Browse files

test

parent 50c6e827
No related branches found
No related tags found
1 merge request!289Pm node views portals
...@@ -12,7 +12,12 @@ class MultipleChoiceQuestion extends Tools { ...@@ -12,7 +12,12 @@ class MultipleChoiceQuestion extends Tools {
get run() { get run() {
return (state, dispatch) => { return (state, dispatch) => {
const { empty, $from, $to } = state.selection; const { empty, $from, $to } = state.selection;
const content = Fragment.empty; let content = Fragment.empty;
if (!empty && $from.sameParent($to) && $from.parent.inlineContent)
content = $from.parent.content.cut(
$from.parentOffset,
$to.parentOffset,
);
const footnote = state.config.schema.nodes.multiple_choice.create( const footnote = state.config.schema.nodes.multiple_choice.create(
{ id: uuidv4() }, { id: uuidv4() },
......
/* eslint-disable react-hooks/exhaustive-deps */ /* eslint-disable react-hooks/exhaustive-deps */
import React, { useLayoutEffect, useRef } from 'react'; import React, { useEffect, useRef, useMemo } from 'react';
import { EditorState } from 'prosemirror-state'; import { EditorState } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view'; import { EditorView } from 'prosemirror-view';
import { StepMap } from 'prosemirror-transform'; import { StepMap } from 'prosemirror-transform';
...@@ -9,11 +9,16 @@ const styles = { ...@@ -9,11 +9,16 @@ const styles = {
border: '1px solid black', border: '1px solid black',
}; };
const EditorWrapper = styled.div`
pointer-events: visible;
user-select: all;
`;
let questionView;
export default ({ node, view, getPos }) => { export default ({ node, view, getPos }) => {
console.log(node); console.log(node);
const editorRef = useRef(); const editorRef = useRef();
let questionView; useEffect(() => {
useLayoutEffect(() => {
questionView = new EditorView( questionView = new EditorView(
{ mount: editorRef.current }, { mount: editorRef.current },
{ {
...@@ -88,10 +93,15 @@ export default ({ node, view, getPos }) => { ...@@ -88,10 +93,15 @@ export default ({ node, view, getPos }) => {
view.dispatch(view.state.tr); view.dispatch(view.state.tr);
}; };
return ( const MemorizedComponent = useMemo(
<> () => (
<div ref={editorRef} style={styles} /> <>
<button onClick={clickMe}>Click me</button> <EditorWrapper ref={editorRef} style={styles} />
</> <button onClick={clickMe}>Click me</button>
</>
),
[],
); );
return <>{MemorizedComponent}</>;
}; };
import React from 'react';
const styles = {
backgroundColor: 'red',
width: '200px',
height: '200px',
};
export default () => {
// useEffect(() => {
// const editorViewDOM = editorViewRef.current;
// if (editorViewDOM) {
// createEditorView(editorViewDOM);
// }
// }, [createEditorView]);
return <div style={styles}></div>;
};
...@@ -6,6 +6,7 @@ const portalPlugin = new PluginKey('portalPlugin'); ...@@ -6,6 +6,7 @@ const portalPlugin = new PluginKey('portalPlugin');
class ReactNodeView { class ReactNodeView {
constructor(node, view, getPos, decorations, createPortal, Component) { constructor(node, view, getPos, decorations, createPortal, Component) {
this.dom = document.createElement('div'); this.dom = document.createElement('div');
this.dom.setAttribute('contenteditable', true);
this.dom.id = uuidv4(); this.dom.id = uuidv4();
this.dom.classList.add('portal'); this.dom.classList.add('portal');
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment