Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prosemirror-changeset

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-changeset

Distills a series of editing steps into deleted and added ranges

  • 2.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1M
increased by1.06%
Maintainers
1
Weekly downloads
 
Created

What is prosemirror-changeset?

The prosemirror-changeset package is a utility for managing and representing changes in ProseMirror documents. It helps in tracking changes, creating change sets, and applying them to documents. This is particularly useful for collaborative editing, version control, and undo/redo functionality.

What are prosemirror-changeset's main functionalities?

Creating a ChangeSet

This feature allows you to create a ChangeSet from a ProseMirror document. The ChangeSet can then be used to track changes over time.

const { ChangeSet } = require('prosemirror-changeset');
const { Schema, DOMParser } = require('prosemirror-model');
const { schema } = require('prosemirror-schema-basic');

const doc = DOMParser.fromSchema(schema).parse(document.querySelector('#content'));
const changeSet = ChangeSet.create(doc);
console.log(changeSet);

Applying Changes

This feature demonstrates how to apply changes to a ChangeSet. It shows how to simulate a change in the document and update the ChangeSet accordingly.

const { ChangeSet } = require('prosemirror-changeset');
const { Schema, DOMParser } = require('prosemirror-model');
const { schema } = require('prosemirror-schema-basic');

const doc = DOMParser.fromSchema(schema).parse(document.querySelector('#content'));
let changeSet = ChangeSet.create(doc);

// Simulate a change
const tr = doc.tr.insertText('Hello', 1);
changeSet = changeSet.addSteps(doc, tr.doc, tr.mapping.maps);
console.log(changeSet);

Reverting Changes

This feature shows how to revert changes using a ChangeSet. It demonstrates how to undo changes and revert the document to its previous state.

const { ChangeSet } = require('prosemirror-changeset');
const { Schema, DOMParser } = require('prosemirror-model');
const { schema } = require('prosemirror-schema-basic');

const doc = DOMParser.fromSchema(schema).parse(document.querySelector('#content'));
let changeSet = ChangeSet.create(doc);

// Simulate a change
const tr = doc.tr.insertText('Hello', 1);
changeSet = changeSet.addSteps(doc, tr.doc, tr.mapping.maps);

// Revert the change
const revertedDoc = changeSet.revert(doc);
console.log(revertedDoc);

Other packages similar to prosemirror-changeset

FAQs

Package last updated on 17 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc