How to use the prosemirror-view.DecorationSet function in prosemirror-view

To help you get started, we’ve selected a few prosemirror-view 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 / dist / addons / CollaborativeAddon / FirebasePlugin.js View on Github external
base Plugin state?

*/

/*
  Doesn't need to be a plugin??
*/

/*
  How to create a 'current' merged commit?
  - Always merge current steps?
  - Only show up to last steps?
*/

var _require6 = require('prosemirror-view'),
    DecorationSet = _require6.DecorationSet,
    Decoration = _require6.Decoration;

function stringToColor(string) {
  var alpha = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;

  var hue = string.split('').reduce(function (sum, char) {
    return sum + char.charCodeAt(0);
  }, 0) % 360;
  return 'hsla(' + hue + ', 100%, 50%, ' + alpha + ')';
}

// Checkpoint a document every 100 steps
var SAVE_EVERY_N_STEPS = 100;

// healDatabase - In case a step corrupts the document (happens surpsiginly often), apply each step individually to find errors
// and then delete all of those steps
github pubpub / pubpub-editor / packages / pubpub-prose / dist / prosemirror-setup / plugins / mentionsPlugin.js View on Github external
'use strict';

Object.defineProperty(exports, "__esModule", {
	value: true
});

var _prosemirrorState = require('prosemirror-state');

var _plugins = require('../plugins');

var _pluginKeys = require('./pluginKeys');

var _schema = require('../schema');

var _require = require('prosemirror-view'),
    DecorationSet = _require.DecorationSet,
    Decoration = _require.Decoration;

