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

provide wax context for tools

parent c73538b9
No related branches found
No related tags found
1 merge request!289Pm node views portals
......@@ -3,13 +3,22 @@ import { EditorView } from 'prosemirror-view';
import { AbstractNodeView } from 'wax-prosemirror-services';
import { StepMap } from 'prosemirror-transform';
let questionView;
export default class MultipleChoiceNodeView extends AbstractNodeView {
constructor(node, view, getPos, decorations, createPortal, Component) {
super(node, view, getPos, decorations, createPortal, Component);
constructor(
node,
view,
getPos,
decorations,
createPortal,
Component,
context,
) {
super(node, view, getPos, decorations, createPortal, Component, context);
console.log('ccc', context);
this.node = node;
this.outerView = view;
this.getPos = getPos;
this.context = context;
this.innerView = new EditorView(
{
......@@ -41,6 +50,12 @@ export default class MultipleChoiceNodeView extends AbstractNodeView {
}
dispatchInner(tr) {
this.context.updateView(
{
['mytest']: this.innerView,
},
'mytest',
);
let { state, transactions } = this.innerView.state.applyTransaction(tr);
this.innerView.updateState(state);
......
......@@ -16,8 +16,7 @@ class MultipleChoiceQuestionService extends Service {
});
const addPortal = this.container.get('AddPortal');
addPortal({ nodeView, component: TestComponent });
addPortal({ nodeView, component: TestComponent, context: this.app });
}
}
......
......@@ -17,7 +17,16 @@ export default props => {
id: null,
getPos: () => {},
decorations: [],
createPortal: (element, component, node, view, getPos, decorations) => {
context: {},
createPortal: (
element,
component,
node,
view,
getPos,
decorations,
context,
) => {
setPortal({
...portal,
id: uuidv4(),
......@@ -27,6 +36,7 @@ export default props => {
view,
getPos,
decorations,
context,
});
},
});
......
import { v4 as uuidv4 } from 'uuid';
export default class AbstractNodeView {
constructor(node, view, getPos, decorations, createPortal, Component) {
constructor(
node,
view,
getPos,
decorations,
createPortal,
Component,
context,
) {
this.dom = document.createElement('div');
this.dom.id = uuidv4();
this.dom.classList.add('portal');
createPortal(this.dom, Component, node, view, getPos, decorations);
createPortal(this.dom, Component, node, view, getPos, decorations, context);
}
update(node) {
......
......@@ -3,20 +3,29 @@ import AbstractNodeView from './AbstractNodeView';
const portalPlugin = new PluginKey('portalPlugin');
const CreateNodeView = (createPortal, Component, NodeView) => {
const CreateNodeView = (createPortal, Component, NodeView, context) => {
return (theNode, view, getPos, decorations) =>
new NodeView(theNode, view, getPos, decorations, createPortal, Component);
new NodeView(
theNode,
view,
getPos,
decorations,
createPortal,
Component,
context,
);
};
export default props => {
const nodeViews = {};
props.portals.forEach(p => {
const name = p.nodeView ? p.nodeView.name() : p.name;
console.log('ppp', p);
nodeViews[name] = CreateNodeView(
props.createPortal,
p.component,
p.nodeView || AbstractNodeView,
p.context.context,
);
});
......
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