Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const createReference = (citationData, state, engine) => {
const citationID = citationData.id;
const newNode = schema.nodes.citation.create({data: citationData, citationID });
const citationsNode = findNodesWithIndex(state.doc, 'citations');
const pos = citationsNode[0].index + 1;
// tries to find the closest place to insert this note
const newPoint = insertPoint(state.doc, pos, schema.nodes.citation, {data: citationData});
let tr = state.tr.insert(newPoint, newNode);
tr.setMeta('createdReference', citationID);
engine.addCitation(citationData);
return tr;
}
public dragover = throttle(50, (event: DragEvent) => {
const pos = this.view.posAtCoords({ left: event.clientX, top: event.clientY });
if (pos) {
const {
dragging,
state: { doc, schema },
} = this.view;
const target = dragging?.slice
? dropPoint(doc, pos.pos, dragging.slice) ?? pos.pos
: insertPoint(doc, pos.pos, schema.image) ?? pos.pos;
if (target === this.target) {
// This line resets the timeout.
this.scheduleRemoval(100);
return;
}
this.target = target;
this.updateDecorationSet();
this.scheduleRemoval(100);
}
});
createCitation(state, onAction, citationData) {
const referenceNode = schema.nodes.reference.create({
citationID: '1',
});
const newNode = schema.nodes.citation.create({data: citationData});
const citationsNode = findNodesWithIndex(state.doc, 'citations');
const pos = citationsNode[0].index + 1;
// tries to find the closest place to insert this note
const newPoint = insertPoint(state.doc, pos, schema.nodes.citation, {data: citationData});
let tr = state.tr.insert(newPoint, newNode);
tr = tr.replaceSelectionWith(referenceNode);
const action = tr.action();
onAction(action);
}
},
select(state) {
return insertPoint(state.doc, state.selection.from, footnoteSchema.nodes.footnote) != null
},
run(state, dispatch) {