How to use the prosemirror-transform.insertPoint function in prosemirror-transform

To help you get started, we’ve selected a few prosemirror-transform examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pubpub / pubpub-editor / packages / pubpub-editor / src / addons / CitationsAddon / citationsPlugin.js View on Github external
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;
}
github ifiokjr / remirror / @remirror / extension-drop-cursor / src / drop-cursor-plugin.tsx View on Github external
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);
    }
  });
github pubpub / pubpub-editor / packages / pubpub-prose / src / prosemirror-setup / plugins / autocompletePlugin.js View on Github external
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);
    }
  },
github ProseMirror / website / example / footnote / index.js View on Github external
select(state) {
    return insertPoint(state.doc, state.selection.from, footnoteSchema.nodes.footnote) != null
  },
  run(state, dispatch) {