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

prosemirror-additional-marks

v1.0.2

Published

A prosemirror marks package to add additional marks into the editor

Downloads

8

Readme

prosemirror-additional-marks

This package defines a set of additional marks for prosemirror which can be used when creating your own editor.

Live Demo

https://dhananjeyan286.github.io/prosemirror-additional-marks/demo/src/index.html

Installation

npm i prosemirror-additional-marks

Usage

Note : Add the below entry in your package.json file for now to avoid loading multiple prosemirror-model packages, will fix this in future versions "resolutions": { "prosemirror-model": "1.22.3" }


import { EditorState, Plugin } from "prosemirror-state"
import { EditorView } from "prosemirror-view"
import { Schema } from "prosemirror-model"
import { schema } from "prosemirror-schema-basic"
import { addListNodes } from "prosemirror-schema-list"
import { addMarks, addShortcuts, addCommands, getPlugins } from "../../dist/index.es";
import { history } from "prosemirror-history";
import { baseKeymap } from "prosemirror-commands";
import { dropCursor } from "prosemirror-dropcursor";
import { gapCursor } from "prosemirror-gapcursor";
import { buildKeymap, buildInputRules } from "prosemirror-example-setup";
import { keymap } from "prosemirror-keymap";

let config = ["bold", "italics", "underline", "strikethrough", "link", "fontSize", "fontFamily", "fontColor", "backgroundColor", "script", "inlineCode"]

// config can also be like this
// let config = [
//     "bold",
//     "italics",
//     "underline",
//     "strikethrough",
//     { name: "link", regex: defaultLinkRegex },
//     { name: "fontSize", default: "10pt" },
//     { name: "fontFamily", default: "Arial" },
//     { name: "fontColor", default: "#000000" },
//     { name: "backgroundColor", default: "#ffffff" },
//     "script",
//     "inlineCode"
// ]

export function getDefaultPlugins(schema) {
    let plugins = [
        buildInputRules(schema),
        keymap(buildKeymap(schema)),
        keymap(baseKeymap),
        dropCursor(),
        gapCursor(),
        history(),
    ];

    var attributes = {
        class: "ProseMirror-example-setup-style"
    };

    return plugins.concat(
        new Plugin({
            props: { attributes: attributes },
        })
    );
}

let nodes = addListNodes(schema.spec.nodes, "paragraph block*", "block")

let mySchema = new Schema({
    nodes: nodes,
    marks: addMarks(schema.spec.marks, config),
});

let editor = new EditorView(document.querySelector("#editor"), {
    state: EditorState.create({
        schema: mySchema,
        plugins: getDefaultPlugins(mySchema).concat(getPlugins(config)),
    })
});
window.editor = editor

addCommands(editor, config)
addShortcuts(editor, config)
// editor.dom.addEventListener("cursorPositionChanged", (e) => {
//     console.log(e.detail); // a event that throws the marks at current cursor position whenever view is updated,
//     // this can be used when updating the menubar with respect to cursor movements
//     // for eg : bold icon can be highlighted if bold mark is present at current cursor position by adding an event listener to the dom event "cursorPositionChanged"
// });

APIs Exposed


import { preProcessConfig, getSubConfig, addMarks, addShortcuts, addCommands, getPlugins, sampleConfig } from "prosemirror-additional-marks"

addMarks(marks, config) // returns you the marks that needs to put in your schema based on your config

addShortcuts(view, config) // adds shortcuts based on your config

addCommands(view, config) // adds the commands to view.commands object which you can use to bind it to the menubar
// view.commands.addLink(link) eg - view.commands.addLink("https://www.google.com"),
// view.commands.addLinkWithText(link, text), eg - view.commands.addLinkWithText("https://www.google.com", "Google"),
// view.commands.removeLink(),

// view.commands.setBackgroundColor(color), eg - view.commands.setBackgroundColor("red"),
// view.commands.setBackgroundColor() - to remove background color,

// view.commands.setFontColor(color), eg - view.commands.setFontColor("red"),
// view.commands.setFontColor() - to remove font color,

// view.commands.setFontFamily(fontFamilyName), eg - view.commands.setFontFamily("Times New Roman"),
// view.commands.setFontFamily() - to remove font family,

// view.commands.setFontSize(size), eg - view.commands.setFontSize("15pt"),
// view.commands.setFontSize() - to remove font size,

// view.commands.toggleBold(),
// view.commands.toggleInlineCode(),
// view.commands.toggleItalics(),
// view.commands.toggleStrikethrough(),
// view.commands.toggleSubScript(),
// view.commands.toggleSuperScript(),
// view.commands.toggleUnderline()

getPlugins(config) // returns shortcuts plugin for the config, cursorEventsPlugin to get marks at current cursor position for every view updation,
// plugin that adds default style attributes to editor-div

sampleConfig // gives the default config

preProcessConfig(config) // returns the config after pre processing

getSubConfig(name, config) // returns the specific config for the given mark name

Authors

RM. Dhananjeyan

Credits

Joe B. Lewis - For knowledge sharing

Issues

Use Github Issues to file requests and bugs.

License

MIT License