GithubHelp home page GithubHelp logo

aarongreenlee / prosemirror-noting Goto Github PK

View Code? Open in Web Editor NEW

This project forked from guardian/prosemirror-noting

0.0 1.0 0.0 1.89 MB

Prosemirror plugin that adds the ability to have ranges added to the document that expand and contract around dependent on the input.

License: MIT License

JavaScript 95.96% CSS 4.04%

prosemirror-noting's Introduction

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

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

prosemirror-noting's People

Contributors

richieahb avatar jonathonherbert avatar shaundillon avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.