How to use the prosemirror-state.Transaction.prototype function in prosemirror-state

To help you get started, we’ve selected a few prosemirror-state 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 chanzuckerberg / czi-prosemirror / src / ui / Editor.js View on Github external
export const DEFAULT_NODE_VIEWS = Object.freeze({
  [IMAGE]: ImageNodeView,
  [MATH]: MathNodeView,
  [BOOKMARK]: BookmarkNodeView,
  [LIST_ITEM]: ListItemNodeView,
});

const EDITOR_EMPTY_STATE = Object.freeze(createEmptyEditorState());

// Monkey patch the `scrollIntoView` mathod of 'Transaction'.
// Why this is necessary?
// It appears that promse-mirror does call `scrollIntoView` extensively
// from many of the built-in transformations, thus cause unwanted page
// scrolls. To make the behavior more manageable, this patched method asks
// developer to explicitly use `scrollIntoView(true)` to enforce page scroll.
const scrollIntoView = Transaction.prototype.scrollIntoView;
const scrollIntoViewPatched = function(forced: boolean): Transaction {
  if (forced === true && scrollIntoView) {
    return scrollIntoView.call(this);
  } else {
    return this;
  }
};
Transaction.prototype.scrollIntoView = scrollIntoViewPatched;

// Sets the implementation so that `FontTypeMarkSpec` can load custom fonts.
WebFontLoader.setImplementation(webfontloader);

const handleDOMEvents = {
  drop: handleEditorDrop,
  keydown: handleEditorKeyDown,
  paste: handleEditorPaste,
github chanzuckerberg / czi-prosemirror / src / ui / Editor.js View on Github external
// Monkey patch the `scrollIntoView` mathod of 'Transaction'.
// Why this is necessary?
// It appears that promse-mirror does call `scrollIntoView` extensively
// from many of the built-in transformations, thus cause unwanted page
// scrolls. To make the behavior more manageable, this patched method asks
// developer to explicitly use `scrollIntoView(true)` to enforce page scroll.
const scrollIntoView = Transaction.prototype.scrollIntoView;
const scrollIntoViewPatched = function(forced: boolean): Transaction {
  if (forced === true && scrollIntoView) {
    return scrollIntoView.call(this);
  } else {
    return this;
  }
};
Transaction.prototype.scrollIntoView = scrollIntoViewPatched;

// Sets the implementation so that `FontTypeMarkSpec` can load custom fonts.
WebFontLoader.setImplementation(webfontloader);

const handleDOMEvents = {
  drop: handleEditorDrop,
  keydown: handleEditorKeyDown,
  paste: handleEditorPaste,
};

function bindNodeView(NodeView: CustomNodeView): Function {
  return (node, view, getPos, decorations) => {
    return new NodeView(node, view, getPos, decorations);
  };
}