How to use the prosemirror-view.Decoration.widget 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 / src / plugins / collaborativeold.js View on Github external
/* If cursor color provided - override defaults */
		if (cursorData.cursorColor) {
			innerChildBar.style.backgroundColor = cursorData.cursorColor;
			innerChildCircleSmall.style.backgroundColor = cursorData.cursorColor;
			innerChildCircleBig.style.backgroundColor = cursorData.cursorColor;
			innerStyle += `.name.${formattedDataId}::after { background-color: ${cursorData.cursorColor} !important; } `;
		}
		style.innerHTML = innerStyle;
		// console.timeEnd('redner2');
		const selectionFrom = selection.from;
		const selectionTo = selection.to;
		const selectionHead = selection.head;

		const decorations = [];
		decorations.push(
			Decoration.widget(selectionHead, elem, {
				key: `cursor-widget-${cursorData.id}`,
				lastActive: cursorData.lastActive,
			}),
		);

		if (selectionFrom !== selectionTo) {
			decorations.push(
				Decoration.inline(
					selectionFrom,
					selectionTo,
					{
						class: `cursor-range ${formattedDataId}`,
						style: `background-color: ${cursorData.backgroundColor ||
							'rgba(0, 25, 150, 0.2)'};`,
					},
					{ key: `cursor-inline-${cursorData.id}`, lastActive: cursorData.lastActive },
github ProseMirror / website / example / upload / index.js View on Github external
apply(tr, set) {
      // Adjust decoration positions to changes made by the transaction
      set = set.map(tr.mapping, tr.doc)
      // See if the transaction adds or removes any placeholders
      let action = tr.getMeta(this)
      if (action && action.add) {
        let widget = document.createElement("placeholder")
        let deco = Decoration.widget(action.add.pos, widget, {id: action.add.id})
        set = set.add(tr.doc, [deco])
      } else if (action && action.remove) {
        set = set.remove(set.find(null, null,
                                  spec => spec.id == action.remove.id))
      }
      return set
    }
  },
github guardian / prosemirror-noting / src / js / utils / DecorationUtils.js View on Github external
dom.classList.add(
    `note-${id}`,
    `note-wrapper--${side < 0 ? "start" : "end"}`,
    `note-wrapper--${type}`
  );
  dom.dataset.toggleNoteId = id;
  const cursorAtWidgetAndInsideNote = inside && cursorPos === notePos;
  // If we have a cursor at the note widget position and we're inside a note,
  // we need to ensure that other widgets don't alter its render order, so
  // we keep the sign of the side value and shrink it to ensure it keeps its
  // precedence.
  const sideToRender = cursorAtWidgetAndInsideNote
    ? side - Math.sign(side) / 2
    : 0 - side;
  return Decoration.widget(notePos, dom, {
    // MAX_SAFE_INTEGER is here to order note decorations consistently across
    // plugins without imposing a (realistic) limit on the number of noting
    // plugins that can run concurrently.
    side:
      sideToRender + pluginPriority / Number.MAX_SAFE_INTEGER * Math.sign(side),
    marks: []
  });
};
github yjs / yjs / bindings / prosemirror.js View on Github external
awareness.forEach((state, userID) => {
        if (state.cursor != null) {
          const username = `User: ${userID}`
          decorations.push(Decoration.widget(state.cursor.from, () => {
            const cursor = document.createElement('span')
            cursor.classList.add('ProseMirror-yjs-cursor')
            const user = document.createElement('div')
            user.insertBefore(document.createTextNode(username), null)
            cursor.insertBefore(user, null)
            return cursor
          }, { key: username }))
          decorations.push(Decoration.inline(state.cursor.from, state.cursor.to, { style: 'background-color: #ffa50070' }))
        }
      })
      return DecorationSet.create(state.doc, decorations)
github guardian / prosemirror-invisibles / src / js / utils / create-deco.js View on Github external
export default (pos, type) => {
  const span = document.createElement('span');
  span.classList.add('invisible');
  span.classList.add(`invisible--${type}`);
  return Decoration.widget(pos, span, {
    marks: [],
    key: type
  });
};
github ifiokjr / remirror / @remirror / extension-drop-cursor / src / drop-cursor-plugin.tsx View on Github external
private createInlineDecoration($pos: ResolvedPos): Decoration[] {
    const decorations: Decoration[] = [];

    const dropCursor = Decoration.widget($pos.pos, this.inlineElement, { key: 'drop-cursor-inline' });
    decorations.push(dropCursor);

    return decorations;
  }
  /**
github ProseMirror / website / src / collab / client / comment.js View on Github external
function commentTooltip(state, dispatch) {
  let sel = state.selection
  if (!sel.empty) return null
  let comments = commentPlugin.getState(state).commentsAt(sel.from)
  if (!comments.length) return null
  return DecorationSet.create(state.doc, [Decoration.widget(sel.from, renderComments(comments, dispatch, state))])
}
github ProseMirror / website / example / lint / index.js View on Github external
lint(doc).forEach(prob => {
    decos.push(Decoration.inline(prob.from, prob.to, {class: "problem"}),
               Decoration.widget(prob.from, lintIcon(prob)))
  })
  return DecorationSet.create(doc, decos)
github nib-edit / Nib / packages / core / src / plugins / link / plugin.js View on Github external
return {
          ...prev,
          link,
          editDecoration: undefined
        };
      }

      let { createDecoration, editDecoration } = prev;

      if (tr.getMeta("show-add-link-toolbar") === true) {
        const { $from, $to } = newState.selection;
        if ($from.pos === $to.pos) {
          const node = document.createElement("span");
          node.className = "nib-link-marker";
          createDecoration = DecorationSet.create(newState.doc, [
            Decoration.widget($from.pos, node)
          ]);
        } else {
          createDecoration = DecorationSet.create(newState.doc, [
            Decoration.inline($from.pos, $to.pos, {
              class: "nib-link-marker"
            })
          ]);
        }
        return {
          link,
          editorFocusState: prev.editorFocusState,
          createDecoration,
          showAddLinkToolbar: true
        };
      }
github chanzuckerberg / czi-prosemirror / src / CursorPlaceholderPlugin.js View on Github external
apply(tr, set) {
      set = set.map(tr.mapping, tr.doc);
      const action = tr.getMeta(this);
      if (!action) {
        return set;
      }
      if (action.add) {
        const widget = document.createElement('czi-cursor-placeholder');
        widget.className = 'czi-cursor-placeholder';
        const deco = Decoration.widget(action.add.pos, widget, {
          id: PLACE_HOLDER_ID,
        });
        set = set.add(tr.doc, [deco]);
      } else if (action.remove) {
        const found = set.find(null, null, specFinder);
        set = set.remove(found);
      }

      return set;
    },
  },