var mentionsPlugin = new _prosemirrorState.Plugin({
	state: {
		init: function init(config, instance) {
			// const set = DecorationSet.empty;
			return { decos: DecorationSet.empty, start: null };
		},
		apply: function apply(transaction, state, prevEditorState, editorState) {

			var sel = editorState.selection;
			var updateMentions = this.spec.editorView.props.viewHandlers.updateMentions;

			if (!sel.empty) {
				updateMentions('');
				return { decos: DecorationSet.empty, start: null };
github pubpub / pubpub-editor / packages / pubpub-prose / dist / prosemirror-setup / plugins / diffPlugin.js View on Github external
init: function init(config, instance) {
      var _require = require("prosemirror-view"),
          DecorationSet = _require.DecorationSet,
          Decoration = _require.Decoration;

      return { deco: DecorationSet.empty,
        linkedEditor: config.linkedEditor,
        originalEditor: config.originalEditor,
        showAsAdditions: config.showAsAdditions
      };
    },
    apply: function apply(action, state, prevEditorState, editorState) {
github chanzuckerberg / czi-prosemirror / dist / CursorPlaceholderPlugin.js View on Github external
init: function init() {
      return _prosemirrorView.DecorationSet.empty;
    },
    apply: function apply(tr, set) {
github pubpub / pubpub-editor / packages / pubpub-prose / dist / plugins / citationsPlugin.js View on Github external
var _docOperations = require('../utils/doc-operations');

var _references = require('../references');

var _prosemirrorState = require('prosemirror-state');

var _prosemirrorModel = require('prosemirror-model');

var _prosemirrorTransform = require('prosemirror-transform');

var _pluginKeys = require('./pluginKeys');

var _setup = require('../setup');

var _require = require("prosemirror-view"),
    DecorationSet = _require.DecorationSet,
    Decoration = _require.Decoration;

/*
Problem:
  - problem: remote diffs do not have meta data
*/

var createReferenceDecoration = function createReferenceDecoration(index, node, label) {
  return Decoration.node(index, index + 1, {}, { citationID: node.attrs.citationID, label: label });
};

var findCitationNode = function findCitationNode(doc, citationID) {
  var citationsNode = doc.child(1);
  if (!citationsNode) {
    return null;
  }
github pubpub / pubpub-editor / packages / pubpub-editor / dist / prosemirror-setup / plugins / citationsPlugin.js View on Github external
var _references = require('../../references');

var _prosemirrorState = require('prosemirror-state');

var _prosemirrorModel = require('prosemirror-model');

var _plugins = require('../plugins');

var _prosemirrorTransform = require('prosemirror-transform');

var _pluginKeys = require('./pluginKeys');

var _schema = require('../schema');

var _require = require('prosemirror-view'),
    DecorationSet = _require.DecorationSet,
    Decoration = _require.Decoration;

var createReferenceDecoration = function createReferenceDecoration(index, node, label) {
	return Decoration.node(index, index + 1, {}, { citationID: node.attrs.citationID, label: label });
};

var findCitationNode = function findCitationNode(doc, citationID) {
	var citationsNode = doc.child(1);
	if (!citationsNode) {
		return null;
	}
	var foundNode = (0, _docOperations.findNodeByFunc)(doc, function (_node) {
		return _node.type.name === 'citation' && _node.attrs.citationID === citationID;
	});
	if (!foundNode) {
		return null;
github pubpub / pubpub-editor / packages / pubpub-editor / dist / prosemirror-setup / plugins / footnotesPlugin.js View on Github external
var _docOperations = require('../../utils/doc-operations');

var _prosemirrorState = require('prosemirror-state');

var _prosemirrorModel = require('prosemirror-model');

var _plugins = require('../plugins');

var _prosemirrorTransform = require('prosemirror-transform');

var _pluginKeys = require('./pluginKeys');

var _schema = require('../schema');

var _require = require('prosemirror-view'),
    DecorationSet = _require.DecorationSet,
    Decoration = _require.Decoration;

var createFootnoteDecoration = function createFootnoteDecoration(index, node, label) {
	return Decoration.node(index, index + node.nodeSize, {}, { label: label });
};

var createDecorations = function createDecorations(doc, set) {
	var nodes = (0, _docOperations.findNodesWithIndex)(doc, 'footnote') || [];
	var count = 0;
	var decos = nodes.map(function (node, index) {
		count++;
		var deco = createFootnoteDecoration(node.index, node.node, count);
		return deco;
	});

	var newSet = DecorationSet.create(doc, decos);
github pubpub / pubpub-editor / packages / pubpub-editor / dist / prosemirror-setup / plugins / diffPlugin.js View on Github external
apply: function apply(action, state, prevEditorState, editorState) {
      var _require2 = require("prosemirror-view"),
          DecorationSet = _require2.DecorationSet,
          Decoration = _require2.Decoration;

      if (action.type === 'transform') {
        state.linkedEditor.linkedTransform();
      }

      if (action.type === 'patch') {
        var diffIndex = action.diffIndex;
        var diff = state.lastDiff[diffIndex];
        //Removals always require an insertion, and possibly a deletion
        //
        if (diff.removed) {
          var textNode = pubSchema.text(text);
          var newT = state.tr.replaceWith(to, to, textNode);
          var _action = {
            type: 'transform',
github pubpub / pubpub-editor / packages / pubpub-prose / dist / editors / baseEditor.js View on Github external
this._createDecorations = function (editorState) {
      var _require = require("prosemirror-view"),
          DecorationSet = _require.DecorationSet;

      return DecorationSet.empty;
    };
github pubpub / pubpub-editor / packages / pubpub-prose / dist / prosemirror-setup / plugins / selectPlugin.js View on Github external
apply: function apply(transaction, state, prevEditorState, editorState) {
      var sel = transaction.curSelection;
      if (sel) {
        var decos = [_prosemirrorView.Decoration.inline(sel.$from.pos, sel.$to.pos, { class: 'selection-marker' }, { inclusiveLeft: true,
          inclusiveRight: true
        })];
        var deco = _prosemirrorView.DecorationSet.create(editorState.doc, decos);
        return { deco: deco };
      }

      return state;
    }
  },