npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@guardian/prosemirror-noting

v3.1.6

Published

A plugin to allow noting in prosemirror

Downloads

31

Readme

prosemirror-noting

This plugin adds the ability to have ranges added to the document that expand and contract around dependent on the input. These notes are represented as marks in the document.

Very basic demo here


Install

npm install prosemirror-noting

Usage

Add the mark to the schema

const mySchema = new Schema({
  nodes,
  marks: Object.assign({}, marks, {
    note: createNoteMark(
      {
        note: "span.note",
      },
      (meta) => ({
        class: meta.hidden ? "note--collapsed" : "",
        title: "My Title",
        contenteditable: !meta.hidden,
      })
    ),
  }),
});

Add the plugin to the state

const historyPlugin = history();
const noterPlugin = noter(mySchema.marks.note, doc, historyPlugin);

new EditorView(document.querySelector("#editor"), {
  state: EditorState.create({
    doc: DOMParser.fromSchema(mySchema).parse(
      document.querySelector("#content")
    ),
    plugins: [
      keymap({
        F10: toggleNote("note"),
      }),
      historyPlugin,
      noterPlugin,
    ],
  }),
});

And import the css (if needed) from prosemirror-noting/dist/noting.css.

API

createNoteMark(typeTagMap: string | object, attrGenerator: function): MarkType

Returns a mark to be added to the schema.

  • typeTagMap - if this is passed with an object it expects a map between a "note type" and a dom tag (e.g. { note: "span.note"}). Otherwise if a string is passed it will expect that string to be simply a tag name and the type will default to a type of note. Good for styling.
  • attrGenerator - this will run when rendering the note to add derived DOM attributes from the meta data.

toggleNote(type: string = "note", cursorToEnd = false): CommandFunction

Returns a command used for toggling notes based on the cursor position.

  • type - this will use the type to decide which note type to toggle if there are more than one.
  • cursorToEnd - this will make the cursor skip to after the note when adding a new note

Toggle note works in the following way:

  • Selections
    • Completely inside a note - will slice the note
    • Completely outside a note - will add a note
    • Part inside and part outside - will extend the note
  • Cursor
    • Inside a note - will remove the note
    • Outside a note - will start a note

toggleAllNotes(type: string): CommandFunction

Returns a command used for toggling all notes.

  • type - this will use the type to decide which note type to toggle if there are more than one.

setNoteMeta(id: string, meta: object): CommandFunction

Returns a command to set the meta for a note id

  • id - the string id of the note to edit.
  • meta - an object that will be assigned to the current meta (i.e. will not overwrite keys it does not contain).

noter(markType: MarkType, historyPlugin: Plugin, onNoteCreate: function = () => {}): Plugin

Returns the plugin to add to prosemirror

  • markType - the mark type that is being used in the schema to handle the notes.
  • historyPlugin - pass the history plugin to handle undo / redo.
  • onNoteCreate - a callback that is called when a new note is added to the document.

Roadmap

  • Add in collapsing as a config option, currently there are some overlapping concerns here (meta.hidden manually having to be set in the schema setup)
  • Better documentation
  • Use proper plugin state in order to expose the state of the notes
  • Better CSS / decorations