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 { injectable } from 'inversify';
import { TextSelection } from 'prosemirror-state'; import { Fragment } from 'prosemirror-model';
import { AddMarkStep } from 'prosemirror-transform';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import Tools from '../../lib/Tools'; import Tools from '../../lib/Tools';
...@@ -13,36 +11,12 @@ class CreateDropDown extends Tools { ...@@ -13,36 +11,12 @@ class CreateDropDown extends Tools {
get run() { get run() {
return (state, dispatch) => { return (state, dispatch) => {
const { const content = Fragment.empty;
tr, const createGap = state.config.schema.nodes.multiple_drop_down_option.create(
selection: { from, to }, { id: uuidv4() },
} = state; content,
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',
}),
),
); );
dispatch(state.tr.replaceSelectionWith(createGap));
dispatch(tr);
}; };
} }
......
...@@ -22,11 +22,11 @@ class CreateDropDownService extends Service { ...@@ -22,11 +22,11 @@ class CreateDropDownService extends Service {
} }
register() { register() {
const CreateMark = this.container.get('CreateMark'); const CreateNode = this.container.get('CreateNode');
const addPortal = this.container.get('AddPortal'); const addPortal = this.container.get('AddPortal');
this.container.bind('CreateDropDown').to(CreateDropDown); this.container.bind('CreateDropDown').to(CreateDropDown);
CreateMark({ CreateNode({
multiple_drop_down_option: multipleDropDownOptionNode, multiple_drop_down_option: multipleDropDownOptionNode,
}); });
......
...@@ -2,9 +2,9 @@ const multipleDropDownOptionNode = { ...@@ -2,9 +2,9 @@ const multipleDropDownOptionNode = {
attrs: { attrs: {
class: { default: 'multiple-drop-down-option' }, class: { default: 'multiple-drop-down-option' },
id: { default: '' }, id: { default: '' },
isfirst: { default: false }, // isfirst: { default: false },
answer: { default: {} }, // answer: { default: {} },
options: { default: [] }, // options: { default: [] },
}, },
group: 'inline questions', group: 'inline questions',
content: 'text*', 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