attempt prosemirror update, troubleshooting

This commit is contained in:
Shawn Erquhart
2017-06-15 11:36:10 -04:00
parent e7ac3a7671
commit 49b3a62823
5 changed files with 27 additions and 33 deletions

View File

@ -4,8 +4,8 @@ import { schema } from "prosemirror-markdown";
import makeParser from '../parser';
const testSchema = new Schema({
nodes: schema.nodeSpec,
marks: schema.markSpec,
nodes: schema.spec.nodes,
marks: schema.spec.marks,
});
// Temporary plugins test, uses preloaded plugins from ../parser

View File

@ -48,9 +48,9 @@ function buildInputRules(schema) {
}
function markActive(state, type) {
const { from, to, empty } = state.selection;
const { from, to, empty, $from } = state.selection;
if (empty) {
return type.isInSet(state.storedMarks || state.doc.marksAt(from));
return type.isInSet(state.storedMarks || $from.marks());
}
return state.doc.rangeHasMark(from, to, type);
}
@ -111,6 +111,7 @@ export default class Editor extends Component {
this.view = new EditorView(this.ref, {
state: this.createEditorState(),
onAction: this.handleAction,
dispatchTransaction: this.handleTransaction,
});
}
@ -121,18 +122,6 @@ export default class Editor extends Component {
return EditorState.create({
doc,
schema,
plugins: [
inputRules({
rules: allInputRules.concat(buildInputRules(schema)),
}),
keymap(buildKeymap(schema)),
keymap(baseKeymap),
history.history(),
keymap({
'Mod-z': history.undo,
'Mod-y': history.redo,
}),
],
});
}
@ -146,16 +135,14 @@ export default class Editor extends Component {
}
}
handleAction = (action) => {
handleTransaction = (transaction) => {
const { serializer } = this.state;
const newState = this.view.state.applyAction(action);
const newState = this.view.state.apply(transaction);
const md = serializer.serialize(newState.doc);
console.log(md);
const processedMarkdown = unified()
.use(markdownToRemark)
.use(remarkToMarkdown, { fences: true, commonmark: true, footnotes: true, pedantic: true })
.processSync(md);
console.log(processedMarkdown.contents);
this.props.onChange(processedMarkdown.contents);
this.view.updateState(newState);
if (newState.selection !== this.state.selection) {

View File

@ -14,7 +14,12 @@ export default function markdownToProseMirror({ state }) {
// on the state object.
const { schema, plugins } = state;
return transform;
// return transform;
return node => {
const result = transform(node);
return result;
};
/**
* The MDAST transformer function.