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

temp

parent 79003346
No related branches found
No related tags found
1 merge request!293Inline question
...@@ -12,50 +12,55 @@ class MultipleChoiceQuestion extends Tools { ...@@ -12,50 +12,55 @@ class MultipleChoiceQuestion extends Tools {
get run() { get run() {
return (state, dispatch) => { return (state, dispatch) => {
console.log(state.selection); console.log(state);
const { from, to } = state.selection; const { from, to } = state.selection;
const { tr } = state; const { tr } = state;
state.doc.nodesBetween(from, to, (node, pos) => { state.schema.nodes.question_wrapper.spec.atom = false;
if (node.type.name === 'question_wrapper') {
const { empty, $from, $to } = state.selection; setTimeout(() => {
let content = Fragment.empty; state.doc.nodesBetween(from, to, (node, pos) => {
if (!empty && $from.sameParent($to) && $from.parent.inlineContent) if (node.type.name === 'question_wrapper') {
content = $from.parent.content.cut( const { empty, $from, $to } = state.selection;
$from.parentOffset, let content = Fragment.empty;
$to.parentOffset, 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() },
content, content,
);
dispatch(tr.replaceSelectionWith(footnote));
} else {
tr.setBlockType(
from,
to,
state.config.schema.nodes.question_wrapper,
{
class: 'question',
},
);
if (!tr.steps.length) return false;
const { empty, $from, $to } = state.selection;
let content = Fragment.empty;
if (!empty && $from.sameParent($to) && $from.parent.inlineContent)
content = $from.parent.content.cut(
$from.parentOffset,
$to.parentOffset,
); );
dispatch(tr.replaceSelectionWith(footnote));
} else {
tr.setBlockType(
from,
to,
state.config.schema.nodes.question_wrapper,
{
class: 'question',
},
);
if (!tr.steps.length) return false;
const { empty, $from, $to } = state.selection;
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() },
content, content,
); );
dispatch(tr.replaceSelectionWith(footnote)); dispatch(tr.replaceSelectionWith(footnote));
// dispatch(state.tr.replaceSelectionWith(footnote)); // dispatch(state.tr.replaceSelectionWith(footnote));
} }
});
state.schema.nodes.question_wrapper.spec.atom = true;
}); });
}; };
} }
......
...@@ -18,6 +18,7 @@ class MultipleChoiceQuestionService extends Service { ...@@ -18,6 +18,7 @@ class MultipleChoiceQuestionService extends Service {
createNode({ createNode({
question_wrapper: { question_wrapper: {
group: 'block', group: 'block',
atom: true,
content: 'inline*', content: 'inline*',
attrs: { attrs: {
class: { default: 'paragraph' }, class: { default: 'paragraph' },
......
const multipleChoiceNode = { const multipleChoiceNode = {
group: 'inline', group: 'inline',
content: 'inline*', content: 'inline*',
inline: true, // inline: true,
// atom: true, atom: true,
attrs: { attrs: {
id: { default: '' }, id: { default: '' },
}, },
......
import { isPlainObject } from "lodash"; import { isPlainObject } from 'lodash';
import ParseRule from "./ParseRule"; import ParseRule from './ParseRule';
import Middleware from "../lib/Middleware"; import Middleware from '../lib/Middleware';
export default class Node { export default class Node {
name = ""; name = '';
importer = {}; importer = {};
atom = false; atom = false;
inline = false; inline = false;
isolating = false; isolating = false;
draggable = false; draggable = false;
group = ""; group = '';
content = ""; content = '';
_attrs = {}; _attrs = {};
_parseRules = []; _parseRules = [];
...@@ -73,7 +73,7 @@ export default class Node { ...@@ -73,7 +73,7 @@ export default class Node {
hooks = hook; hooks = hook;
}); });
return hooks.value; return hooks.value;
} },
}; };
} }
} }
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