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

create node

parent a122a0a5
No related branches found
No related tags found
1 merge request!396add inputs
import { injectable } from 'inversify';
import { TextSelection } from 'prosemirror-state';
import { AddMarkStep } from 'prosemirror-transform';
import { Fragment } from 'prosemirror-model';
import { v4 as uuidv4 } from 'uuid';
import Tools from '../../lib/Tools';
......@@ -13,36 +11,12 @@ class CreateDropDown extends Tools {
get run() {
return (state, dispatch) => {
const {
tr,
selection: { from, to },
} = state;
console.log(tr);
tr.insertText('hi');
const selectionFrom = new TextSelection(state.doc.resolve(from));
const selectionTo = new TextSelection(state.doc.resolve(to + 2));
console.log(selectionFrom.$anchor, selectionTo.$head);
state.tr.setSelection(
TextSelection.between(selectionFrom.$anchor, selectionTo.$head),
);
tr.step(
new AddMarkStep(
from,
to + 2,
state.config.schema.marks.multiple_drop_down_option.create({
id: uuidv4(),
class: 'multiple-drop-down-option',
}),
),
const content = Fragment.empty;
const createGap = state.config.schema.nodes.multiple_drop_down_option.create(
{ id: uuidv4() },
content,
);
dispatch(tr);
dispatch(state.tr.replaceSelectionWith(createGap));
};
}
......
......@@ -22,11 +22,11 @@ class CreateDropDownService extends Service {
}
register() {
const CreateMark = this.container.get('CreateMark');
const CreateNode = this.container.get('CreateNode');
const addPortal = this.container.get('AddPortal');
this.container.bind('CreateDropDown').to(CreateDropDown);
CreateMark({
CreateNode({
multiple_drop_down_option: multipleDropDownOptionNode,
});
......
......@@ -2,9 +2,9 @@ const multipleDropDownOptionNode = {
attrs: {
class: { default: 'multiple-drop-down-option' },
id: { default: '' },
isfirst: { default: false },
answer: { default: {} },
options: { default: [] },
// isfirst: { default: false },
// answer: { default: {} },
// options: { default: [] },
},
group: 'inline questions',
content: 'text*',
......
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