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-elements

v9.6.7

Published

This Prosemirror plugin adds the ability to add custom 'elements' to a document.

Downloads

439

Readme

@guardian/prosemirror-elements

This Prosemirror plugin adds the ability to add custom 'elements' to a document.

Why does this exist?

Modelling non-text content in Prosemirror can be tricky. prosemirror-elements provides an abstraction that makes it easy to write custom elements that:

  • contain user-defined fields that model many different kinds of content, including rich text fields and arbitrary data
  • are first class citizens of the Prosemirror schema (for example, nested rich text fields play nicely with collaborative editing)
  • are renderer-agnostic (we use React as a default)

Setup

  1. Ensure you have dev-nginx and yarn installed on your local machine.
  2. Run the setup script: ./script/setup.sh

Run

  1. Ensure nginx is running.
  2. yarn start builds the project locally, spins up a webserver on https://prosemirror-elements.local.dev-gutools.co.uk, and watches for file changes.

Test

  • Run the unit tests via Jest with yarn test:unit.
  • Run the integration tests via Cypress with yarn test:integration.
    • You'll need to be running the application via yarn start simultaneously for the tests to work – make sure the server is responding on http://localhost:7890 before running the tests.
    • For reasons we're not yet able to determine, Cypress won't run your tests immediately when you select them in the GUI. Hit the 'refresh' button and they should run normally.

Release

This repository uses changesets for version management

To release a new version with your changes, run yarn changeset add and follow the prompts. This will create a new changeset file in the .changeset directory. Commit this file with your PR.

When your PR is merged, Changesets will create a PR to release the new version.

Testing locally in applications using prosemirror-elements

We've found yalc useful in testing local changes to prosemirror-elements in applications that use it.

Setup:

  1. Install yalc globally with npm i yalc -g or yarn global add yalc.
  2. Run yarn yalc in your local project from your current branch, to build the project and push changes to yalc.
  3. Run yalc add @guardian/prosemirror-elements within the project consuming prosemirror-elements locally.

Note: any changes you make to your local prosemirror-elements branch must be republished (step 3). Don't forget to run yarn yalc again!

Adding a new element using prosemirror-elements

Quick-Start Guide

How prosemirror-elements works

How prosemirror-elements works

Troubleshooting when developing this library

Problems with yarn link

ProseMirror and its dependencies sometimes use object identity checks (e.g. instanceof). When using yarn link, it's possible for the consuming code to bundle different versions of dependencies simultaneously. This can be difficult to work around. It will not happen during a normal install.

We recommend using yalc to avoid this issue, but it's also possible to work around it.

One known instance of this occurs when appending the NodeSpec generated by the library to the parent editor schema. This would normally be accomplished by appending it to a parent schema, like so:

const mySchema = new Schema({
  nodes: OrderedMap.from(schema.spec.nodes).append(nodeSpec),
  marks,
});

This may fail if your bundler has included the ordered-map dependency twice in your project. Because ordered-map uses instanceof to determine if an incoming object is an OrderedMap, the incoming object will fail this check, despite it being the correct shape.

As a workaround, try reconstructing the map as an object:

const objectNodeSpec: Record<string, NodeSpec> = {};
nodeSpec.forEach((key, value) => (objectNodeSpec[key] = value as NodeSpec));

const mySchema = new Schema({
  nodes: OrderedMap.from(schema.spec.nodes).append(objectNodeSpec),
  marks,
});